Skip to content
Snippets Groups Projects
Commit 7079c63e authored by Patrick Barroca's avatar Patrick Barroca :grin:
Browse files

Merge branch 'hotline#72723_traitement_d_integration_cosmogramme_bloque' into 'hotline'

hotline #72723 fix article indexing with deleted domains

See merge request !2545
parents 17f7c2d5 c73baf1b
Branches
Tags
3 merge requests!2547Master,!2546Hotline,!2545hotline #72723 fix article indexing with deleted domains
Pipeline #3682 passed with stage
in 31 minutes and 17 seconds
- ticket #72723 : Indexation : Correction de l'indexation d'articles liés à des domaines ayant été supprimés
\ No newline at end of file
......@@ -111,6 +111,7 @@ class Class_NoticeDomain extends Storm_Model_Abstract {
$_belongs_to = ['domain' => ['model' => 'Class_Catalogue',
'referenced_in' => 'domain_id'],
'panier_notice' => ['model' => 'Class_PanierNotice',
'referenced_in' => 'panier_id']],
......@@ -129,12 +130,23 @@ class Class_NoticeDomain extends Storm_Model_Abstract {
}
public function getNotice() {
return Class_Notice::findFirstBy(['clef_alpha' => $this->getRecordAlphaKey()]);
}
public function updateFacette() {
$this->_withRecordAndDomainDo([$this, '_updateRecordFacets']);
return $this;
}
public function beforeDelete() {
$record = $this->getNotice();
$domain = $this->getDomain();
if(!$record || !$domain)
return;
$this->_withRecordAndDomainDo([$this, '_deleteRecordFacetIfLast']);
}
protected function _deleteRecordFacetIfLast($record, $domain) {
$existing = Class_NoticeDomain::getLoader()
->countBy(['domain_id' => $domain->getId(),
'record_alpha_key' => $this->getRecordAlphaKey()]);
......@@ -145,15 +157,17 @@ class Class_NoticeDomain extends Storm_Model_Abstract {
}
public function getNotice() {
return Class_Notice::findFirstBy(['clef_alpha' => $this->getRecordAlphaKey()]);
protected function _updateRecordFacets($record, $domain) {
$record->updateFacette($domain->getFacette())->save();
}
public function updateFacette() {
$this->getNotice()
->updateFacette($this->getDomain()->getFacette())
->save();
return $this;
protected function _withRecordAndDomainDo($callback) {
$record = $this->getNotice();
$domain = $this->getDomain();
if (!$record || !$domain)
return;
return call_user_func($callback, $record, $domain);
}
}
\ No newline at end of file
......@@ -323,6 +323,32 @@ class Class_Indexation_PseudoNoticeArticleTest
}
/** @see http://forge.afi-sa.fr/issues/72723 */
class Class_Indexation_PseudoNoticeArticleWithUnknownDomainTest
extends Class_Indexation_PseudoNoticeTestCase {
public function setUp() {
parent::setUp();
$this->fixture('Class_NoticeDomain',
['id' => 189,
'domain_id' => 17,
'record_alpha_key' => 'MYARTCILE-1-----8']);
$this->fixture('Class_Article',
['id' => 1,
'titre' => 'My Artcile',
'contenu' => 'article is about...',
'domaine_ids' => '17']);
}
/** @test */
public function indexAllShouldNotHaveFatalError() {
Class_Article::indexAll();
}
}
class Class_Indexation_PseudoNoticeArticleUpdateTest
extends Class_Indexation_PseudoNoticeTestCase {
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment