| Conditions | 20 |
| Paths | 3471 |
| Total Lines | 94 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 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 |
||
| 163 | $FulltextIndex = FulltextIndex::getInstance(); |
||
| 164 | if ($indexenabled) { |
||
| 165 | $result = $FulltextIndex->addPagewords($page, $body); |
||
| 166 | if ($verbose) dbglog("Indexer: addPageWords({$page}) ".($result ? 'done' : 'failed')); |
||
| 167 | if (!$result) { |
||
| 168 | return false; |
||
| 169 | } |
||
| 170 | } else { |
||
| 171 | if ($verbose) dbglog("Indexer: full text indexing disabled for {$page}"); |
||
| 172 | // ensure the page content deleted from the Fulltext index |
||
| 173 | $result = $FulltextIndex->deletePageWords($page); |
||
| 174 | if ($verbose) dbglog("Indexer: deletePageWords({$page}) ".($result ? 'done' : 'failed')); |
||
| 175 | if (!$result) { |
||
| 176 | return false; |
||
| 177 | } |
||
| 178 | } |
||
| 179 | |||
| 180 | // update index tag file |
||
| 181 | io_saveFile($idxtag, $this->getVersion()); |
||
| 182 | if ($verbose) dbglog("Indexer: finished"); |
||
| 183 | |||
| 184 | return $result; |
||
| 185 | } |
||
| 186 | |||
| 187 | /** |
||
| 188 | * Remove a page from the index |
||
| 189 | * |
||
| 190 | * Erases entries in all known indexes. Locking is handled internally. |
||
| 191 | * |
||
| 192 | * @param string $page name of the page to index |
||
| 193 | * @param bool $verbose print status messages |
||
| 194 | * @param bool $force force reindexing even when the index is up to date |
||
| 195 | * @return bool If the function completed successfully |
||
| 196 | * |
||
| 197 | * @throws IndexLockException |
||
| 198 | * @throws IndexWriteException |
||
| 199 | * @author Satoshi Sahara <[email protected]> |
||
| 200 | * @author Tom N Harris <[email protected]> |
||
| 201 | */ |
||
| 202 | public function deletePage($page, $verbose = false, $force = false) |
||
| 203 | { |
||
| 204 | $idxtag = metaFN($page,'.indexed'); |
||
| 205 | if (!$force && !file_exists($idxtag)) { |
||
| 206 | if ($verbose) dbglog("Indexer: {$page}.indexed file does not exist, ignoring"); |
||
| 207 | return true; |
||
| 208 | } |
||
| 209 | |||
| 210 | // remove obsoleted content from Fulltext index |
||
| 211 | $FulltextIndex = FulltextIndex::getInstance(); |
||
| 212 | $result = $FulltextIndex->deletePageWords($page); |
||
| 213 | if ($verbose) dbglog("Indexer: deletePageWords({$page}) ".($result ? 'done' : 'failed')); |
||
| 214 | if (!$result) { |
||
| 215 | return false; |
||
| 216 | } |
||
| 217 | |||
| 218 | // delete all keys of the page from metadata index |
||
| 219 | $MetadataIndex = MetadataIndex::getInstance(); |
||
| 220 | $result = $MetadataIndex->deleteMetaKeys($page); |
||
| 221 | if ($verbose) dbglog("Indexer: deleteMetaKeys({$page}) ".($result ? 'done' : 'failed')); |
||
| 222 | if (!$result) { |
||
| 223 | return false; |
||
| 224 | } |
||
| 225 | |||
| 226 | // mark the page as deleted in the page.idx |
||
| 227 | $pid = $this->getPID($page); |
||
| 228 | $this->lock(); |
||
| 229 | $this->saveIndexKey('page', '', $pid, self::INDEX_MARK_DELETED.$page); |
||
| 230 | if ($verbose) dbglog("Indexer: {$page} has marked as deleted in page.idx"); |
||
| 231 | $this->unlock(); |
||
| 232 | |||
| 233 | unset(static::$pidCache[$pid]); |
||
| 234 | @unlink($idxtag); |
||
| 235 | return $result; |
||
| 236 | } |
||
| 237 | |||
| 238 | /** |
||
| 239 | * Rename a page in the search index without changing the indexed content. |
||
| 240 | * This function doesn't check if the old or new name exists in the filesystem. |
||
| 241 | * It returns an error if the old page isn't in the page list of the indexer |
||
| 242 | * and it deletes all previously indexed content of the new page. |
||
| 243 | * |
||
| 244 | * @param string $oldpage The old page name |
||
| 245 | * @param string $newpage The new page name |
||
| 246 | * @return bool If the page was successfully renamed |
||
| 247 | * @throws IndexLockException |
||
| 248 | * @throws IndexWriteException |
||
| 249 | */ |
||
| 250 | public function renamePage($oldpage, $newpage) |
||
| 251 | { |
||
| 252 | $index = $this->getIndex('page', ''); |
||
| 253 | // check if oldpage found in page.idx |
||
| 254 | $oldPid = array_search($oldpage, $index, true); |
||
| 255 | if ($oldPid === false) return false; |
||
| 256 | |||
| 257 | // check if newpage found in page.idx |
||
| 308 |