=') && version_compare($phpCurrentVersion, '5.5.0', '<'))) {
die("PHP {$phpVersionRequired} required. Current version is " . $phpCurrentVersion . ').');
}
require_once '../_lib/_sys/init.php';
set_time_limit(300);
header('Content-Type: text/html; charset=utf-8');
header('X-Robots-Tag: noindex, nofollow');
$confirmation = Qs_Request::getGetValue('confirmation');
$session = new Qs_Session_Namespace(basename(__FILE__));
$info = parse_url($_SERVER['REQUEST_URI']);
if (empty($confirmation) || (int) $confirmation !== (int) $session->confirmation) {
$confirmation = rand(1000, 9999);
$session->confirmation = $confirmation;
$url = $info['path'] . '?' . http_build_query(array('confirmation' => $confirmation));
echo '
Do you really want to renumber all Welds ?
';
echo 'Click here to confirm
';
exit;
}
$session->confirmation = null;
$db = Qs_Db::getInstance();
$stampIds = $db->fetchCol(
$db->select()
->from(Qs_Db::getPair('Stamp'), array('id'))
->order(array('added', 'id'))
);
$mediaObj = new App_Process_Media_Obj();
$stampObj = $mediaObj->getStampObj();
$markTable = new Qs_Db_Table(array('name' => Qs_Db::getTableName('StampMark'), 'db' => $db));
function write($msg) {
$msg = $msg ? (date('Y-m-d H:i:s') . ' ' . $msg . PHP_EOL) : PHP_EOL;
echo nl2br($msg);
}
write('processing ' . count($stampIds) . ' Charts ...');
$db->query('TRUNCATE TABLE cf_MarkNumSequence;');
foreach ($stampIds as $stampId) {
try {
write('renumbering Chart #' . $stampId . ' Welds ...');
$db->beginTransaction();
$mediaObj->clearData();
$stampObj->clearData();
$stampObj->setPrimaryKey($stampId);
$stampData = $stampObj->getData();
$mediaObj->setPrimaryKey($stampData['mediaId']);
$mediaObj->setStampId($stampData['stampId']);
$mediaObj->readMarks();
$marks = $mediaObj->getMarks();
$markNumbers = [];
$partId = $stampObj->readPartId($stampId);
$originalLatMarkNum = $lastMarkNum = (int) $stampObj->getLastMarkNum($partId, $stampData['serialNumber'], $stampData['meltLotNumber']);
foreach ($marks as $mark) {
$num = ++$lastMarkNum;
$markNumbers[] = $num;
$markTable->update(
array('num' => $num),
array('id = ?' => $mark['_markId'])
);
}
if ($marks && $originalLatMarkNum != $lastMarkNum) {
$stampObj->updateLastMarkNum($lastMarkNum, $partId, $stampData['serialNumber'], $stampData['meltLotNumber']);
}
write('... ok ' . implode(', ', $markNumbers));
$db->commit();
} catch (\Exception $e) {
write('... fail ' . $e->getMessage());
$db->rollBack();
Qs_Debug::log($e->getMessage(), 3);
}
write(PHP_EOL);
}
write('... ALL DONE');