diff --git a/VERSIONS_HOTLINE/94527 b/VERSIONS_HOTLINE/94527 new file mode 100644 index 0000000000000000000000000000000000000000..10e7059de75f5a44405d58b56680472c483b42c6 --- /dev/null +++ b/VERSIONS_HOTLINE/94527 @@ -0,0 +1 @@ + - ticket #94527 : Liens Notices / Albums : ajout d'un script de maintenance des liens lorsque les types de documents des notices changent \ No newline at end of file diff --git a/library/Class/FRBR/Link.php b/library/Class/FRBR/Link.php index 8f6b3406e92afcc7dc263db612b169883c9a637c..851eb713e8a4c3dbfe92698014251283a35e72e9 100644 --- a/library/Class/FRBR/Link.php +++ b/library/Class/FRBR/Link.php @@ -351,6 +351,16 @@ class Class_FRBR_Link extends Storm_Model_Abstract { public function isSourceRecord() { - return static::TYPE_NOTICE == $this->getSourceType(); + return $this->isEndRecord('source'); + } + + + public function isTargetRecord() { + return $this->isEndRecord('target'); + } + + + public function isEndRecord($end) { + return static::TYPE_NOTICE == $this->getTypeFor($end); } } diff --git a/library/ZendAfi/Controller/Router/RewriteWithoutBaseUrl.php b/library/ZendAfi/Controller/Router/RewriteWithoutBaseUrl.php index 5b1aeb948d2abc3e3d9a4fb88885b81f368c3c38..d9f86b89f5f1c738469c6778cdadb251dec0f448 100644 --- a/library/ZendAfi/Controller/Router/RewriteWithoutBaseUrl.php +++ b/library/ZendAfi/Controller/Router/RewriteWithoutBaseUrl.php @@ -63,7 +63,7 @@ class ZendAfi_Controller_Router_RewriteWithoutBaseUrl extends Zend_Controller_Ro */ public function route(Zend_Controller_Request_Abstract $request) { $path_info = $request->getPathInfo(); - if (0===strpos($path_info, BASE_URL)) + if ('/' != BASE_URL && 0 === strpos($path_info, BASE_URL)) $request->setPathInfo(str_replace(BASE_URL, '', $path_info)); return parent::route($request); } diff --git a/scripts/repair_album_to_record_links.php b/scripts/repair_album_to_record_links.php new file mode 100644 index 0000000000000000000000000000000000000000..74421efa9799a7697826af20f6d1eacaa7ca777d --- /dev/null +++ b/scripts/repair_album_to_record_links.php @@ -0,0 +1,73 @@ +<?php +error_reporting(E_ERROR | E_PARSE); +require(__DIR__.'/../console.php'); + +echo "\n\nWelcome to the iRepair Album Links 3000 Pro tool by @liliputech & @patbator, since 1674 (tm) \n\n"; + +class Script_Album_Record_Link_Mapper { + protected $_repaired_count = 0; + + + public function repairedCount() { + return $this->_repaired_count; + } + + + public function repair($link) { + $repaired = false; + foreach(['source', 'target'] as $end) + $repaired = $repaired || $this->_repairEndIn($end, $link); + + if (!$repaired) { + echo '.'; + return; + } + + //$link->beforeSave(); + //echo json_encode($link->getRawAttributes(), JSON_PRETTY_PRINT); + //exit; + $link->save(); + echo 'R'; + $this->_repaired_count++; + } + + + protected function _repairEndIn($end, $link) { + $key = $link->getKeyFor($end); + $parts = explode('-', $key); + $type = array_pop($parts); + $truncated_key = implode('-',$parts); + + if (!$link->isEndRecord($end) || Class_TypeDoc::UNKNOWN !== (int)$type) + return false; + + $records = Class_Notice::findAllBy(['where' => 'clef_alpha like "' . $truncated_key . '%"']); + + if (!$records || 1 < count($records)) + return false; + + $record = reset($records); + if ($record->isUnknown()) + return false; + + $link->callSetterByAttributeName($end, $record->getAbsoluteUrl()); + return true; + } +} + +$mapper = new Script_Album_Record_Link_Mapper(); + +$page = 1; +while ($links = Class_FRBR_Link::findAllBy(['limitPage' => [$page, 1000]])) { + echo "\npage: $page\n"; + $page ++; + array_map([$mapper, 'repair'], + $links); + + Storm_Model_Abstract::unsetLoaders(); + Storm_Model_Loader::resetCache(); + gc_collect_cycles(); +} + +echo "\n\n repaired : " . $mapper->repairedCount(); +echo "\n\nDONE !!!!\n\n"; \ No newline at end of file