Skip to content

Commit

Permalink
implement binary deletion with XmlPropsRemover
Browse files Browse the repository at this point in the history
  • Loading branch information
dbu committed Jan 6, 2024
1 parent d92d822 commit 262799b
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 9 deletions.
14 changes: 13 additions & 1 deletion src/Jackalope/Transport/DoctrineDBAL/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -1598,7 +1598,7 @@ private function removePropertiesFromNode(string $nodePath, array $propertiesToD
$xml = $this->getConnection()->fetchOne($query, [$nodeId]);

$xmlPropsRemover = new XmlPropsRemover($xml, $propertiesToDelete);
[$xml, $references] = $xmlPropsRemover->removeProps();
[$xml, $references, $binaries] = $xmlPropsRemover->removeProps();

foreach ($references as $type => $propertyNames) {
$table = $this->referenceTables['reference' === $type ? PropertyType::REFERENCE : PropertyType::WEAKREFERENCE];
Expand All @@ -1615,6 +1615,18 @@ private function removePropertiesFromNode(string $nodePath, array $propertiesToD
}
}
}
foreach ($binaries as $propertyName) {
try {
$query = "DELETE FROM {$this->binaryTable} WHERE node_id = ? AND property_name = ?";
$this->getConnection()->executeQuery($query, [$nodeId, $propertyName]);
} catch (DBALException $e) {
throw new RepositoryException(
"Can not delete binaries for property $propertyName from `{$this->binaryTable}`",
$e->getCode(),
$e
);
}
}

$query = 'UPDATE phpcr_nodes SET props = ? WHERE id = ?';
$params = [$xml, $nodeId];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ class XmlPropsRemover
*/
private array $weakReferences = [];

/**
* @var string[]
*/
private array $binaries = [];

/**
* @var string[]
*/
Expand All @@ -37,21 +42,23 @@ public function __construct(string $xml, array $propertyNames)
}

/**
* @example [$xml, $references] = $xmlPropsRemover->removeProps($xml, $propertiesToDelete);
* @example [$xml, $references, $binaries] = $xmlPropsRemover->removeProps($xml, $propertiesToDelete);
*
* @return array{
* 0: string,
* 1: array{
* reference: string[],
* weakreference: string[],
* },
* 2: string[]
* } An array with the new xml (0) and the references (1) which requires to be removed
*/
public function removeProps(): array
{
$this->newXml = '<?xml version="1.0" encoding="UTF-8"?>'.PHP_EOL;
$this->references = [];
$this->weakReferences = [];
$this->binaries = [];
$this->newStartTag = '';
$this->skipCurrentTag = false;

Expand All @@ -76,6 +83,7 @@ public function removeProps(): array
'reference' => $this->references,
'weakreference' => $this->weakReferences,
],
$this->binaries,
];
}

Expand All @@ -91,14 +99,20 @@ private function startHandler(\XMLParser $parser, string $name, array $attrs): v
if ('SV:PROPERTY' === $name) {
$svName = $attrs['SV:NAME'];

if (\in_array((string)$svName, $this->propertyNames, true)) {
if (\in_array((string) $svName, $this->propertyNames, true)) {
$this->skipCurrentTag = true;
$svType = $attrs['SV:TYPE'];

if ('reference' === $svType) {
$this->references[] = $svName;
} elseif ('weakreference' === $svType) {
$this->weakReferences[] = $svName;
$svType = strtolower($attrs['SV:TYPE']);

switch ($svType) {
case 'reference':
$this->references[] = $svName;
break;
case 'weakreference':
$this->weakReferences[] = $svName;
break;
case 'binary':
$this->binaries[] = $svName;
break;
}

return;
Expand Down

0 comments on commit 262799b

Please sign in to comment.