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