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