get_task_id()); // task can't be stopped here $appbox = appbox::get_instance(\bootstrap::getCore()); $conn = $appbox->get_connection(); $registry = $appbox->get_registry(); $running = true; if (!is_executable($registry->get('GV_exiftool'))) { printf("Exiftool is not executable, script can not process\n"); return 'stopped'; } $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.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']; if (!file_exists($pathfile)) { printf("le fichier nexiste $pathfile pas ....\n"); $uuid = uuid::generate_v4(); } else { $uuid_file = new system_file($pathfile); $uuid = $uuid_file->write_uuid(); } $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(); echo "mise a jour du record " . $row['record_id'] . " avec uuid " . $uuid . "\n"; $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->get_task_id())); $stmt->closeCursor(); $this->setProgress(0, 0); $ret = 'todelete'; } $sql = "SELECT status FROM task2 WHERE status='tostop' AND task_id=" . $this->get_task_id(); $stmt = $conn->prepare($sql); $stmt->execute(array(':task_id' => $this->get_task_id())); $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->get_task_id()); 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 (Excepiton $e) { } } return $todo; } } ?>