| Conditions | 11 |
| Paths | 80 |
| Total Lines | 65 |
| Code Lines | 40 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 145 | public function update(): void |
||
| 146 | { |
||
| 147 | // Register updates to an item for update |
||
| 148 | foreach ($this->updateRegistryToItem as $workspace => $tableArray) { |
||
| 149 | foreach ($tableArray as $table => $recordArray) { |
||
| 150 | foreach ($recordArray as $item) { |
||
| 151 | $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('sys_refindex'); |
||
| 152 | $statement = $queryBuilder |
||
| 153 | ->select('tablename', 'recuid') |
||
| 154 | ->from('sys_refindex') |
||
| 155 | ->where( |
||
| 156 | $queryBuilder->expr()->eq('ref_table', $queryBuilder->createNamedParameter($table)), |
||
| 157 | $queryBuilder->expr()->eq('ref_uid', $queryBuilder->createNamedParameter($item['uid'], \PDO::PARAM_INT)), |
||
| 158 | $queryBuilder->expr()->eq('deleted', $queryBuilder->createNamedParameter(0, \PDO::PARAM_INT)), |
||
| 159 | $queryBuilder->expr()->eq('workspace', $queryBuilder->createNamedParameter($workspace, \PDO::PARAM_INT)) |
||
| 160 | ) |
||
| 161 | ->execute(); |
||
| 162 | while ($row = $statement->fetch()) { |
||
| 163 | $this->registerForUpdate($row['tablename'], (int)$row['recuid'], $item['targetWorkspace']); |
||
|
|
|||
| 164 | } |
||
| 165 | } |
||
| 166 | } |
||
| 167 | } |
||
| 168 | $this->updateRegistryToItem = []; |
||
| 169 | |||
| 170 | // Drop rows from reference index if requested. Note this is performed *after* update-to-item, to |
||
| 171 | // find rows pointing to a record and register updates before rows are dropped. Needed if a record |
||
| 172 | // changes the workspace during publish: In this case all records pointing to the record in a workspace |
||
| 173 | // need to be registered for update for live workspace and after that the workspace rows can be dropped. |
||
| 174 | foreach ($this->dropRegistry as $workspace => $tableArray) { |
||
| 175 | foreach ($tableArray as $table => $uidArray) { |
||
| 176 | foreach ($uidArray as $uid) { |
||
| 177 | $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('sys_refindex'); |
||
| 178 | $queryBuilder->delete('sys_refindex') |
||
| 179 | ->where( |
||
| 180 | $queryBuilder->expr()->eq('workspace', $queryBuilder->createNamedParameter($workspace, \PDO::PARAM_INT)), |
||
| 181 | $queryBuilder->expr()->orX( |
||
| 182 | $queryBuilder->expr()->andX( |
||
| 183 | $queryBuilder->expr()->eq('tablename', $queryBuilder->createNamedParameter($table)), |
||
| 184 | $queryBuilder->expr()->eq('recuid', $queryBuilder->createNamedParameter($uid, \PDO::PARAM_INT)) |
||
| 185 | ), |
||
| 186 | $queryBuilder->expr()->andX( |
||
| 187 | $queryBuilder->expr()->eq('ref_table', $queryBuilder->createNamedParameter($table)), |
||
| 188 | $queryBuilder->expr()->eq('ref_uid', $queryBuilder->createNamedParameter($uid, \PDO::PARAM_INT)) |
||
| 189 | ) |
||
| 190 | ) |
||
| 191 | ) |
||
| 192 | ->execute(); |
||
| 193 | } |
||
| 194 | } |
||
| 195 | } |
||
| 196 | $this->dropRegistry = []; |
||
| 197 | |||
| 198 | // Perform reference index updates |
||
| 199 | $referenceIndex = GeneralUtility::makeInstance(ReferenceIndex::class); |
||
| 200 | $referenceIndex->enableRuntimeCache(); |
||
| 201 | foreach ($this->updateRegistry as $workspace => $tableArray) { |
||
| 202 | $referenceIndex->setWorkspaceId($workspace); |
||
| 203 | foreach ($tableArray as $table => $uidArray) { |
||
| 204 | foreach ($uidArray as $uid) { |
||
| 205 | $referenceIndex->updateRefIndexTable($table, $uid); |
||
| 206 | } |
||
| 207 | } |
||
| 208 | } |
||
| 209 | $this->updateRegistry = []; |
||
| 210 | } |
||
| 212 |