diff --git a/VERSIONS_HOTLINE/88956 b/VERSIONS_HOTLINE/88956 new file mode 100644 index 0000000000000000000000000000000000000000..f9da33f1180070e79f3ab79ecc19c348819b36bf --- /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 0000000000000000000000000000000000000000..7033a8c02ade7e8f3ee4cfb9261a36e84cd705e6 --- /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 0000000000000000000000000000000000000000..d6ce62fc7b93129a0b17a478ff5044482775ec35 --- /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 0000000000000000000000000000000000000000..192ba001ca559e62060ace69cf24c2f76dcbb860 --- /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 c2eeb498dd2d5fc8be361ca443854d2bb4bced99..21165b817f7cd68a551f4408b391af49a74076f9 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 90ccaf80a99405882082e5881a0717fa69bbbbf5..21be0b9554cc035810057807f84379f9e943de24 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 0000000000000000000000000000000000000000..17bbe703a4416452724f748102fc91dd7fbfcef7 --- /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