Commit 64855d55 authored by Ghislain Loas's avatar Ghislain Loas

hotline #78216 upgrade digital migration

parent 186db19e
Pipeline #4745 failed with stage
in 43 minutes and 57 seconds
- ticket #78216 : Ressource numérique : amélioration de la migration vers le système de plugin.
\ No newline at end of file
......@@ -28,6 +28,6 @@ set_include_path($base_path . PATH_SEPARATOR .
get_include_path());
include_once "local.php";
include_once "fonctions/fonctions.php";
include_once "library/fonctions/fonctions.php";
require_once "library/startup.php";
?>
\ No newline at end of file
......@@ -118,6 +118,7 @@ class Class_CosmoVarLoader extends Storm_Model_Loader {
class Class_CosmoVar extends Storm_Model_Abstract {
const DOUBLE_SEARCH_NONE = 2;
const DOUBLE_SEARCH_ALPHA_KEY = 1;
const DOUBLE_SEARCH_IDS = 0;
......@@ -126,17 +127,18 @@ class Class_CosmoVar extends Storm_Model_Abstract {
const PICKUP_LOCATION_CHOICE = 1;
const PICKUP_LOCATION_PATRON = 2;
protected $_table_name = 'variables';
protected $_table_primary = 'clef';
protected $_loader_class = 'Class_CosmoVarLoader';
protected $_fixed_id = true;
protected $_table_name = 'variables',
$_table_primary = 'clef',
$_loader_class = 'Class_CosmoVarLoader',
$_fixed_id = true;
/**
* @param string $name
* @return mixed string|null
*/
public static function get($name) {
return static::getValueOf($name);
return Class_CosmoVar::getValueOf($name);
}
}
?>
\ No newline at end of file
public function set($name, $value) {
return Class_CosmoVar::setValueOf($name, $value);
}
}
\ No newline at end of file
......@@ -33,7 +33,10 @@ abstract class Class_Migration_DigitalResource_Abstract {
->upgradePermissions()
->renameBatches()
->upgradeAlbums()
->upgradeRecords();
->upgradeRecords()
->upgradeProfiles()
->upgradeArticles()
->upgradeDomains();
}
......@@ -74,7 +77,7 @@ abstract class Class_Migration_DigitalResource_Abstract {
->setRights($group->getRights())
->save();
$permission = $this->_getConfig()
->getPermission();
->getPermission();
$permission->permitTo($group, new Class_Entity());
}
......@@ -118,7 +121,6 @@ abstract class Class_Migration_DigitalResource_Abstract {
}
protected function renameBatches() {
if(!$batch = Class_Batch::findFirstBy(['type' => $this->_getOldBatchName()]))
return $this;
......@@ -159,6 +161,81 @@ abstract class Class_Migration_DigitalResource_Abstract {
}
protected function upgradeProfiles() {
foreach(Class_Profil::findTopProfils() as $profile) {
$old_doc_type = (string) $this->_getOldDocTypeId();
$doc_types = $profile->getSelTypeDoc();
if (false === strpos($doc_types, $old_doc_type))
continue;
$profile
->setSelTypeDoc(str_replace($old_doc_type,
$this->_getConfig()->getDocType(),
$doc_types))
->save();
}
return $this;
}
protected function upgradeArticles() {
if (!$old_sso = $this->_getOldSsoAction())
return $this;
foreach(Class_Article::findAll() as $article) {
$changed = false;
$replace = '/modules/' . $old_sso;
$by = '/modules/' . $this->_getConfig()->getSsoAction();
$in = [$article->getContenu(),
$article->getDescription()];
if (false !== strpos($in[0], $replace)) {
$changed = true;
$article
->setContenu(str_replace($replace,
$by,
$in[0]));
}
if (false !== strpos($in[1], $replace)) {
$changed = true;
$article
->setDescription(str_replace($replace,
$by,
$in[1]));
}
if($changed)
$article->save();
}
Class_Article::clearCache();
return $this;
}
protected function _getOldSsoAction() {
return '';
}
protected function upgradeDomains() {
foreach(Class_Catalogue::findAllBy(['type_doc not' => 'null']) as $domain) {
$old_doc_type = (string) $this->_getOldDocTypeId();
$doc_types = $domain->getTypeDoc();
if (false === strpos($doc_types, $old_doc_type))
continue;
$domain
->setTypeDoc(str_replace($old_doc_type,
$this->_getConfig()->getDocType(),
$doc_types))
->save();
}
return $this;
}
abstract protected function _getOldRightToken();
abstract protected function _getAdminVarMapping();
abstract protected function _getConfig();
......
......@@ -28,6 +28,11 @@ class Class_Migration_DigitalResource_ToutApprendre extends Class_Migration_Digi
}
protected function _getOldSsoAction() {
return 'toutapprendre';
}
protected function _getOldRightToken() {
return 6;
}
......
......@@ -274,13 +274,21 @@ class ToutApprendreHarvestTest extends ToutApprendreHarvestTestCase {
/** @test */
public function matiereShouldBeImport() {
$this->assertEquals('Bureautique / Internet',Class_CodifMatiere::find($this->_first_album->getMatiere())->getLibelle());
$this->assertEquals('Bureautique / Internet', Class_CodifMatiere::find($this->_first_album->getMatiere())->getLibelle());
}
/** @test */
public function tagsShouldBeImportAsThemeAndRubrique() {
$this->assertEquals('Multimedia;Tableur / Excel',$this->_first_album->getTags());
$this->assertEquals('Multimedia;Tableur / Excel', $this->_first_album->getTags());
}
/** @test */
public function tagsShouldBeIndexedInRecord() {
$this->_first_album->index();
$record = Class_Notice::find(1);
$this->assertContains('Z1 Z2', $record->getFacettes());
}
......
......@@ -62,14 +62,25 @@ class Class_Migration_DigitialResource_ToutApprendreTest extends ModelTestCase {
'preferences' => [],
'sous_menus' => ''] ]]]]];
$profil_adulte = $this->fixture('Class_Profil',
['id' => 22,
'parent_id' => null])
->setBrowser('opac')
->setLibelle('Profil Adulte')
->setSelTypeDoc('1;2;108')
->setCfgMenus($cfg_menus);
$this->fixture('Class_Catalogue',
['id' => 22,
'libelle' => 'should be updated',
'type_doc' => '1;2;108']);
$this->fixture('Class_Article',
['id' => 22,
'titre' => 'should be updated',
'contenu' => '<a href="/modules/toutapprendre">lien</a>',
'description' => '<a href="/modules/toutapprendre">lien</a>']);
$profil_without_toutapprendre = $this->fixture('Class_Profil',
['id' => 23,
'rewrite_url' => 'adulte'])
......@@ -196,4 +207,23 @@ class Class_Migration_DigitialResource_ToutApprendreTest extends ModelTestCase {
$this->assertEquals('2018-08-13 07:46:22', $batch->getLastRun());
$this->assertEquals('1;2;3;4;5;6;0', $batch->getPickDay());
}
/** @test */
public function profileSelTypeDocShouldContainsToutApprendre() {
$this->assertEquals('1;2;ToutApprendre', Class_Profil::find(22)->getSelTypeDoc());
}
/** @test */
public function domainTypeDocShouldContainsToutApprendre() {
$this->assertEquals('1;2;ToutApprendre', Class_Catalogue::find(22)->getTypeDoc());
}
/** @test */
public function articleWithLinkShouldContainsToutMinusApprendre() {
$this->assertContains('/modules/tout-apprendre', Class_Article::find(22)->getContenu());
$this->assertContains('/modules/tout-apprendre', Class_Article::find(22)->getDescription());
}
}
......@@ -1024,4 +1024,24 @@ class NoticeUpdateFacetsFromItemsTest extends ModelTestCase {
public function recordFacetsShouldContainsNoveltyForRoubaixAndNoveltyForLille() {
$this->assertEquals('T0 B10 YROUB HNNNN0001 HNANA0001 B11 HNNNN0002 2016-05', Class_Notice::find(5)->getFacettes());
}
}
class NoticeGetMatieresTest extends ModelTestCase {
protected $_storm_default_to_volatile = true;
/** @test */
public function shouldReturnMatieres() {
Class_CosmoVar::set('unimarc_zone_matiere',
'600abcjxyz;601abcx;602ajxyz;605a;606ajxyz;607ajxyz;608ajxyz;610aejxyz;615amnx;616acfjxy;620abcdefghi;909a');
$record = $this->fixture('Class_Notice',
['id' => 5,
'matieres' => 'ELECTRONIQUE ELEKTRONIK MANUELS MANUEL D00 ENSEIGNEMENT ANSAINEMAN SUPERIEUR SUPERIER']);
$this->assertEquals('ELECTRONIQUE ELEKTRONIK MANUELS MANUEL D00 ENSEIGNEMENT ANSAINEMAN SUPERIEUR SUPERIER', $record->getMatieres());
}
}
\ No newline at end of file
Markdown is supported
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