diff --git a/lib/classes/patch/3102.class.php b/lib/classes/patch/3102.class.php deleted file mode 100644 index 01fa90e923..0000000000 --- a/lib/classes/patch/3102.class.php +++ /dev/null @@ -1,91 +0,0 @@ -release; - } - - public function require_all_upgrades() - { - return false; - } - - /** - * - * @return Array - */ - public function concern() - { - return $this->concern; - } - - public function apply(base &$base) - { - $conn = connection::getPDOConnection(); - - $sql = 'SELECT task_id FROM task2 WHERE `class` = "task_period_upgradetov31"'; - - $stmt = $conn->prepare($sql); - $stmt->execute(); - $rowcount = $stmt->rowCount(); - $stmt->closeCursor(); - - if ($rowcount == 0) { - $sql = 'INSERT INTO `task2` - (`task_id`, `usr_id_owner`, `pid`, `status`, `crashed`, - `active`, `name`, `last_exec_time`, `class`, `settings`, `completed`) - VALUES - (null, 0, 0, "stopped", 0, 1, "upgrade to v3.1", - "0000-00-00 00:00:00", "task_period_upgradetov31", - "' . - '", -1)'; - - $stmt = $conn->prepare($sql); - $stmt->execute(); - $stmt->closeCursor(); - } - - if ($base->get_base_type() == base::DATA_BOX) { - $sql = 'UPDATE record SET sha256 = "" - WHERE sha256 IS NULL AND parent_record_id = 0'; - $stmt = $base->get_connection()->prepare($sql); - $stmt->execute(); - $stmt->closeCursor(); - } - - return true; - } -} diff --git a/lib/classes/patch/320c.class.php b/lib/classes/patch/320c.class.php index 7fc019c8d7..d6de86d19d 100644 --- a/lib/classes/patch/320c.class.php +++ b/lib/classes/patch/320c.class.php @@ -117,17 +117,6 @@ class patch_320c implements patchInterface $databox->delete_data_from_cache(databox::CACHE_META_STRUCT); $conn = connection::getPDOConnection(); - $sql = 'INSERT INTO `task2` - (`task_id`, `usr_id_owner`, `pid`, `status`, `crashed`, - `active`, `name`, `last_exec_time`, `class`, `settings`, `completed`) - VALUES - (null, 0, 0, "stopped", 0, 1, "upgrade to v3.2 for sbas ' . $databox->get_sbas_id() . '", - "0000-00-00 00:00:00", "task_period_upgradetov32", - "' . - '' . $databox->get_sbas_id() . '", -1)'; - $stmt = $conn->prepare($sql); - $stmt->execute(); - $stmt->closeCursor(); $sql = 'DELETE FROM `task2` WHERE class="readmeta"'; $stmt = $conn->prepare($sql); diff --git a/lib/classes/task/period/upgradetov31.class.php b/lib/classes/task/period/upgradetov31.class.php deleted file mode 100644 index 8291c49a70..0000000000 --- a/lib/classes/task/period/upgradetov31.class.php +++ /dev/null @@ -1,172 +0,0 @@ -getID()); - // task can't be stopped here - $core = \bootstrap::getCore(); - $appbox = appbox::get_instance($core); - $conn = $appbox->get_connection(); - $running = true; - - $todo = $this->how_many_left(); - $done = 0; - - $appbox = appbox::get_instance(\bootstrap::getCore()); - $ret = 'stopped'; - - $this->setProgress($done, $todo); - - - while ($running) { - - foreach ($appbox->get_databoxes() as $databox) { - $connbas = $databox->get_connection(); - - $sql = 'SELECT r.coll_id, r.type, r.record_id, s.path, s.file, r.xml - FROM record r, subdef s - WHERE ISNULL(uuid) - AND s.record_id = r.record_id AND s.name="document" LIMIT 100'; - - $stmt = $connbas->prepare($sql); - $stmt->execute(); - $rs = $stmt->fetchAll(PDO::FETCH_ASSOC); - $stmt->closeCursor(); - - foreach ($rs as $row) { - $pathfile = p4string::addEndSlash($row['path']) . $row['file']; - - $uuid = uuid::generate_v4(); - try { - $media = $core->guess(new \SplFileInfo($pathfile)); - $collection = \collection::get_from_coll_id($databox, $row['coll_id']); - - $file = new \Alchemy\Phrasea\Border\File($media, $collection); - $uuid = $file->getUUID(true, true); - } catch (\Exception $e) { - - } - - $sql = 'UPDATE record SET uuid = :uuid WHERE record_id = :record_id'; - - $params = array( - ':uuid' => $uuid - , ':record_id' => $row['record_id'] - ); - $stmt = $connbas->prepare($sql); - $stmt->execute($params); - $stmt->closeCursor(); - - $this->log("mise a jour du record " . $row['record_id'] . " avec uuid " . $uuid); - - $done ++; - $this->setProgress($done, $todo); - } - } - - $todo = $this->how_many_left() + $done; - - if ($done == $todo) { - $sql = 'UPDATE task2 SET status="tostop" WHERE task_id = :task_id'; - $stmt = $conn->prepare($sql); - $stmt->execute(array(':task_id' => $this->getID())); - $stmt->closeCursor(); - - $this->setProgress(0, 0); - $ret = 'todelete'; - } - - $sql = "SELECT status FROM task2 WHERE status='tostop' AND task_id=" . $this->getID(); - $stmt = $conn->prepare($sql); - $stmt->execute(array(':task_id' => $this->getID())); - $row = $stmt->fetch(PDO::FETCH_ASSOC); - $stmt->closeCursor(); - - if ($row) { - $running = false; - } - - $conn->close(); - unset($conn); - sleep(1); - $conn = connection::getPDOConnection(); - } - printf("taskid %s ending." . PHP_EOL, $this->getID()); - - sleep(1); - - printf("good bye world I was task upgrade to version 3.1" . PHP_EOL); - - flush(); - - return $ret; - } - - private function how_many_left() - { - $todo = 0; - $appbox = appbox::get_instance(\bootstrap::getCore()); - - foreach ($appbox->get_databoxes() as $databox) { - try { - $connbas = $databox->get_connection(); - - $sql = 'SELECT count(r.record_id) as total FROM record r, subdef s' - . ' WHERE ISNULL(uuid)' - . ' AND s.record_id = r.record_id AND s.name="document"'; - - $stmt = $connbas->prepare($sql); - $stmt->execute(); - $row = $stmt->fetch(PDO::FETCH_ASSOC); - $stmt->closeCursor(); - - if ($row) { - $todo += (int) $row['total']; - } - } catch (Exception $e) { - - } - } - - return $todo; - } -} - diff --git a/lib/classes/task/period/upgradetov32.class.php b/lib/classes/task/period/upgradetov32.class.php deleted file mode 100644 index 500a2dc45a..0000000000 --- a/lib/classes/task/period/upgradetov32.class.php +++ /dev/null @@ -1,347 +0,0 @@ -sbas_id = (int) $sx_task_settings->sbas_id; - parent::loadSettings($sx_task_settings); - } - - protected function run2() - { - printf("taskid %s starting." . PHP_EOL, $this->getID()); - - $registry = registry::get_instance(); - - $registry->set('GV_sphinx', false, \registry::TYPE_BOOLEAN); - - if ( ! $this->sbas_id) { - printf("sbas_id '" . $this->sbas_id . "' invalide\n"); - $this->return_value = self::RETURNSTATUS_STOPPED; - - return; - } - - try { - $databox = databox::get_instance($this->sbas_id); - $connbas = connection::getPDOConnection($this->sbas_id); - } catch (Exception $e) { - $this->return_value = self::RETURNSTATUS_STOPPED; - - return; - } - - foreach ($databox->get_meta_structure()->get_elements() as $struct_el) { - if ($struct_el->is_on_error()) { - - printf("Please verify all your databox meta fields before migrating, It seems somes are wrong\n"); - $this->return_value = self::STATE_STOPPED; - - return self::STATE_STOPPED; - } - } - - $this->running = true; - - try { - $sql = 'ALTER TABLE `record` ADD `migrated` TINYINT( 1 ) UNSIGNED NOT NULL , ADD INDEX ( `migrated` ) '; - $stmt = $connbas->prepare($sql); - $stmt->execute(); - $stmt->closeCursor(); - } catch (Exception $e) { - - } - - $n_done = 0; - - while ($this->running) { - try { - - $sql = 'SELECT COUNT(record_id) as total FROM record'; - $stmt = $connbas->prepare($sql); - $stmt->execute(); - $row = $stmt->fetch(PDO::FETCH_ASSOC); - $stmt->closeCursor(); - - $total = 0; - if ($row) { - $total = $row['total']; - } - - $sql = 'SELECT COUNT(record_id) as total FROM record WHERE migrated = 1'; - $stmt = $connbas->prepare($sql); - $stmt->execute(); - $row = $stmt->fetch(PDO::FETCH_ASSOC); - $stmt->closeCursor(); - - $done = 0; - if ($row) { - $done = $row['total']; - } - - $this->setProgress($done, $total); - - $this->running = false; - $sql = 'select record_id, coll_id, xml, BIN(status) as status - FROM record - WHERE originalname IS NULL - LIMIT 0, 500'; - - $stmt = $connbas->prepare($sql); - $stmt->execute(); - $rs = $stmt->fetchAll(PDO::FETCH_ASSOC); - $stmt->closeCursor(); - - if (count($rs) > 0) { - $this->running = true; - } - - $sql = 'UPDATE record SET originalname = :originalname WHERE record_id = :record_id'; - $stmt_original = $connbas->prepare($sql); - $connbas->beginTransaction(); - foreach ($rs as $row) { - $original = ''; - $sxe = simplexml_load_string($row['xml']); - if ($sxe) { - foreach ($sxe->doc->attributes() as $key => $value) { - $key = trim($key); - $value = trim($value); - if ($key != 'originalname') { - continue; - } - $original = basename($value); - break; - } - } - try { - $stmt_original->execute(array(':originalname' => $value, ':record_id' => $row['record_id'])); - } catch (Exception $e) { - - } - } - $connbas->commit(); - - $sql = 'select record_id, coll_id, xml, BIN(status) as status - FROM record - WHERE migrated="0" AND record_id NOT IN (select distinct record_id from technical_datas) - LIMIT 0, 500'; - - $stmt = $connbas->prepare($sql); - $stmt->execute(); - $rs = $stmt->fetchAll(PDO::FETCH_ASSOC); - $stmt->closeCursor(); - - if (count($rs) > 0) { - $this->running = true; - } - - $sql = 'REPLACE INTO technical_datas (id, record_id, name, value) - VALUES (null, :record_id, :name, :value)'; - $stmt = $connbas->prepare($sql); - $connbas->beginTransaction(); - - foreach ($rs as $row) { - try { - $record = new record_adapter($this->sbas_id, $row['record_id']); - $document = $record->get_subdef('document'); - - foreach ($document->readTechnicalDatas() as $name => $value) { - if (is_null($value)) { - continue; - } - - $stmt->execute(array( - ':record_id' => $record->get_record_id() - , ':name' => $name - , ':value' => $value - )); - } - } catch (Exception $e) { - - } - } - - $connbas->commit(); - $stmt->closeCursor(); - - $sql = 'select record_id, coll_id, xml, BIN(status) as status - FROM record - WHERE migrated=0 - LIMIT 0, 500'; - - $stmt = $connbas->prepare($sql); - $stmt->execute(); - $rs = $stmt->fetchAll(PDO::FETCH_ASSOC); - $stmt->closeCursor(); - - if (count($rs) > 0) { - $this->running = true; - } - $connbas->beginTransaction(); - - $sql = 'UPDATE record SET migrated=1 WHERE record_id = :record_id'; - $stmt = $connbas->prepare($sql); - - foreach ($rs as $row) { - try { - $record = new record_adapter($this->sbas_id, $row['record_id']); - - $metas = $databox->get_meta_structure(); - - $metadatas = array(); - - if (($sxe = simplexml_load_string($row['xml'])) != FALSE) { - $z = $sxe->xpath('/record/description'); - if ($z && is_array($z)) { - foreach ($z[0] as $ki => $vi) { - $databox_field = $metas->get_element_by_name((string) $ki); - if ( ! $databox_field) { - continue; - } - - $value = (string) $vi; - - if (trim($value) === '') { - continue; - } - - if ($databox_field->is_multi()) { - $new_value = caption_field::get_multi_values($value, $databox_field->get_separator()); - if (isset($metadatas[$databox_field->get_id()])) { - $value = array_unique(array_merge($metadatas[$databox_field->get_id()]['value'], $new_value)); - } else { - $value = $new_value; - } - } else { - $new_value = array($value); - if (isset($metadatas[$databox_field->get_id()])) { - $value = array(array_shift($metadatas[$databox_field->get_id()]['value']) . ' ' . array_shift($new_value)); - } else { - $value = $new_value; - } - } - - $metadatas[$databox_field->get_id()] = array( - 'meta_struct_id' => $databox_field->get_id() - , 'meta_id' => null - , 'value' => $value - ); - } - } - } - $record->set_metadatas($metadatas, true); - unset($record); - } catch (Exception $e) { - - } - try { - $record = new record_adapter($this->sbas_id, $row['record_id']); - $record->set_binary_status($row['status']); - unset($record); - } catch (Exception $e) { - - } - $stmt->execute(array(':record_id' => $row['record_id'])); - } - - $stmt->closeCursor(); - unset($stmt); - $connbas->commit(); - - $n_done += 500; - - $memory = memory_get_usage() >> 20; - - if ($n_done >= 5000) { - $this->return_value = task_abstract::RETURNSTATUS_TORESTART; - - return; - } - if ($memory > 100) { - $this->return_value = task_abstract::RETURNSTATUS_TORESTART; - - return; - } - } catch (Exception $e) { - - } - usleep(500000); - } - - $sql = 'ALTER TABLE `record` DROP `migrated`'; - $stmt = $connbas->prepare($sql); - $stmt->execute(); - $stmt->closeCursor(); - - $sql = "DELETE from technical_datas WHERE name='DONE'"; - $stmt = $connbas->prepare($sql); - $stmt->execute(); - $stmt->closeCursor(); - - $conn = connection::getPDOConnection(); - - printf("taskid %s ending." . PHP_EOL, $this->getID()); - sleep(1); - printf("good bye world I was task upgrade to version 3.2" . PHP_EOL); - - $sql = 'UPDATE task2 SET status="tostop" WHERE task_id = :task_id'; - - $stmt = $conn->prepare($sql); - $stmt->execute(array(':task_id' => $this->getID())); - $stmt->closeCursor(); - - $this->setProgress(0, 0); - - $this->return_value = self::RETURNSTATUS_TODELETE; - - flush(); - - return; - } -} -