From fd05f6741fccdd94f7a9a04ee4504372b492a47d Mon Sep 17 00:00:00 2001 From: Arthur Suzuki <arthur.suzuki@biblibre.com> Date: Tue, 30 Apr 2019 16:46:52 +0200 Subject: [PATCH] hotline#88956 : add authors migration script --- VERSIONS_HOTLINE/88956 | 1 + cosmogramme/sql/patch/patch_370.php | 2 + .../Class/Migration/ArteVODAuthorsOrder.php | 55 +++++++++ scripts/artevod_update_authors.php | 6 + tests/db/UpgradeDBTest.php | 8 ++ tests/library/Class/ArteVodLinkTest.php | 6 - .../Migration/ArteVODAuthorsOrderTest.php | 108 ++++++++++++++++++ 7 files changed, 180 insertions(+), 6 deletions(-) create mode 100644 VERSIONS_HOTLINE/88956 create mode 100644 cosmogramme/sql/patch/patch_370.php create mode 100644 library/Class/Migration/ArteVODAuthorsOrder.php create mode 100644 scripts/artevod_update_authors.php create mode 100644 tests/library/Class/Migration/ArteVODAuthorsOrderTest.php diff --git a/VERSIONS_HOTLINE/88956 b/VERSIONS_HOTLINE/88956 new file mode 100644 index 00000000000..f9da33f1180 --- /dev/null +++ b/VERSIONS_HOTLINE/88956 @@ -0,0 +1 @@ + - ticket #88956 : Arte VOD : ajout d'un script de mise à jour des auteurs \ No newline at end of file diff --git a/cosmogramme/sql/patch/patch_370.php b/cosmogramme/sql/patch/patch_370.php new file mode 100644 index 00000000000..7033a8c02ad --- /dev/null +++ b/cosmogramme/sql/patch/patch_370.php @@ -0,0 +1,2 @@ +<?php +(new Class_Migration_ArteVODAuthorsOrder())->updateAuthorsForAllAlbums(); diff --git a/library/Class/Migration/ArteVODAuthorsOrder.php b/library/Class/Migration/ArteVODAuthorsOrder.php new file mode 100644 index 00000000000..d6ce62fc7b9 --- /dev/null +++ b/library/Class/Migration/ArteVODAuthorsOrder.php @@ -0,0 +1,55 @@ +<?php +/** + * Copyright (c) 2012-2019, Agence Française Informatique (AFI). All rights reserved. + * + * BOKEH is free software; you can redistribute it and/or modify + * it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by + * the Free Software Foundation. + * + * There are special exceptions to the terms and conditions of the AGPL as it + * is applied to this software (see README file). + * + * BOKEH is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU AFFERO GENERAL PUBLIC LICENSE for more details. + * + * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE + * along with BOKEH; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + + +class Class_Migration_ArteVODAuthorsOrder { + public function updateAuthors($album) { + $old_authors = new Storm_Collection($album->getAuthors()); + $album->getMarc()->clearZone('701'); + $this->addAuthorsTo($old_authors, function($author) + { + return $author->getResponsibility()=='300'; + }, $album); + $this->addAuthorsTo($old_authors, function($author) + { + return $author->getResponsibility()!='300'; + }, $album); + $album->index(); + } + + + 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) + { + $album->addAuthor($author); + }) ; + } +} diff --git a/scripts/artevod_update_authors.php b/scripts/artevod_update_authors.php new file mode 100644 index 00000000000..192ba001ca5 --- /dev/null +++ b/scripts/artevod_update_authors.php @@ -0,0 +1,6 @@ +<?php +error_reporting(E_ERROR | E_PARSE); +require(__DIR__.'/../console.php'); + +(new Class_Migration_ArteVODAuthorsOrder()) + ->updateAuthorsForAllAlbums(function($album) { echo 'updated [ ' .$album->getTitre()." ]\n";}); diff --git a/tests/db/UpgradeDBTest.php b/tests/db/UpgradeDBTest.php index c2eeb498dd2..21165b817f7 100644 --- a/tests/db/UpgradeDBTest.php +++ b/tests/db/UpgradeDBTest.php @@ -2585,3 +2585,11 @@ class UpgradeDB_369_Test extends UpgradeDBTestCase { $this->assertIndex('rendez_vous', $key); } } + + +class UpgradeDB_370_Test extends UpgradeDBTestCase { + public function prepare() {} + + /** @test */ + public function placeholderForArteVodUpdateAuthor() {} +} diff --git a/tests/library/Class/ArteVodLinkTest.php b/tests/library/Class/ArteVodLinkTest.php index 90ccaf80a99..21be0b9554c 100644 --- a/tests/library/Class/ArteVodLinkTest.php +++ b/tests/library/Class/ArteVodLinkTest.php @@ -153,10 +153,4 @@ class ArteVodLinkWithUserAndAlbumTest extends ModelTestCase { $this->_arte_vod_link->url()); } - - } - - - -?> \ No newline at end of file diff --git a/tests/library/Class/Migration/ArteVODAuthorsOrderTest.php b/tests/library/Class/Migration/ArteVODAuthorsOrderTest.php new file mode 100644 index 00000000000..17bbe703a44 --- /dev/null +++ b/tests/library/Class/Migration/ArteVODAuthorsOrderTest.php @@ -0,0 +1,108 @@ +<?php +/** + * Copyright (c) 2012-2019, Agence Française Informatique (AFI). All rights reserved. + * + * BOKEH is free software; you can redistribute it and/or modify + * it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by + * the Free Software Foundation. + * + * There are special exceptions to the terms and conditions of the AGPL as it + * is applied to this software (see README file). + * + * BOKEH is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU AFFERO GENERAL PUBLIC LICENSE for more details. + * + * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE + * along with BOKEH; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +class ArteVodLinkUpdateAuthorTest extends ModelTestCase { + protected $_storm_default_to_volatile = true; + + + public function setUp() { + parent::setUp(); + $album = $this->fixture('Class_Album', + ['id' => 5, + 'titre' => 'Comme elle respire', + ]); + $album->beArteVOD() + ->setNotes([ + ['field' => '701', + 'data' => ['a' => 'Trintignant Marie', + '4' => '005']], + ['field' => '701', + 'data' => ['a' => 'Depardieu Guillaume', + '4' => '005']], + ['field' => '701', + 'data' => ['a' => 'Salvadori Pierre', + '4' => '300']], + ['field' => '701', + 'data' => ['a' => 'Zo', + '4' => '300']], + ['field' => '701', + 'data'=> ['a' => 'Jean-François Stévenin', + '4' => '005']], + ['field' => '701', + 'data' => ['a' => 'Mastroiani', + '4' => '300']], + ]) + ->setVisible(true) + ->setExternalUri("http://artevod/comme-elle-respire") + ->beValidated() + ->save(); + (new Class_Migration_ArteVODAuthorsOrder())->updateAuthorsForAllAlbums(); + } + + + /** @test */ + public function directorShouldBeSalvadori() { + $this->assertEquals('Salvadori Pierre' , + Class_Notice::findFirstBy([])->getAuteurPrincipal()); + } + + + /** @test */ + public function secondDirectorShouldBeZo() { + $this->assertEquals('Zo|' , + Class_Notice::findFirstBy([])->getAuteursUnimarc()[1]); + } + + + /** @test */ + public function thirdDirectorShouldBeMastroiani() { + $this->assertEquals('Mastroiani|' , + Class_Notice::findFirstBy([])->getAuteursUnimarc()[2]); + } + + + /** @test */ + public function firstActorShouldBeTrintignant() { + $this->assertEquals('Trintignant Marie|' , + Class_Notice::findFirstBy([])->getAuteursUnimarc()[3]); + } + + + /** @test */ + public function secondActorShouldBeDepardieu() { + $this->assertEquals('Depardieu Guillaume|' , + Class_Notice::findFirstBy([])->getAuteursUnimarc()[4]); + } + + + /** @test */ + public function thirdActorShouldBeDepardieu() { + $this->assertEquals('Jean-François Stévenin|' , + Class_Notice::findFirstBy([])->getAuteursUnimarc()[5]); + } + + + /** @test */ + public function externalUriShouldBeCommeElleRespire() { + $this->assertContains('http://artevod/comme-elle-respire', + implode(Class_Notice::findFirstBy([])->getUnimarcZone("856"))); + } +} \ No newline at end of file -- GitLab