| @@ 112-157 (lines=46) @@ | ||
| 109 | /** |
|
| 110 | * @inheritdoc |
|
| 111 | */ |
|
| 112 | protected function updateProperties($path, INode $node, $changedProperties) { |
|
| 113 | $existingProperties = $this->getProperties($path, $node, []); |
|
| 114 | $deleteStatement = self::DELETE_BY_PATH_AND_NAME_STMT; |
|
| 115 | $insertStatement = self::INSERT_BY_PATH_STMT; |
|
| 116 | $updateStatement = self::UPDATE_BY_PATH_AND_NAME_STMT; |
|
| 117 | ||
| 118 | // TODO: use "insert or update" strategy ? |
|
| 119 | $this->connection->beginTransaction(); |
|
| 120 | foreach ($changedProperties as $propertyName => $propertyValue) { |
|
| 121 | $propertyExists = array_key_exists($propertyName, $existingProperties); |
|
| 122 | // If it was null, we need to delete the property |
|
| 123 | if (is_null($propertyValue)) { |
|
| 124 | if ($propertyExists) { |
|
| 125 | $this->connection->executeUpdate($deleteStatement, |
|
| 126 | [ |
|
| 127 | $path, |
|
| 128 | $propertyName |
|
| 129 | ] |
|
| 130 | ); |
|
| 131 | } |
|
| 132 | } else { |
|
| 133 | if (!$propertyExists) { |
|
| 134 | $this->connection->executeUpdate($insertStatement, |
|
| 135 | [ |
|
| 136 | $path, |
|
| 137 | $propertyName, |
|
| 138 | $propertyValue |
|
| 139 | ] |
|
| 140 | ); |
|
| 141 | } else { |
|
| 142 | $this->connection->executeUpdate($updateStatement, |
|
| 143 | [ |
|
| 144 | $propertyValue, |
|
| 145 | $path, |
|
| 146 | $propertyName |
|
| 147 | ] |
|
| 148 | ); |
|
| 149 | } |
|
| 150 | } |
|
| 151 | } |
|
| 152 | ||
| 153 | $this->connection->commit(); |
|
| 154 | $this->offsetUnset($path); |
|
| 155 | ||
| 156 | return true; |
|
| 157 | } |
|
| 158 | ||
| 159 | /** |
|
| 160 | * Bulk load properties for children |
|
| @@ 107-153 (lines=47) @@ | ||
| 104 | /** |
|
| 105 | * @inheritdoc |
|
| 106 | */ |
|
| 107 | protected function updateProperties($path, INode $node, $changedProperties) { |
|
| 108 | $existingProperties = $this->getProperties($path, $node, []); |
|
| 109 | $fileId = $node->getId(); |
|
| 110 | $deleteStatement = self::DELETE_BY_ID_AND_NAME_STMT; |
|
| 111 | $insertStatement = self::INSERT_BY_ID_STMT; |
|
| 112 | $updateStatement = self::UPDATE_BY_ID_AND_NAME_STMT; |
|
| 113 | ||
| 114 | // TODO: use "insert or update" strategy ? |
|
| 115 | $this->connection->beginTransaction(); |
|
| 116 | foreach ($changedProperties as $propertyName => $propertyValue) { |
|
| 117 | $propertyExists = array_key_exists($propertyName, $existingProperties); |
|
| 118 | // If it was null, we need to delete the property |
|
| 119 | if (is_null($propertyValue)) { |
|
| 120 | if ($propertyExists) { |
|
| 121 | $this->connection->executeUpdate($deleteStatement, |
|
| 122 | [ |
|
| 123 | $fileId, |
|
| 124 | $propertyName |
|
| 125 | ] |
|
| 126 | ); |
|
| 127 | } |
|
| 128 | } else { |
|
| 129 | if (!$propertyExists) { |
|
| 130 | $this->connection->executeUpdate($insertStatement, |
|
| 131 | [ |
|
| 132 | $fileId, |
|
| 133 | $propertyName, |
|
| 134 | $propertyValue |
|
| 135 | ] |
|
| 136 | ); |
|
| 137 | } else { |
|
| 138 | $this->connection->executeUpdate($updateStatement, |
|
| 139 | [ |
|
| 140 | $propertyValue, |
|
| 141 | $fileId, |
|
| 142 | $propertyName |
|
| 143 | ] |
|
| 144 | ); |
|
| 145 | } |
|
| 146 | } |
|
| 147 | } |
|
| 148 | ||
| 149 | $this->connection->commit(); |
|
| 150 | $this->offsetUnset($fileId); |
|
| 151 | ||
| 152 | return true; |
|
| 153 | } |
|
| 154 | ||
| 155 | /** |
|
| 156 | * Bulk load properties for directory children |
|