PHRAS-828_CTERMS-NOT-PURGED

- fix : cterms are cleared before reindexation (admin button) or populate (cli) ; terms in "stock" are preserved.
 nb.: rejected terms (red) are also purged so a term may pop-up again as candidate even if it had been rejected before.
This commit is contained in:
Jean-Yves Gaulier
2016-11-07 18:38:51 +01:00
parent 9d16ee8809
commit 75a44812d6
2 changed files with 29 additions and 2 deletions

View File

@@ -142,6 +142,7 @@ class Indexer
} }
if ($what & self::RECORDS) { if ($what & self::RECORDS) {
$databox->clearCandidates();
$this->recordIndexer->populateIndex($bulk, $databox); $this->recordIndexer->populateIndex($bulk, $databox);
// Final flush // Final flush

View File

@@ -1193,14 +1193,40 @@ class databox extends base implements ThumbnailedElement
return $this; return $this;
} }
public function clearCandidates()
{
try {
$domct = $this->get_dom_cterms();
if ($domct !== false) {
$nodesToDel = [];
for($n = $domct->documentElement->firstChild; $n; $n = $n->nextSibling) {
if(!($n->getAttribute('delbranch'))){
$nodesToDel[] = $n;
}
}
foreach($nodesToDel as $n) {
$n->parentNode->removeChild($n);
}
if(!empty($nodesToDel)) {
$this->saveCterms($domct);
}
}
} catch (\Exception $e) {
}
}
public function reindex() public function reindex()
{ {
$this->clearCandidates();
$this->get_connection()->update('pref', ['updated_on' => '0000-00-00 00:00:00'], ['prop' => 'indexes']); $this->get_connection()->update('pref', ['updated_on' => '0000-00-00 00:00:00'], ['prop' => 'indexes']);
// Set TO_INDEX flag on all records // Set TO_INDEX flag on all records
$sql = "UPDATE record SET jeton = (jeton | :token)"; $sql = "UPDATE record SET jeton = ((jeton & ~ :token_and) | :token_or)";
$stmt = $this->connection->prepare($sql); $stmt = $this->connection->prepare($sql);
$stmt->bindValue(':token', PhraseaTokens::TO_INDEX, PDO::PARAM_INT); $stmt->bindValue(':token_and', PhraseaTokens::INDEXING, PDO::PARAM_INT);
$stmt->bindValue(':token_or', PhraseaTokens::TO_INDEX, PDO::PARAM_INT);
$stmt->execute(); $stmt->execute();
$this->app['dispatcher']->dispatch( $this->app['dispatcher']->dispatch(