Skip to content

Commit

Permalink
add indexName
Browse files Browse the repository at this point in the history
  • Loading branch information
Marc Neuhaus committed May 14, 2017
1 parent 676768b commit 7e0ac5b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
16 changes: 9 additions & 7 deletions src/Adapter/MySQLAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public function __construct($configuration)

public function addObject($object, $objectId, $indexName = null)
{
$id = $this->getObject($objectId, serialize($object));
$id = $this->getObject($objectId, serialize($object), $indexName);
$this->connection->query(sprintf('DELETE FROM %scontents WHERE object = "%s"',
$this->configuration['table_prefix'], $id));

Expand Down Expand Up @@ -116,7 +116,7 @@ protected function insertContent($id, $key, $value)
$query->execute();
}

public function getObject($objectId, $data)
public function getObject($objectId, $data, $indexName)
{
$query = sprintf('SELECT id FROM %sobjects WHERE objectId = "%s"', $this->configuration['table_prefix'],
$objectId);
Expand All @@ -126,28 +126,30 @@ public function getObject($objectId, $data)
$timestamp = time();
$query = $this->connection->prepare(sprintf('
UPDATE %sobjects
SET data = ?, updated = ?
SET data = ?, updated = ?, `index` = ?
WHERE id = ?
',
$this->configuration['table_prefix']
));
$query->bind_param("sii", $data, $timestamp, $row['id']);
$query->bind_param("siis", $data, $timestamp, $row['id'], $indexName);
$query->execute();

return intval($row['id']);
}

$query = $this->connection->prepare(sprintf('
INSERT INTO %sobjects
(objectId, data, created, updated)
VALUES(?, ?, ?, ?)
(objectId, `index`, data, created, updated)
VALUES(?, ?, ?, ?, ?)
',
$this->configuration['table_prefix']
));

$timestamp = time();
$query->bind_param(
"ssii",
"sssii",
$objectId,
$indexName,
$data,
$timestamp,
$timestamp
Expand Down
2 changes: 1 addition & 1 deletion tests/Functional/Adapter/MySQLAdapterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function testNaughtyCharacters($content, $expectations)
$data = [
'content' => $content,
];
$id = 'textObject';
$id = uniqid();
$index->addObject($data, $id, 'someIndex');

foreach ($expectations as $search => $hasResults) {
Expand Down

0 comments on commit 7e0ac5b

Please sign in to comment.