Skip to content
Snippets Groups Projects
Commit 5a553713 authored by Patrick Barroca's avatar Patrick Barroca :grin:
Browse files

hotline #94527 : add repair album to record links script

parent dd8e0f90
Branches
Tags
4 merge requests!3297WIP: Master,!3203Master,!3202Hotline,!3194hotline #94527 : add repair album to record links script
Pipeline #8005 passed with stage
in 36 minutes and 25 seconds
- 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
......@@ -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);
}
}
......@@ -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);
}
......
<?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
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