Skip to content
Snippets Groups Projects
Commit 0926b18a authored by Ghislain Loas's avatar Ghislain Loas
Browse files

hotline #15865 remove codif_auteur with x libelle and formes + add pagination to script

parent 724f20d4
Branches
Tags
3 merge requests!393Master,!392Hotline 6.51,!379Hotline 15865 wrong libelle codif auteur
......@@ -26,10 +26,16 @@ require_once 'ModelTestCase.php';
abstract class RepairCodifAuthorTestCase extends ModelTestCase {
protected $_guitton_pierre,
$_lebas_patrick,
$_x,
$_book;
public function setUp() {
parent::setUp();
$this->_x = $this->fixture('Class_CodifAuteur',
['id' => 3,
'libelle' => 'x',
'formes' => 'x']);
$this->_lebas_patrick = $this->fixture('Class_CodifAuteur',
['id' => 2,
'Libelle' => 'Patrickx',
......@@ -55,7 +61,10 @@ class RepairCodifAuthorUpdateTest extends RepairCodifAuthorTestCase {
Storm_Test_ObjectWrapper::onLoaderOfModel('Class_CodifAuteur')
->whenCalled('findAllBy')
->answers([$this->_guitton_pierre]);
->answers([$this->_guitton_pierre])
->whenCalled('countBy')
->answers(0);
Storm_Test_ObjectWrapper::onLoaderOfModel('Class_Notice')
->whenCalled('findFirstBy')
......@@ -79,7 +88,9 @@ class RepairCodifAuthorDeleteTest extends RepairCodifAuthorTestCase {
Storm_Test_ObjectWrapper::onLoaderOfModel('Class_CodifAuteur')
->whenCalled('findAllBy')
->answers([$this->_guitton_pierre]);
->answers([$this->_guitton_pierre])
->whenCalled('countBy')
->answers(0);
Storm_Test_ObjectWrapper::onLoaderOfModel('Class_Notice')
->whenCalled('findFirstBy')
......@@ -103,7 +114,10 @@ class RepairCodifAuthorNoUpdateTest extends RepairCodifAuthorTestCase {
Storm_Test_ObjectWrapper::onLoaderOfModel('Class_CodifAuteur')
->whenCalled('findAllBy')
->answers([$this->_lebas_patrick]);
->answers([$this->_lebas_patrick])
->whenCalled('countBy')
->answers(0);
Class_CodifAuteur::repairAllWithWrongLibelle();
}
......@@ -114,4 +128,28 @@ class RepairCodifAuthorNoUpdateTest extends RepairCodifAuthorTestCase {
$this->assertEquals('Patrickx', Class_CodifAuteur::find(2)->getLibelle());
}
}
class RepairCodifAuthorRemoveXTest extends RepairCodifAuthorTestCase {
public function setUp() {
parent::setUp();
Storm_Test_ObjectWrapper::onLoaderOfModel('Class_CodifAuteur')
->whenCalled('findAllBy')
->answers([$this->_x])
->whenCalled('countBy')
->answers(0);
Class_CodifAuteur::repairAllWithWrongLibelle();
}
/** @test */
public function libelleShouldBeRepaired() {
$this->assertEquals(null, Class_CodifAuteur::find(3));
}
}
?>
\ No newline at end of file
......@@ -45,13 +45,21 @@ class CodifAuteurLoader extends Storm_Model_Loader {
public function repairAllWithWrongLibelle() {
$auteurs = Class_CodifAuteur::findAllBy(['where' => 'libelle = formes and libelle like \'%x%\''
$auteurs = Class_CodifAuteur::findAllBy(['where' => 'BINARY libelle = formes and libelle like \'%x%\'',
'limit' => 5000
]);
$auteurs_to_repair= [];
foreach($auteurs as $auteur) {
if($auteur->getLibelle() != $auteur->getFormes() )
continue;
if(($auteur->getLibelle() === 'x') && ($auteur->getFormes() === 'x')){
$auteur->delete();
continue;
}
$notice = Class_Notice::findFirstBy(['where' => 'facettes like \'% A'.$auteur->getId().' %\'']);
if(!$notice) {
......@@ -62,6 +70,9 @@ class CodifAuteurLoader extends Storm_Model_Loader {
if($new_auteur = $notice->getAuteurWith($auteur->getFormes()))
$auteur->setLibelle($new_auteur)->save();
}
if (Class_CodifAuteur::countBy(['where' => 'BINARY libelle = formes and libelle like \'%x%\''
])>0)
$this->repairAllWithWrongLibelle();
}
}
......
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