diff --git a/VERSIONS_HOTLINE/88956 b/VERSIONS_HOTLINE/88956 new file mode 100644 index 0000000000000000000000000000000000000000..07e3ebd5cc03418377a715a6dd37117c0b631fee --- /dev/null +++ b/VERSIONS_HOTLINE/88956 @@ -0,0 +1,2 @@ + - ticket #88956 : Arte VOD : Amélioration du script de mise à jour des auteurs + \ No newline at end of file diff --git a/library/Class/Migration/ArteVODAuthorsOrder.php b/library/Class/Migration/ArteVODAuthorsOrder.php index d6ce62fc7b93129a0b17a478ff5044482775ec35..4b3a201519e83b62de9cec60b9f3e73c948ff24d 100644 --- a/library/Class/Migration/ArteVODAuthorsOrder.php +++ b/library/Class/Migration/ArteVODAuthorsOrder.php @@ -21,6 +21,33 @@ class Class_Migration_ArteVODAuthorsOrder { + use Trait_MemoryCleaner; + + public function updateAuthorsForAllAlbums($closure=null) { + try { + $page = 0; + while($albums = Class_Album::findAllBy(['type_doc_id' => Class_TypeDoc::ARTEVOD, + 'order' => 'id', + 'limitPage' => [$page, 500]])) { + $this->_runPage($albums, $closure); + $this->_cleanMemory(); + $page++; + } + } catch(Exception $e) { + return; + } + } + + + protected function _runPage($albums, $closure) { + foreach($albums as $album) { + $this->updateAuthors($album); + if ($closure) + $closure($album); + } + } + + public function updateAuthors($album) { $old_authors = new Storm_Collection($album->getAuthors()); $album->getMarc()->clearZone('701'); @@ -36,15 +63,6 @@ class Class_Migration_ArteVODAuthorsOrder { } - public function updateAuthorsForAllAlbums($closure=null) { - foreach(Class_Album::findAllBy(['type_doc_id' => Class_TypeDoc::ARTEVOD]) as $album) { - $this->updateAuthors($album); - if ($closure) - $closure($album); - } - } - - protected function addAuthorsTo($authors, $closure, $album) { $authors->select($closure) ->eachDo(function ($author) use ($album) diff --git a/tests/library/Class/Migration/ArteVODAuthorsOrderTest.php b/tests/library/Class/Migration/ArteVODAuthorsOrderTest.php index 17bbe703a4416452724f748102fc91dd7fbfcef7..1d326c665a7183ca75ba077738ffc9e1a2738482 100644 --- a/tests/library/Class/Migration/ArteVODAuthorsOrderTest.php +++ b/tests/library/Class/Migration/ArteVODAuthorsOrderTest.php @@ -54,7 +54,10 @@ class ArteVodLinkUpdateAuthorTest extends ModelTestCase { ->setExternalUri("http://artevod/comme-elle-respire") ->beValidated() ->save(); - (new Class_Migration_ArteVODAuthorsOrder())->updateAuthorsForAllAlbums(); + + (new Class_Migration_ArteVODAuthorsOrder()) + ->setMemoryCleaner(function() {}) + ->updateAuthorsForAllAlbums(); }