This commit is contained in:
Romain Neutron
2012-04-26 00:55:53 +02:00
parent edbfff226e
commit ade22295ad
631 changed files with 92375 additions and 101763 deletions

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -18,146 +18,127 @@
abstract class task_appboxAbstract extends task_abstract
{
abstract protected function retrieve_content(appbox $appbox);
abstract protected function retrieve_content(appbox $appbox);
abstract protected function process_one_content(appbox $appbox, Array $row);
abstract protected function process_one_content(appbox $appbox, Array $row);
abstract protected function post_process_one_content(appbox $appbox, Array $row);
abstract protected function post_process_one_content(appbox $appbox, Array $row);
protected function run2()
{
while ($this->running)
protected function run2()
{
try
{
$conn = connection::getPDOConnection();
}
catch (Exception $e)
{
$this->log($e->getMessage());
$this->log(("Warning : abox connection lost, restarting in 10 min."));
sleep(60 * 10);
$this->running = false;
$this->return_value = self::RETURNSTATUS_TORESTART;
while ($this->running) {
try {
$conn = connection::getPDOConnection();
} catch (Exception $e) {
$this->log($e->getMessage());
$this->log(("Warning : abox connection lost, restarting in 10 min."));
sleep(60 * 10);
$this->running = false;
$this->return_value = self::RETURNSTATUS_TORESTART;
return;
}
$this->set_last_exec_time();
try {
$sql = 'SELECT task2.* FROM task2 WHERE task_id = :taskid';
$stmt = $conn->prepare($sql);
$stmt->execute(array(':taskid' => $this->get_task_id()));
$row = $stmt->fetch(PDO::FETCH_ASSOC);
$stmt->closeCursor();
$this->records_done = 0;
$duration = time();
} catch (Exception $e) {
$this->task_status = self::STATUS_TOSTOP;
$this->return_value = self::RETURNSTATUS_STOPPED;
$rs = array();
}
if ($row) {
if ( ! $this->running)
break;
$appbox = appbox::get_instance(\bootstrap::getCore());
try {
$this->load_settings(simplexml_load_string($row['settings']));
} catch (Exception $e) {
$this->log($e->getMessage());
continue;
}
$this->current_state = self::STATE_OK;
$this->process($appbox)
->check_current_state();
}
$this->increment_loops();
$this->pause($duration);
}
return;
}
}
$this->set_last_exec_time();
try
{
$sql = 'SELECT task2.* FROM task2 WHERE task_id = :taskid';
$stmt = $conn->prepare($sql);
$stmt->execute(array(':taskid' => $this->get_task_id()));
$row = $stmt->fetch(PDO::FETCH_ASSOC);
$stmt->closeCursor();
$this->records_done = 0;
$duration = time();
}
catch (Exception $e)
{
$this->task_status = self::STATUS_TOSTOP;
$this->return_value = self::RETURNSTATUS_STOPPED;
$rs = array();
}
if ($row)
{
if (!$this->running)
break;
$appbox = appbox::get_instance(\bootstrap::getCore());
try
{
$this->load_settings(simplexml_load_string($row['settings']));
}
catch (Exception $e)
{
$this->log($e->getMessage());
continue;
/**
*
* @return <type>
*/
protected function process(appbox $appbox)
{
$conn = $appbox->get_connection();
$tsub = array();
try {
/**
* GET THE RECORDS TO PROCESS ON CURRENT SBAS
*/
$rs = $this->retrieve_content($appbox);
} catch (Exception $e) {
$this->log('Error : ' . $e->getMessage());
$rs = array();
}
$this->current_state = self::STATE_OK;
$this->process($appbox)
->check_current_state();
}
$rowstodo = count($rs);
$rowsdone = 0;
$this->increment_loops();
$this->pause($duration);
}
if ($rowstodo > 0)
$this->setProgress(0, $rowstodo);
return;
}
foreach ($rs as $row) {
try {
/**
*
* @return <type>
*/
protected function process(appbox $appbox)
{
$conn = $appbox->get_connection();
$tsub = array();
try
{
/**
* GET THE RECORDS TO PROCESS ON CURRENT SBAS
*/
$rs = $this->retrieve_content($appbox);
}
catch (Exception $e)
{
$this->log('Error : ' . $e->getMessage());
$rs = array();
}
/**
* PROCESS ONE RECORD
*/
$this->process_one_content($appbox, $row);
} catch (Exception $e) {
$this->log("Exception : " . $e->getMessage()
. " " . basename($e->getFile()) . " " . $e->getLine());
}
$rowstodo = count($rs);
$rowsdone = 0;
$this->records_done ++;
$this->setProgress($rowsdone, $rowstodo);
if ($rowstodo > 0)
$this->setProgress(0, $rowstodo);
/**
* POST COIT
*/
$this->post_process_one_content($appbox, $row);
foreach ($rs as $row)
{
try
{
$this->check_memory_usage()
->check_records_done()
->check_task_status();
/**
* PROCESS ONE RECORD
*/
$this->process_one_content($appbox, $row);
}
catch (Exception $e)
{
$this->log("Exception : " . $e->getMessage()
. " " . basename($e->getFile()) . " " . $e->getLine());
}
$this->records_done++;
$this->setProgress($rowsdone, $rowstodo);
/**
* POST COIT
*/
$this->post_process_one_content($appbox, $row);
$this->check_memory_usage()
->check_records_done()
->check_task_status();
if (!$this->running)
break;
}
if ( ! $this->running)
break;
}
$this->check_memory_usage()
$this->check_memory_usage()
->check_records_done()
->check_task_status();
if ($rowstodo > 0)
$this->setProgress(0, 0);
return $this;
}
if ($rowstodo > 0)
$this->setProgress(0, 0);
return $this;
}
}

View File

@@ -21,176 +21,154 @@ abstract class task_databoxAbstract extends task_abstract
//
// abstract public function getName();
protected $mono_sbas_id;
protected $mono_sbas_id;
abstract protected function retrieve_sbas_content(databox $databox);
abstract protected function retrieve_sbas_content(databox $databox);
abstract protected function process_one_content(databox $databox, Array $row);
abstract protected function process_one_content(databox $databox, Array $row);
abstract protected function flush_records_sbas();
abstract protected function flush_records_sbas();
abstract protected function post_process_one_content(databox $databox, Array $row);
abstract protected function post_process_one_content(databox $databox, Array $row);
protected function run2()
{
while($this->running)
protected function run2()
{
try
{
$conn = connection::getPDOConnection();
}
catch(Exception $e)
{
$this->log($e->getMessage());
$this->log(("Warning : abox connection lost, restarting in 10 min."));
while ($this->running) {
try {
$conn = connection::getPDOConnection();
} catch (Exception $e) {
$this->log($e->getMessage());
$this->log(("Warning : abox connection lost, restarting in 10 min."));
for($t = 60 * 10; $this->running && $t; $t--) // DON'T do sleep(600) because it prevents ticks !
sleep(1);
for ($t = 60 * 10; $this->running && $t; $t -- ) // DON'T do sleep(600) because it prevents ticks !
sleep(1);
$this->running = false;
$this->return_value = self::RETURNSTATUS_TORESTART;
$this->running = false;
$this->return_value = self::RETURNSTATUS_TORESTART;
return;
}
return;
}
$this->set_last_exec_time();
$this->set_last_exec_time();
try
{
$sql = 'SELECT sbas_id, task2.* FROM sbas, task2 WHERE task_id = :taskid';
$stmt = $conn->prepare($sql);
$stmt->execute(array(':taskid' => $this->get_task_id()));
$rs = $stmt->fetchAll(PDO::FETCH_ASSOC);
$stmt->closeCursor();
$this->records_done = 0;
$duration = time();
}
catch(Exception $e)
{
$this->task_status = self::STATUS_TOSTOP;
$this->return_value = self::RETURNSTATUS_STOPPED;
$rs = array();
}
foreach($rs as $row)
{
if(!$this->running)
break;
try {
$sql = 'SELECT sbas_id, task2.* FROM sbas, task2 WHERE task_id = :taskid';
$stmt = $conn->prepare($sql);
$stmt->execute(array(':taskid' => $this->get_task_id()));
$rs = $stmt->fetchAll(PDO::FETCH_ASSOC);
$stmt->closeCursor();
$this->records_done = 0;
$duration = time();
} catch (Exception $e) {
$this->task_status = self::STATUS_TOSTOP;
$this->return_value = self::RETURNSTATUS_STOPPED;
$rs = array();
}
foreach ($rs as $row) {
if ( ! $this->running)
break;
$this->sbas_id = (int) $row['sbas_id'];
$this->sbas_id = (int) $row['sbas_id'];
if($this->mono_sbas_id && $this->sbas_id !== $this->mono_sbas_id)
{
continue;
if ($this->mono_sbas_id && $this->sbas_id !== $this->mono_sbas_id) {
continue;
}
if ($this->mono_sbas_id) {
$this->log('This task works on ' . phrasea::sbas_names($this->mono_sbas_id));
}
try {
$this->load_settings(simplexml_load_string($row['settings']));
} catch (Exception $e) {
$this->log($e->getMessage());
continue;
}
$this->current_state = self::STATE_OK;
$this->process_sbas()->check_current_state();
$this->process_sbas()->flush_records_sbas();
}
$this->increment_loops();
$this->pause($duration);
}
if($this->mono_sbas_id)
{
$this->log('This task works on ' . phrasea::sbas_names($this->mono_sbas_id));
}
try
{
$this->load_settings(simplexml_load_string($row['settings']));
}
catch(Exception $e)
{
$this->log($e->getMessage());
continue;
}
$this->current_state = self::STATE_OK;
$this->process_sbas()->check_current_state();
$this->process_sbas()->flush_records_sbas();
}
$this->increment_loops();
$this->pause($duration);
$this->set_status($this->return_value);
return;
}
$this->process_sbas()->check_current_state();
$this->process_sbas()->flush_records_sbas();
$this->set_status($this->return_value);
return;
}
/**
*
* @return <type>
*/
protected function process_sbas()
{
$tsub = array();
$connbas = false;
try
/**
*
* @return <type>
*/
protected function process_sbas()
{
$databox = databox::get_instance($this->sbas_id);
$connbas = $databox->get_connection();
/**
* GET THE RECORDS TO PROCESS ON CURRENT SBAS
*/
$rs = $this->retrieve_sbas_content($databox);
}
catch(Exception $e)
{
$this->log('Error : ' . $e->getMessage());
$rs = array();
}
$tsub = array();
$connbas = false;
$rowstodo = count($rs);
$rowsdone = 0;
try {
$databox = databox::get_instance($this->sbas_id);
$connbas = $databox->get_connection();
/**
* GET THE RECORDS TO PROCESS ON CURRENT SBAS
*/
$rs = $this->retrieve_sbas_content($databox);
} catch (Exception $e) {
$this->log('Error : ' . $e->getMessage());
$rs = array();
}
if($rowstodo > 0)
$this->setProgress(0, $rowstodo);
$rowstodo = count($rs);
$rowsdone = 0;
foreach($rs as $row)
{
try
{
if ($rowstodo > 0)
$this->setProgress(0, $rowstodo);
/**
* PROCESS ONE RECORD
*/
$this->process_one_content($databox, $row);
}
catch(Exception $e)
{
$this->log("Exception : " . $e->getMessage()
. " " . basename($e->getFile()) . " " . $e->getLine());
}
foreach ($rs as $row) {
try {
$this->records_done++;
$this->setProgress($rowsdone, $rowstodo);
/**
* PROCESS ONE RECORD
*/
$this->process_one_content($databox, $row);
} catch (Exception $e) {
$this->log("Exception : " . $e->getMessage()
. " " . basename($e->getFile()) . " " . $e->getLine());
}
/**
* POST COIT
*/
$this->post_process_one_content($databox, $row);
$this->records_done ++;
$this->setProgress($rowsdone, $rowstodo);
$this->check_memory_usage()
->check_records_done()
->check_task_status();
/**
* POST COIT
*/
$this->post_process_one_content($databox, $row);
if(!$this->running)
break;
}
$this->check_memory_usage()
->check_records_done()
->check_task_status();
if ( ! $this->running)
break;
}
$this->check_memory_usage()
$this->check_memory_usage()
->check_records_done()
->check_task_status();
if($connbas instanceof PDO)
{
$connbas->close();
unset($connbas);
if ($connbas instanceof PDO) {
$connbas->close();
unset($connbas);
}
if ($rowstodo > 0)
$this->setProgress(0, 0);
return $this;
}
if($rowstodo > 0)
$this->setProgress(0, 0);
return $this;
}
}

View File

@@ -17,80 +17,72 @@
*/
class task_manager
{
const STATUS_SCHED_STOPPED = 'stopped';
const STATUS_SCHED_STOPPING = 'stopping';
const STATUS_SCHED_STARTED = 'started';
const STATUS_SCHED_TOSTOP = 'tostop';
const STATUS_SCHED_STOPPED = 'stopped';
const STATUS_SCHED_STOPPING = 'stopping';
const STATUS_SCHED_STARTED = 'started';
const STATUS_SCHED_TOSTOP = 'tostop';
protected $appbox;
protected $tasks;
protected $appbox;
protected $tasks;
public function __construct(appbox &$appbox)
{
$this->appbox = $appbox;
return $this;
}
public function old_get_tasks($refresh = false)
{
if ($this->tasks && !$refresh)
return $this->tasks;
$sql = "SELECT task2.* FROM task2 ORDER BY task_id ASC";
$stmt = $this->appbox->get_connection()->prepare($sql);
$stmt->execute();
$rs = $stmt->fetchAll(PDO::FETCH_ASSOC);
$stmt->closeCursor();
$tasks = array();
foreach ($rs as $row)
public function __construct(appbox &$appbox)
{
$classname = $row['class'];
if (!class_exists($classname))
continue;
try
{
$tasks[$row['task_id']] = new $classname($row['task_id']);
}
catch (Exception $e)
{
$this->appbox = $appbox;
}
return $this;
}
$this->tasks = $tasks;
return $this->tasks;
}
public function get_tasks($refresh = false)
{
if ($this->tasks && !$refresh)
return $this->tasks;
$sql = "SELECT task2.* FROM task2 ORDER BY task_id ASC";
$stmt = $this->appbox->get_connection()->prepare($sql);
$stmt->execute();
$rs = $stmt->fetchAll(PDO::FETCH_ASSOC);
$stmt->closeCursor();
$tasks = array();
$appbox = \appbox::get_instance(\bootstrap::getCore());
$lockdir = $appbox->get_registry()->get('GV_RootPath') . 'tmp/locks/';
foreach ($rs as $row)
public function old_get_tasks($refresh = false)
{
$row['pid'] = NULL;
if ($this->tasks && ! $refresh)
return $this->tasks;
$sql = "SELECT task2.* FROM task2 ORDER BY task_id ASC";
$stmt = $this->appbox->get_connection()->prepare($sql);
$stmt->execute();
$rs = $stmt->fetchAll(PDO::FETCH_ASSOC);
$stmt->closeCursor();
$classname = $row['class'];
if (!class_exists($classname))
continue;
try
{
$tasks = array();
foreach ($rs as $row) {
$classname = $row['class'];
if ( ! class_exists($classname))
continue;
try {
$tasks[$row['task_id']] = new $classname($row['task_id']);
} catch (Exception $e) {
}
}
$this->tasks = $tasks;
return $this->tasks;
}
public function get_tasks($refresh = false)
{
if ($this->tasks && ! $refresh)
return $this->tasks;
$sql = "SELECT task2.* FROM task2 ORDER BY task_id ASC";
$stmt = $this->appbox->get_connection()->prepare($sql);
$stmt->execute();
$rs = $stmt->fetchAll(PDO::FETCH_ASSOC);
$stmt->closeCursor();
$tasks = array();
$appbox = \appbox::get_instance(\bootstrap::getCore());
$lockdir = $appbox->get_registry()->get('GV_RootPath') . 'tmp/locks/';
foreach ($rs as $row) {
$row['pid'] = NULL;
$classname = $row['class'];
if ( ! class_exists($classname))
continue;
try {
// if( ($lock = fopen( $lockdir . 'task.'.$row['task_id'].'.lock', 'a+')) )
// {
// if (flock($lock, LOCK_SH | LOCK_NB) === FALSE)
@@ -105,130 +97,116 @@ class task_manager
// }
// fclose($lock);
// }
$tasks[$row['task_id']] = new $classname($row['task_id']);
}
catch (Exception $e)
{
$tasks[$row['task_id']] = new $classname($row['task_id']);
} catch (Exception $e) {
}
}
}
$this->tasks = $tasks;
return $this->tasks;
}
$this->tasks = $tasks;
return $this->tasks;
}
/**
*
* @param <type> $task_id
* @return task_abstract
*/
public function get_task($task_id)
{
$tasks = $this->get_tasks();
if (!isset($tasks[$task_id]))
throw new Exception('Unknown task_id');
return $tasks[$task_id];
}
public function set_sched_status($status)
{
$av_status = array(
self::STATUS_SCHED_STARTED
, self::STATUS_SCHED_STOPPED
, self::STATUS_SCHED_STOPPING
, self::STATUS_SCHED_TOSTOP
);
if (!in_array($status, $av_status))
throw new Exception(sprintf('unknown status `%s` ', $status));
$sql = "UPDATE sitepreff SET schedstatus = :schedstatus, schedqtime=NOW()";
$stmt = $this->appbox->get_connection()->prepare($sql);
$stmt->execute(array(':schedstatus' => $status));
$stmt->closeCursor();
return $this;
}
public function get_scheduler_state()
{
$pid = NULL;
$appbox = appbox::get_instance(\bootstrap::getCore());
$lockdir = $appbox->get_registry()->get('GV_RootPath') . 'tmp/locks/';
if( ($schedlock = fopen( $lockdir . 'scheduler.lock', 'a+')) )
/**
*
* @param <type> $task_id
* @return task_abstract
*/
public function get_task($task_id)
{
if (flock($schedlock, LOCK_SH | LOCK_NB) === FALSE)
{
// already locked : running !
$pid = trim(fgets($schedlock, 512));
}
else
{
// can lock : not running
flock($schedlock, LOCK_UN);
}
fclose($schedlock);
$tasks = $this->get_tasks();
if ( ! isset($tasks[$task_id]))
throw new Exception('Unknown task_id');
return $tasks[$task_id];
}
$sql = "SELECT UNIX_TIMESTAMP()-UNIX_TIMESTAMP(schedqtime) AS qdelay
public function set_sched_status($status)
{
$av_status = array(
self::STATUS_SCHED_STARTED
, self::STATUS_SCHED_STOPPED
, self::STATUS_SCHED_STOPPING
, self::STATUS_SCHED_TOSTOP
);
if ( ! in_array($status, $av_status))
throw new Exception(sprintf('unknown status `%s` ', $status));
$sql = "UPDATE sitepreff SET schedstatus = :schedstatus, schedqtime=NOW()";
$stmt = $this->appbox->get_connection()->prepare($sql);
$stmt->execute(array(':schedstatus' => $status));
$stmt->closeCursor();
return $this;
}
public function get_scheduler_state()
{
$pid = NULL;
$appbox = appbox::get_instance(\bootstrap::getCore());
$lockdir = $appbox->get_registry()->get('GV_RootPath') . 'tmp/locks/';
if (($schedlock = fopen($lockdir . 'scheduler.lock', 'a+'))) {
if (flock($schedlock, LOCK_SH | LOCK_NB) === FALSE) {
// already locked : running !
$pid = trim(fgets($schedlock, 512));
} else {
// can lock : not running
flock($schedlock, LOCK_UN);
}
fclose($schedlock);
}
$sql = "SELECT UNIX_TIMESTAMP()-UNIX_TIMESTAMP(schedqtime) AS qdelay
, schedstatus AS status FROM sitepreff";
$stmt = $this->appbox->get_connection()->prepare($sql);
$stmt->execute();
$ret = $stmt->fetch(PDO::FETCH_ASSOC);
$stmt->closeCursor();
$stmt = $this->appbox->get_connection()->prepare($sql);
$stmt->execute();
$ret = $stmt->fetch(PDO::FETCH_ASSOC);
$stmt->closeCursor();
if($pid === NULL && $ret['status'] !== 'stopped')
{
// auto fix
$this->appbox->get_connection()->exec('UPDATE sitepreff SET schedstatus=\'stopped\'');
$ret['status'] = 'stopped';
}
$ret['pid'] = $pid;
return $ret;
}
public static function getAvailableTasks()
{
$registry = registry::get_instance();
$taskdir = array( $registry->get('GV_RootPath') . "lib/classes/task/period/"
, $registry->get('GV_RootPath') . "config/classes/task/period/"
);
$tasks = array();
foreach($taskdir as $path)
{
if( ($hdir = @opendir($path)) )
{
$tskin = array();
$max = 9999;
while (($max-- > 0) && (($file = readdir($hdir)) !== false))
{
if (!is_file($path . '/' . $file) || substr($file, 0, 1) == "." || substr($file, -10) != ".class.php")
continue;
$classname = 'task_period_' . substr($file, 0, strlen($file) - 10);
try
{
// $testclass = new $classname(null);
if ($classname::interfaceAvailable())
{
$tasks[] = array("class" => $classname, "name" => $classname::getName(), "err" => null);
}
if ($pid === NULL && $ret['status'] !== 'stopped') {
// auto fix
$this->appbox->get_connection()->exec('UPDATE sitepreff SET schedstatus=\'stopped\'');
$ret['status'] = 'stopped';
}
catch (Exception $e)
{
$ret['pid'] = $pid;
return $ret;
}
public static function getAvailableTasks()
{
$registry = registry::get_instance();
$taskdir = array($registry->get('GV_RootPath') . "lib/classes/task/period/"
, $registry->get('GV_RootPath') . "config/classes/task/period/"
);
$tasks = array();
foreach ($taskdir as $path) {
if (($hdir = @opendir($path))) {
$tskin = array();
$max = 9999;
while (($max -- > 0) && (($file = readdir($hdir)) !== false)) {
if ( ! is_file($path . '/' . $file) || substr($file, 0, 1) == "." || substr($file, -10) != ".class.php")
continue;
$classname = 'task_period_' . substr($file, 0, strlen($file) - 10);
try {
// $testclass = new $classname(null);
if ($classname::interfaceAvailable()) {
$tasks[] = array("class" => $classname, "name" => $classname::getName(), "err" => null);
}
} catch (Exception $e) {
}
}
closedir($hdir);
}
}
}
closedir($hdir);
}
}
return $tasks;
}
return $tasks;
}
}

View File

@@ -18,179 +18,168 @@
class task_period_apibridge extends task_appboxAbstract
{
/**
* Return the name of the task
* @return string
*/
public function getName()
{
return 'API bridge uploader';
}
/**
* Get help
* @return string
*/
public function help()
{
return '';
}
/**
*
* @param appbox $appbox
* @return Array
*/
protected function retrieve_content(appbox $appbox)
{
$status = array(Bridge_Element::STATUS_PENDING, Bridge_Element::STATUS_PROCESSING, Bridge_Element::STATUS_PROCESSING_SERVER);
$params = array();
$n = 1;
foreach ($status as $stat)
/**
* Return the name of the task
* @return string
*/
public function getName()
{
$params[':status' . $n] = $stat;
$n++;
return 'API bridge uploader';
}
$sql = 'SELECT id, account_id FROM bridge_elements
/**
* Get help
* @return string
*/
public function help()
{
return '';
}
/**
*
* @param appbox $appbox
* @return Array
*/
protected function retrieve_content(appbox $appbox)
{
$status = array(Bridge_Element::STATUS_PENDING, Bridge_Element::STATUS_PROCESSING, Bridge_Element::STATUS_PROCESSING_SERVER);
$params = array();
$n = 1;
foreach ($status as $stat) {
$params[':status' . $n] = $stat;
$n ++;
}
$sql = 'SELECT id, account_id FROM bridge_elements
WHERE (status = ' . implode(' OR status = ', array_keys($params)) . ')';
$stmt = $appbox->get_connection()->prepare($sql);
$stmt->execute($params);
$rs = $stmt->fetchAll(PDO::FETCH_ASSOC);
$stmt->closeCursor();
$stmt = $appbox->get_connection()->prepare($sql);
$stmt->execute($params);
$rs = $stmt->fetchAll(PDO::FETCH_ASSOC);
$stmt->closeCursor();
return $rs;
}
/**
*
* @param appbox $appbox
* @param array $row
* @return task_period_apibridge
*/
protected function process_one_content(appbox $appbox, Array $row)
{
try
{
$account = Bridge_Account::load_account($appbox, $row['account_id']);
$element = new Bridge_Element($appbox, $account, $row['id']);
$this->log("process " . $element->get_id() . " with status " . $element->get_status());
if ($element->get_status() == Bridge_Element::STATUS_PENDING)
$this->upload_element($element);
else
$this->update_element($element);
}
catch (Exception $e)
{
$sql = 'UPDATE bridge_elements SET status = :status WHERE id = :id';
$params = array(
':status' => Bridge_Element::STATUS_ERROR
, ':id' => $row['id']
);
$stmt = $appbox->get_connection()->prepare($sql);
$stmt->execute($params);
$stmt->closeCursor();
return $rs;
}
return $this;
}
/**
*
* @param appbox $appbox
* @param array $row
* @return task_period_apibridge
*/
protected function post_process_one_content(appbox $appbox, Array $row)
{
return $this;
}
/**
*
* @param Bridge_Element $element
* @return task_period_apibridge
*/
private function upload_element(Bridge_Element $element)
{
$account = $element->get_account();
$element->set_status(Bridge_Element::STATUS_PROCESSING);
$dist_id = null;
try
/**
*
* @param appbox $appbox
* @param array $row
* @return task_period_apibridge
*/
protected function process_one_content(appbox $appbox, Array $row)
{
$dist_id = $account->get_api()->upload($element->get_record(), $element->get_datas());
$element->set_uploaded_on(new DateTime());
}
catch (Exception $e)
{
$this->log('Error while uploading : '.$e->getMessage());
$element->set_status(Bridge_Element::STATUS_ERROR);
}
$element->set_dist_id($dist_id);
try {
$account = Bridge_Account::load_account($appbox, $row['account_id']);
$element = new Bridge_Element($appbox, $account, $row['id']);
return $this;
}
$this->log("process " . $element->get_id() . " with status " . $element->get_status());
/**
*
* @param Bridge_Element $element
* @return task_period_apibridge
*/
protected function update_element(Bridge_Element &$element)
{
$Core = bootstrap::getCore();
$account = $element->get_account();
$connector_status = $account->get_api()->get_element_status($element);
if ($element->get_status() == Bridge_Element::STATUS_PENDING)
$this->upload_element($element);
else
$this->update_element($element);
} catch (Exception $e) {
$sql = 'UPDATE bridge_elements SET status = :status WHERE id = :id';
$status = $element->get_account()->get_api()->map_connector_to_element_status($connector_status);
$error_message = $element->get_account()->get_api()->get_error_message_from_status($connector_status);
$params = array(
':status' => Bridge_Element::STATUS_ERROR
, ':id' => $row['id']
);
$previous_status = $element->get_status();
$stmt = $appbox->get_connection()->prepare($sql);
$stmt->execute($params);
$stmt->closeCursor();
}
if ($status)
{
$element->set_status($status);
$this->log('updating status for : ' . $element->get_id() . " to " . $status);
}
$element->set_connector_status($connector_status);
if ($status === $previous_status)
return;
switch ($status)
{
case Bridge_Element::STATUS_ERROR:
$params = array(
'usr_id' => $account->get_user()->get_id()
, 'reason' => $error_message
, 'account_id' => $account->get_id()
, 'sbas_id' => $element->get_record()->get_sbas_id()
, 'record_id' => $element->get_record()->get_record_id()
);
$events_mngr = eventsmanager_broker::getInstance(appbox::get_instance(\bootstrap::getCore()), $Core);
$events_mngr->trigger('__BRIDGE_UPLOAD_FAIL__', $params);
break;
default:
case Bridge_Element::STATUS_DONE:
case Bridge_Element::STATUS_PENDING:
case Bridge_Element::STATUS_PROCESSING_SERVER:
case Bridge_Element::STATUS_PROCESSING:
break;
return $this;
}
return $this;
}
/**
*
* @param appbox $appbox
* @param array $row
* @return task_period_apibridge
*/
protected function post_process_one_content(appbox $appbox, Array $row)
{
return $this;
}
/**
*
* @param Bridge_Element $element
* @return task_period_apibridge
*/
private function upload_element(Bridge_Element $element)
{
$account = $element->get_account();
$element->set_status(Bridge_Element::STATUS_PROCESSING);
$dist_id = null;
try {
$dist_id = $account->get_api()->upload($element->get_record(), $element->get_datas());
$element->set_uploaded_on(new DateTime());
} catch (Exception $e) {
$this->log('Error while uploading : ' . $e->getMessage());
$element->set_status(Bridge_Element::STATUS_ERROR);
}
$element->set_dist_id($dist_id);
return $this;
}
/**
*
* @param Bridge_Element $element
* @return task_period_apibridge
*/
protected function update_element(Bridge_Element &$element)
{
$Core = bootstrap::getCore();
$account = $element->get_account();
$connector_status = $account->get_api()->get_element_status($element);
$status = $element->get_account()->get_api()->map_connector_to_element_status($connector_status);
$error_message = $element->get_account()->get_api()->get_error_message_from_status($connector_status);
$previous_status = $element->get_status();
if ($status) {
$element->set_status($status);
$this->log('updating status for : ' . $element->get_id() . " to " . $status);
}
$element->set_connector_status($connector_status);
if ($status === $previous_status)
return;
switch ($status) {
case Bridge_Element::STATUS_ERROR:
$params = array(
'usr_id' => $account->get_user()->get_id()
, 'reason' => $error_message
, 'account_id' => $account->get_id()
, 'sbas_id' => $element->get_record()->get_sbas_id()
, 'record_id' => $element->get_record()->get_record_id()
);
$events_mngr = eventsmanager_broker::getInstance(appbox::get_instance(\bootstrap::getCore()), $Core);
$events_mngr->trigger('__BRIDGE_UPLOAD_FAIL__', $params);
break;
default:
case Bridge_Element::STATUS_DONE:
case Bridge_Element::STATUS_PENDING:
case Bridge_Element::STATUS_PROCESSING_SERVER:
case Bridge_Element::STATUS_PROCESSING:
break;
}
return $this;
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -18,133 +18,125 @@
class task_period_batchupload extends task_appboxAbstract
{
public function getName()
{
return(("Batch upload process (XML Service)"));
}
public function getName()
{
return(("Batch upload process (XML Service)"));
}
public function help()
{
return(("Hello I'm the batch upload process."));
}
public function help()
{
return(("Hello I'm the batch upload process."));
}
protected function retrieve_content(appbox $appbox)
{
$conn = $appbox->get_connection();
protected function retrieve_content(appbox $appbox)
{
$conn = $appbox->get_connection();
$sql = 'UPDATE uplfile AS f INNER JOIN uplbatch AS u USING(uplbatch_id)
$sql = 'UPDATE uplfile AS f INNER JOIN uplbatch AS u USING(uplbatch_id)
SET f.error="1", u.error="1"
WHERE u.error=0 AND u.base_id NOT IN(SELECT base_id FROM bas)';
$stmt = $conn->prepare($sql);
$stmt->execute();
$stmt->closeCursor();
$stmt = $conn->prepare($sql);
$stmt->execute();
$stmt->closeCursor();
$sql = 'SELECT uplbatch_id, sbas_id, server_coll_id, usr_id
$sql = 'SELECT uplbatch_id, sbas_id, server_coll_id, usr_id
FROM (uplbatch u INNER JOIN bas b USING(base_id))
WHERE complete="1" AND error="0" ORDER BY uplbatch_id';
$stmt = $conn->prepare($sql);
$stmt->execute();
$rs = $stmt->fetchAll(PDO::FETCH_ASSOC);
$stmt->closeCursor();
$stmt = $conn->prepare($sql);
$stmt->execute();
$rs = $stmt->fetchAll(PDO::FETCH_ASSOC);
$stmt->closeCursor();
return $rs;
}
protected function process_one_content(appbox $appbox, Array $row)
{
$appbox = appbox::get_instance(\bootstrap::getCore());
$registry = $appbox->get_registry();
$conn = $appbox->get_connection();
$session = $appbox->get_session();
$this->log(sprintf(('processing batch %s'), $row['uplbatch_id']));
$errors = '';
$path = NULL;
$coll_id = $row['server_coll_id'];
$sbas_id = $row['sbas_id'];
$usr_id = $row['usr_id'];
$batch_id = $row['uplbatch_id'];
try
{
$databox = databox::get_instance($sbas_id);
$path = $registry->get('GV_RootPath') . 'tmp/batches/' . $batch_id . '/';
if (!is_dir($path))
throw new Exception(sprintf(('Batch directory \'%s\' does not exist'), $path));
$user = User_Adapter::getInstance($usr_id, $appbox);
$auth = new Session_Authentication_None($user);
$session->authenticate($auth);
$sql = 'SELECT * FROM uplfile WHERE uplbatch_id = :batch_id ORDER BY idx';
$stmt = $conn->prepare($sql);
$stmt->execute(array(':batch_id' => $batch_id));
$rs = $stmt->fetchAll(PDO::FETCH_ASSOC);
$stmt->closeCursor();
foreach ($rs as $row2)
{
$this->log(sprintf(('archiving file \'%s\''), $row2['filename']));
try
{
$system_file = new system_file($path . '/' . $row2['idx']);
$system_file->set_phrasea_tech_field(system_file::TECH_FIELD_ORIGINALNAME, $row2['filename']);
$system_file->set_phrasea_tech_field(system_file::TECH_FIELD_PARENTDIRECTORY, '');
$system_file->set_phrasea_tech_field(system_file::TECH_FIELD_SUBPATH, '');
$meta = $system_file->extract_metadatas($databox->get_meta_structure());
$collection = collection::get_from_coll_id($databox, $coll_id);
$record = record_adapter::create($collection, $system_file, $row2['filename'], false);
$record->set_metadatas($meta['metadatas'], true);
$record->rebuild_subdefs();
$record->reindex();
unset($record);
@unlink($system_file->getPathname());
unset($system_file);
}
catch (Exception $e)
{
}
}
rmdir($path);
unset($databox);
$session->logout();
return $rs;
}
catch (Exception $e)
{
$this->log($e->getMessage());
$sql = 'UPDATE uplfile AS f INNER JOIN uplbatch AS u USING(uplbatch_id)
protected function process_one_content(appbox $appbox, Array $row)
{
$appbox = appbox::get_instance(\bootstrap::getCore());
$registry = $appbox->get_registry();
$conn = $appbox->get_connection();
$session = $appbox->get_session();
$this->log(sprintf(('processing batch %s'), $row['uplbatch_id']));
$errors = '';
$path = NULL;
$coll_id = $row['server_coll_id'];
$sbas_id = $row['sbas_id'];
$usr_id = $row['usr_id'];
$batch_id = $row['uplbatch_id'];
try {
$databox = databox::get_instance($sbas_id);
$path = $registry->get('GV_RootPath') . 'tmp/batches/' . $batch_id . '/';
if ( ! is_dir($path))
throw new Exception(sprintf(('Batch directory \'%s\' does not exist'), $path));
$user = User_Adapter::getInstance($usr_id, $appbox);
$auth = new Session_Authentication_None($user);
$session->authenticate($auth);
$sql = 'SELECT * FROM uplfile WHERE uplbatch_id = :batch_id ORDER BY idx';
$stmt = $conn->prepare($sql);
$stmt->execute(array(':batch_id' => $batch_id));
$rs = $stmt->fetchAll(PDO::FETCH_ASSOC);
$stmt->closeCursor();
foreach ($rs as $row2) {
$this->log(sprintf(('archiving file \'%s\''), $row2['filename']));
try {
$system_file = new system_file($path . '/' . $row2['idx']);
$system_file->set_phrasea_tech_field(system_file::TECH_FIELD_ORIGINALNAME, $row2['filename']);
$system_file->set_phrasea_tech_field(system_file::TECH_FIELD_PARENTDIRECTORY, '');
$system_file->set_phrasea_tech_field(system_file::TECH_FIELD_SUBPATH, '');
$meta = $system_file->extract_metadatas($databox->get_meta_structure());
$collection = collection::get_from_coll_id($databox, $coll_id);
$record = record_adapter::create($collection, $system_file, $row2['filename'], false);
$record->set_metadatas($meta['metadatas'], true);
$record->rebuild_subdefs();
$record->reindex();
unset($record);
@unlink($system_file->getPathname());
unset($system_file);
} catch (Exception $e) {
}
}
rmdir($path);
unset($databox);
$session->logout();
} catch (Exception $e) {
$this->log($e->getMessage());
$sql = 'UPDATE uplfile AS f INNER JOIN uplbatch AS u USING(uplbatch_id)
SET f.error="1", u.error="1"
WHERE u.uplbatch_id = :batch_id';
$stmt = $conn->prepare($sql);
$stmt->execute(array(':batch_id' => $batch_id));
$stmt->closeCursor();
$errors = '1';
$stmt = $conn->prepare($sql);
$stmt->execute(array(':batch_id' => $batch_id));
$stmt->closeCursor();
$errors = '1';
}
$sql = 'UPDATE uplbatch SET complete="2", error = :error
WHERE uplbatch_id = :batch_id';
$stmt = $conn->prepare($sql);
$stmt->execute(array(':error' => $errors, ':batch_id' => $batch_id));
$stmt->closeCursor();
$this->log(sprintf(('finishing batch %s'), $row['uplbatch_id']));
return $this;
}
$sql = 'UPDATE uplbatch SET complete="2", error = :error
WHERE uplbatch_id = :batch_id';
$stmt = $conn->prepare($sql);
$stmt->execute(array(':error' => $errors, ':batch_id' => $batch_id));
$stmt->closeCursor();
$this->log(sprintf(('finishing batch %s'), $row['uplbatch_id']));
return $this;
}
protected function post_process_one_content(appbox $appbox, Array $row)
{
return $this;
}
protected function post_process_one_content(appbox $appbox, Array $row)
{
return $this;
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -17,66 +17,61 @@
*/
class task_period_emptyColl extends task_appboxAbstract
{
protected $base_id;
protected $suicidable = true;
protected $base_id;
protected $suicidable = true;
public function getName()
{
return(_("Vidage de collection"));
}
public static function interfaceAvailable()
{
return false;
}
public function help()
{
return("Vide une collection");
}
protected function load_settings(SimpleXMLElement $sx_task_settings)
{
$this->base_id = (int) $sx_task_settings->base_id;
parent::load_settings($sx_task_settings);
return $this;
}
protected $total_records = 0;
protected function retrieve_content(appbox $appbox)
{
if(!$this->base_id)
public function getName()
{
$this->current_state = self::STATE_FINISHED;
return;
}
$collection = collection::get_from_base_id($this->base_id);
$this->total_records = $collection->get_record_amount();
$collection->empty_collection(200);
$this->records_done +=$this->total_records;
$this->setProgress($this->records_done, $this->total_records);
if ($this->total_records == 0)
{
$this->current_state = self::STATE_FINISHED;
$this->log('Job finished');
return(_("Vidage de collection"));
}
return array();
}
public static function interfaceAvailable()
{
return false;
}
protected function process_one_content(appbox $appbox, Array $row)
{
return $this;
}
public function help()
{
return("Vide une collection");
}
protected function post_process_one_content(appbox $appbox, Array $row)
{
return $this;
}
protected function load_settings(SimpleXMLElement $sx_task_settings)
{
$this->base_id = (int) $sx_task_settings->base_id;
parent::load_settings($sx_task_settings);
return $this;
}
protected $total_records = 0;
protected function retrieve_content(appbox $appbox)
{
if ( ! $this->base_id) {
$this->current_state = self::STATE_FINISHED;
return;
}
$collection = collection::get_from_base_id($this->base_id);
$this->total_records = $collection->get_record_amount();
$collection->empty_collection(200);
$this->records_done +=$this->total_records;
$this->setProgress($this->records_done, $this->total_records);
if ($this->total_records == 0) {
$this->current_state = self::STATE_FINISHED;
$this->log('Job finished');
}
return array();
}
protected function process_one_content(appbox $appbox, Array $row)
{
return $this;
}
protected function post_process_one_content(appbox $appbox, Array $row)
{
return $this;
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -16,370 +16,332 @@
*/
class task_period_ftpPull extends task_appboxAbstract
{
protected $debug = false;
protected $proxy;
protected $proxyport;
protected $host;
protected $port;
protected $user;
protected $password;
protected $ssl;
protected $passive;
protected $ftppath;
protected $localpath;
protected $debug = false;
protected $proxy;
protected $proxyport;
protected $host;
protected $port;
protected $user;
protected $password;
protected $ssl;
protected $passive;
protected $ftppath;
protected $localpath;
public function getName()
{
return(_("task::ftp:FTP Pull"));
}
public function help()
{
return '';
}
public function graphic2xml($oldxml)
{
$request = http_request::getInstance();
$parm2 = $request->get_parms(
"proxy", "proxyport", "host", "port", "user"
, "password", "ssl", "ftppath", "localpath"
, "passive", "period"
);
if ($dom = @DOMDocument::loadXML($oldxml))
public function getName()
{
$xmlchanged = false;
foreach (array("str:proxy", "str:proxyport", "str:period", "boo:passive", "boo:ssl", "str:password", "str:user", "str:ftppath", "str:localpath", "str:port", "str:host") as $pname)
{
$ptype = substr($pname, 0, 3);
$pname = substr($pname, 4);
$pvalue = $parm2[$pname];
if ($ns = $dom->getElementsByTagName($pname)->item(0))
{
// le champ existait dans le xml, on supprime son ancienne valeur (tout le contenu)
while (($n = $ns->firstChild))
$ns->removeChild($n);
}
else
{
// le champ n'existait pas dans le xml, on le cree
$dom->documentElement->appendChild($dom->createTextNode("\t"));
$ns = $dom->documentElement->appendChild($dom->createElement($pname));
$dom->documentElement->appendChild($dom->createTextNode("\n"));
}
// on fixe sa valeur
switch ($ptype)
{
case "str":
$ns->appendChild($dom->createTextNode($pvalue));
break;
case "boo":
$ns->appendChild($dom->createTextNode($pvalue ? '1' : '0'));
break;
}
$xmlchanged = true;
}
return(_("task::ftp:FTP Pull"));
}
return($dom->saveXML());
}
public function xml2graphic($xml, $form)
{
if (($sxml = simplexml_load_string($xml))) // in fact XML IS always valid here...
public function help()
{
// ... but we could check for safe values (ex. 0 < period < 3600)
?>
<script type="text/javascript">
<?php echo $form ?>.proxy.value = "<?php echo p4string::MakeString($sxml->proxy, "js", '"') ?>";
<?php echo $form ?>.proxyport.value = "<?php echo p4string::MakeString($sxml->proxyport, "js", '"') ?>";
<?php echo $form ?>.period.value = "<?php echo p4string::MakeString($sxml->period, "js", '"') ?>";
<?php echo $form ?>.localpath.value = "<?php echo p4string::MakeString($sxml->localpath, "js", '"') ?>";
<?php echo $form ?>.ftppath.value = "<?php echo p4string::MakeString($sxml->ftppath, "js", '"') ?>";
<?php echo $form ?>.host.value = "<?php echo p4string::MakeString($sxml->host, "js", '"') ?>";
<?php echo $form ?>.port.value = "<?php echo p4string::MakeString($sxml->port, "js", '"') ?>";
<?php echo $form ?>.user.value = "<?php echo p4string::MakeString($sxml->user, "js", '"') ?>";
<?php echo $form ?>.password.value = "<?php echo p4string::MakeString($sxml->password, "js", '"') ?>";
<?php echo $form ?>.ssl.checked = <?php echo p4field::isyes($sxml->ssl) ? "true" : 'false' ?>;
<?php echo $form ?>.passive.checked = <?php echo p4field::isyes($sxml->passive) ? "true" : 'false' ?>;
</script>
<?php
return("");
return '';
}
else // ... so we NEVER come here
public function graphic2xml($oldxml)
{
// bad xml
return("BAD XML");
}
}
$request = http_request::getInstance();
public function printInterfaceJS()
{
global $parm;
?>
<script type="text/javascript">
function chgxmltxt(textinput, fieldname)
{
setDirty();
}
function chgxmlck(checkinput, fieldname)
{
setDirty();
}
function chgxmlpopup(popupinput, fieldname)
{
setDirty();
}
</script>
<?php
}
function getGraphicForm()
{
return true;
}
public function printInterfaceHTML()
{
global $parm;
ob_start();
?>
<form name="graphicForm" onsubmit="return(false);" method="post">
<br/>
<?php echo('task::ftp:proxy') ?>
<input type="text" name="proxy" style="width:400px;" onchange="chgxmltxt(this, 'proxy');"><br/>
<br/>
<?php echo('task::ftp:proxy port') ?>
<input type="text" name="proxyport" style="width:400px;" onchange="chgxmltxt(this, 'proxyport');"><br/>
<br/>
<?php echo('task::ftp:host') ?>
<input type="text" name="host" style="width:400px;" onchange="chgxmltxt(this, 'host');"><br/>
<br/>
<?php echo('task::ftp:port') ?>
<input type="text" name="port" style="width:400px;" onchange="chgxmltxt(this, 'port');"><br/>
<br/>
<?php echo('task::ftp:user') ?>
<input type="text" name="user" style="width:400px;" onchange="chgxmltxt(this, 'user');"><br/>
<br/>
<?php echo('task::ftp:password') ?>
<input type="password" name="password" style="width:400px;" onchange="chgxmltxt(this, 'password');"><br/>
<br/>
<?php echo('task::ftp:chemin distant') ?>
<input type="text" name="ftppath" style="width:400px;" onchange="chgxmltxt(this, 'ftppath');"><br/>
<br/>
<?php echo('task::ftp:localpath') ?>
<input type="text" name="localpath" style="width:400px;" onchange="chgxmltxt(this, 'localpath');"><br/>
<br/>
<input type="checkbox" name="passive" onchange="chgxmlck(this)">
<?php echo _('task::ftp:mode passif') ?>
<br/>
<input type="checkbox" name="ssl" onchange="chgxmlck(this)">
<?php echo _('task::ftp:utiliser SSL') ?>
<br/>
<?php echo('task::_common_:periodicite de la tache') ?>
<input type="text" name="period" style="width:40px;" onchange="chgxmltxt(this, 'period');">
&nbsp;<?php echo('task::_common_:minutes (unite temporelle)') ?><br/>
</form>
<?php
$out = ob_get_clean();
return $out;
}
public function saveChanges(connection_pdo $conn, $taskid, &$taskrow)
{
$request = http_request::getInstance();
$parm = $request->get_parms(
"xml", "name", "active", "proxy", "proxyport", "period"
, "localpath", "ftppath", "port", "host", "user"
, "password", "passive", "ssl", "debug"
);
if ($parm["xml"] === null)
{
// pas de xml 'raw' : on accepte les champs 'graphic view'
if ($domTaskSettings = DOMDocument::loadXML($taskrow["settings"]))
{
$xmlchanged = false;
foreach (array("proxy", "proxyport", "period", "host", "port", "user", "password", "ssl", "passive", "localpath", "ftppath") as $f)
{
if ($parm[$f] !== NULL)
{
if ($ns = $domTaskSettings->getElementsByTagName($f)->item(0))
{
// le champ existait dans le xml, on supprime son ancienne valeur (tout le contenu)
while (($n = $ns->firstChild))
$ns->removeChild($n);
$parm2 = $request->get_parms(
"proxy", "proxyport", "host", "port", "user"
, "password", "ssl", "ftppath", "localpath"
, "passive", "period"
);
if ($dom = @DOMDocument::loadXML($oldxml)) {
$xmlchanged = false;
foreach (array("str:proxy", "str:proxyport", "str:period", "boo:passive", "boo:ssl", "str:password", "str:user", "str:ftppath", "str:localpath", "str:port", "str:host") as $pname) {
$ptype = substr($pname, 0, 3);
$pname = substr($pname, 4);
$pvalue = $parm2[$pname];
if ($ns = $dom->getElementsByTagName($pname)->item(0)) {
// le champ existait dans le xml, on supprime son ancienne valeur (tout le contenu)
while (($n = $ns->firstChild))
$ns->removeChild($n);
} else {
// le champ n'existait pas dans le xml, on le cree
$dom->documentElement->appendChild($dom->createTextNode("\t"));
$ns = $dom->documentElement->appendChild($dom->createElement($pname));
$dom->documentElement->appendChild($dom->createTextNode("\n"));
}
// on fixe sa valeur
switch ($ptype) {
case "str":
$ns->appendChild($dom->createTextNode($pvalue));
break;
case "boo":
$ns->appendChild($dom->createTextNode($pvalue ? '1' : '0'));
break;
}
$xmlchanged = true;
}
else
{
// le champ n'existait pas dans le xml, on le cree
$domTaskSettings->documentElement->appendChild($domTaskSettings->createTextNode("\t"));
$ns = $domTaskSettings->documentElement->appendChild($domTaskSettings->createElement($f));
$domTaskSettings->documentElement->appendChild($domTaskSettings->createTextNode("\n"));
}
// on fixe sa valeur
$ns->appendChild($domTaskSettings->createTextNode($parm[$f]));
$xmlchanged = true;
}
}
if ($xmlchanged)
$parm["xml"] = $domTaskSettings->saveXML();
}
return($dom->saveXML());
}
// si on doit changer le xml, on verifie qu'il est valide
if ($parm["xml"] && !DOMDocument::loadXML($parm["xml"]))
public function xml2graphic($xml, $form)
{
if (($sxml = simplexml_load_string($xml))) { // in fact XML IS always valid here...
// ... but we could check for safe values (ex. 0 < period < 3600)
?>
<script type="text/javascript">
<?php echo $form ?>.proxy.value = "<?php echo p4string::MakeString($sxml->proxy, "js", '"') ?>";
<?php echo $form ?>.proxyport.value = "<?php echo p4string::MakeString($sxml->proxyport, "js", '"') ?>";
<?php echo $form ?>.period.value = "<?php echo p4string::MakeString($sxml->period, "js", '"') ?>";
return(false);
$sql = "";
$params = array(':task_id' => $taskid);
if ($parm["xml"] !== NULL)
{
$sql .= ( $sql ? " ," : "") . "settings = :settings";
$params[':settings'] = $parm['xml'];
}
if ($parm["name"] !== NULL)
{
$sql .= ( $sql ? " ," : "") . "name = :name";
$params[':name'] = $parm['name'];
}
if ($parm["active"] !== NULL)
{
$sql .= ( $sql ? " ," : "") . "active = :active";
$params[':active'] = $parm['active'];
<?php echo $form ?>.localpath.value = "<?php echo p4string::MakeString($sxml->localpath, "js", '"') ?>";
<?php echo $form ?>.ftppath.value = "<?php echo p4string::MakeString($sxml->ftppath, "js", '"') ?>";
<?php echo $form ?>.host.value = "<?php echo p4string::MakeString($sxml->host, "js", '"') ?>";
<?php echo $form ?>.port.value = "<?php echo p4string::MakeString($sxml->port, "js", '"') ?>";
<?php echo $form ?>.user.value = "<?php echo p4string::MakeString($sxml->user, "js", '"') ?>";
<?php echo $form ?>.password.value = "<?php echo p4string::MakeString($sxml->password, "js", '"') ?>";
<?php echo $form ?>.ssl.checked = <?php echo p4field::isyes($sxml->ssl) ? "true" : 'false' ?>;
<?php echo $form ?>.passive.checked = <?php echo p4field::isyes($sxml->passive) ? "true" : 'false' ?>;
</script>
<?php
return("");
} else { // ... so we NEVER come here
// bad xml
return("BAD XML");
}
}
if ($sql)
public function printInterfaceJS()
{
try
{
$sql = "UPDATE task2 SET $sql WHERE task_id = :task_id";
$stmt = $conn->prepare($sql);
$stmt->execute($params);
$stmt->closeCursor();
global $parm;
?>
<script type="text/javascript">
function chgxmltxt(textinput, fieldname)
{
setDirty();
}
function chgxmlck(checkinput, fieldname)
{
setDirty();
}
function chgxmlpopup(popupinput, fieldname)
{
setDirty();
}
</script>
<?php
}
function getGraphicForm()
{
return true;
}
catch (Exception $e)
{
return false;
}
}
else
public function printInterfaceHTML()
{
return true;
global $parm;
ob_start();
?>
<form name="graphicForm" onsubmit="return(false);" method="post">
<br/>
<?php echo('task::ftp:proxy') ?>
<input type="text" name="proxy" style="width:400px;" onchange="chgxmltxt(this, 'proxy');"><br/>
<br/>
<?php echo('task::ftp:proxy port') ?>
<input type="text" name="proxyport" style="width:400px;" onchange="chgxmltxt(this, 'proxyport');"><br/>
<br/>
<?php echo('task::ftp:host') ?>
<input type="text" name="host" style="width:400px;" onchange="chgxmltxt(this, 'host');"><br/>
<br/>
<?php echo('task::ftp:port') ?>
<input type="text" name="port" style="width:400px;" onchange="chgxmltxt(this, 'port');"><br/>
<br/>
<?php echo('task::ftp:user') ?>
<input type="text" name="user" style="width:400px;" onchange="chgxmltxt(this, 'user');"><br/>
<br/>
<?php echo('task::ftp:password') ?>
<input type="password" name="password" style="width:400px;" onchange="chgxmltxt(this, 'password');"><br/>
<br/>
<?php echo('task::ftp:chemin distant') ?>
<input type="text" name="ftppath" style="width:400px;" onchange="chgxmltxt(this, 'ftppath');"><br/>
<br/>
<?php echo('task::ftp:localpath') ?>
<input type="text" name="localpath" style="width:400px;" onchange="chgxmltxt(this, 'localpath');"><br/>
<br/>
<input type="checkbox" name="passive" onchange="chgxmlck(this)">
<?php echo _('task::ftp:mode passif') ?>
<br/>
<input type="checkbox" name="ssl" onchange="chgxmlck(this)">
<?php echo _('task::ftp:utiliser SSL') ?>
<br/>
<?php echo('task::_common_:periodicite de la tache') ?>
<input type="text" name="period" style="width:40px;" onchange="chgxmltxt(this, 'period');">
&nbsp;<?php echo('task::_common_:minutes (unite temporelle)') ?><br/>
</form>
<?php
$out = ob_get_clean();
return $out;
}
}
protected function load_settings(SimpleXMLElement $sx_task_settings)
{
$this->proxy = (string) $sx_task_settings->proxy;
$this->proxyport = (string) $sx_task_settings->proxyport;
$this->host = (string) ($sx_task_settings->host);
$this->port = (string) ($sx_task_settings->port);
$this->user = (string) ($sx_task_settings->user);
$this->password = (string) ($sx_task_settings->password);
$this->ssl = !!((string) ($sx_task_settings->ssl));
$this->passive = !!((string) ($sx_task_settings->passive));
$this->ftppath = (string) ($sx_task_settings->ftppath);
$this->localpath = (string) ($sx_task_settings->localpath);
parent::load_settings($sx_task_settings);
return $this;
}
protected function retrieve_content(appbox $appbox)
{
try
public function saveChanges(connection_pdo $conn, $taskid, &$taskrow)
{
if (!is_dir($this->localpath) || !system_file::mkdir($this->localpath))
throw new Exception("$this->localpath is not writeable\n");
$request = http_request::getInstance();
if (!is_writeable($this->localpath))
throw new Exception("$this->localpath is not writeable\n");
$parm = $request->get_parms(
"xml", "name", "active", "proxy", "proxyport", "period"
, "localpath", "ftppath", "port", "host", "user"
, "password", "passive", "ssl", "debug"
);
$ftp = new ftpclient($this->host, $port, 90, $this->ssl, $this->proxy, $this->proxyport);
$ftp->login($this->user, $this->password);
$ftp->chdir($this->ftppath);
$list_1 = $ftp->list_directory(true);
$todo = count($list_1);
$this->setProgress($done, $todo);
if ($this->debug)
echo "attente de 25sec pour avoir les fichiers froids...\n";
sleep(25);
$list_2 = $ftp->list_directory(true);
foreach ($list_1 as $filepath => $timestamp)
{
$done++;
$this->setProgress($done, $todo);
if (!isset($list_2[$filepath]))
{
if ($this->debug)
echo "le fichier $filepath a disparu...\n";
continue;
}
if ($list_2[$filepath] !== $timestamp)
{
if ($this->debug)
echo "le fichier $filepath a ete modifie depuis le dernier passage...\n";
continue;
if ($parm["xml"] === null) {
// pas de xml 'raw' : on accepte les champs 'graphic view'
if ($domTaskSettings = DOMDocument::loadXML($taskrow["settings"])) {
$xmlchanged = false;
foreach (array("proxy", "proxyport", "period", "host", "port", "user", "password", "ssl", "passive", "localpath", "ftppath") as $f) {
if ($parm[$f] !== NULL) {
if ($ns = $domTaskSettings->getElementsByTagName($f)->item(0)) {
// le champ existait dans le xml, on supprime son ancienne valeur (tout le contenu)
while (($n = $ns->firstChild))
$ns->removeChild($n);
} else {
// le champ n'existait pas dans le xml, on le cree
$domTaskSettings->documentElement->appendChild($domTaskSettings->createTextNode("\t"));
$ns = $domTaskSettings->documentElement->appendChild($domTaskSettings->createElement($f));
$domTaskSettings->documentElement->appendChild($domTaskSettings->createTextNode("\n"));
}
// on fixe sa valeur
$ns->appendChild($domTaskSettings->createTextNode($parm[$f]));
$xmlchanged = true;
}
}
if ($xmlchanged)
$parm["xml"] = $domTaskSettings->saveXML();
}
}
$finalpath = p4string::addEndSlash($this->localpath) . ($filepath[0] == '/' ? mb_substr($filepath, 1) : $filepath);
echo "Ok pour rappatriement de $filepath vers $finalpath\n";
// si on doit changer le xml, on verifie qu'il est valide
if ($parm["xml"] && ! DOMDocument::loadXML($parm["xml"]))
return(false);
try
{
if (file_exists($finalpath))
throw new Exception("Un fichier du meme nom ($finalpath) existe deja...");
system_file::mkdir(dirname($finalpath));
$ftp->get($finalpath, $filepath);
$ftp->delete($filepath);
$sql = "";
$params = array(':task_id' => $taskid);
if ($parm["xml"] !== NULL) {
$sql .= ( $sql ? " ," : "") . "settings = :settings";
$params[':settings'] = $parm['xml'];
}
catch (Exception $e)
{
if ($this->debug)
echo "Erreur lors du rappatriement de $filepath : " . $e->getMessage() . "\n";
if ($parm["name"] !== NULL) {
$sql .= ( $sql ? " ," : "") . "name = :name";
$params[':name'] = $parm['name'];
}
if ($parm["active"] !== NULL) {
$sql .= ( $sql ? " ," : "") . "active = :active";
$params[':active'] = $parm['active'];
}
}
$ftp->close();
if ($sql) {
try {
$sql = "UPDATE task2 SET $sql WHERE task_id = :task_id";
$stmt = $conn->prepare($sql);
$stmt->execute($params);
$stmt->closeCursor();
$this->setProgress(0, 0);
return true;
} catch (Exception $e) {
return false;
}
} else {
return true;
}
}
catch (Exception $e)
protected function load_settings(SimpleXMLElement $sx_task_settings)
{
if (isset($ftp) && $ftp instanceof ftpclient)
$ftp->close();
echo $e->getMessage() . "\n";
$this->proxy = (string) $sx_task_settings->proxy;
$this->proxyport = (string) $sx_task_settings->proxyport;
$this->host = (string) ($sx_task_settings->host);
$this->port = (string) ($sx_task_settings->port);
$this->user = (string) ($sx_task_settings->user);
$this->password = (string) ($sx_task_settings->password);
$this->ssl = ! ! ((string) ($sx_task_settings->ssl));
$this->passive = ! ! ((string) ($sx_task_settings->passive));
$this->ftppath = (string) ($sx_task_settings->ftppath);
$this->localpath = (string) ($sx_task_settings->localpath);
parent::load_settings($sx_task_settings);
return $this;
}
}
protected function process_one_content(appbox $appbox, Array $row)
{
protected function retrieve_content(appbox $appbox)
{
try {
if ( ! is_dir($this->localpath) || ! system_file::mkdir($this->localpath))
throw new Exception("$this->localpath is not writeable\n");
}
if ( ! is_writeable($this->localpath))
throw new Exception("$this->localpath is not writeable\n");
protected function post_process_one_content(appbox $appbox, Array $row)
{
$ftp = new ftpclient($this->host, $port, 90, $this->ssl, $this->proxy, $this->proxyport);
$ftp->login($this->user, $this->password);
$ftp->chdir($this->ftppath);
$list_1 = $ftp->list_directory(true);
}
$todo = count($list_1);
$this->setProgress($done, $todo);
if ($this->debug)
echo "attente de 25sec pour avoir les fichiers froids...\n";
sleep(25);
$list_2 = $ftp->list_directory(true);
foreach ($list_1 as $filepath => $timestamp) {
$done ++;
$this->setProgress($done, $todo);
if ( ! isset($list_2[$filepath])) {
if ($this->debug)
echo "le fichier $filepath a disparu...\n";
continue;
}
if ($list_2[$filepath] !== $timestamp) {
if ($this->debug)
echo "le fichier $filepath a ete modifie depuis le dernier passage...\n";
continue;
}
$finalpath = p4string::addEndSlash($this->localpath) . ($filepath[0] == '/' ? mb_substr($filepath, 1) : $filepath);
echo "Ok pour rappatriement de $filepath vers $finalpath\n";
try {
if (file_exists($finalpath))
throw new Exception("Un fichier du meme nom ($finalpath) existe deja...");
system_file::mkdir(dirname($finalpath));
$ftp->get($finalpath, $filepath);
$ftp->delete($filepath);
} catch (Exception $e) {
if ($this->debug)
echo "Erreur lors du rappatriement de $filepath : " . $e->getMessage() . "\n";
}
}
$ftp->close();
$this->setProgress(0, 0);
} catch (Exception $e) {
if (isset($ftp) && $ftp instanceof ftpclient)
$ftp->close();
echo $e->getMessage() . "\n";
}
}
protected function process_one_content(appbox $appbox, Array $row)
{
}
protected function post_process_one_content(appbox $appbox, Array $row)
{
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -16,319 +16,303 @@
*/
class task_period_subdef extends task_databoxAbstract
{
/**
* Record buffer for writing meta datas after building subdefs
*
* @var array
*/
protected $recs_to_write = array();
/**
* Record buffer for writing meta datas after building subdefs
*
* @var array
*/
protected $recs_to_write = array();
/**
* Maximum buffer size before flushing records
*
* @var <type>
*/
protected $record_buffer_size;
/**
* Maximum buffer size before flushing records
*
* @var <type>
*/
protected $record_buffer_size;
/**
* Return about text
*
* @return <type>
*/
function help()
{
return(
_("task::subdef:creation des sous definitions des documents d'origine")
);
}
/**
* Returns task name
*
* @return string
*/
public function getName()
{
return(_('task::subdef:creation des sous definitions'));
}
/**
* must return the xml (text) version of the form
*
* @param string $oldxml
* @return string
*/
public function graphic2xml($oldxml)
{
$request = http_request::getInstance();
$parm2 = $request->get_parms(
'period'
, 'flush'
, 'maxrecs'
, 'maxmegs'
);
$dom = new DOMDocument();
$dom->preserveWhiteSpace = false;
$dom->formatOutput = true;
if ($dom->loadXML($oldxml))
/**
* Return about text
*
* @return <type>
*/
function help()
{
$xmlchanged = false;
foreach (array("str:period", "str:flush", "str:maxrecs", "str:maxmegs") as $pname)
{
$ptype = substr($pname, 0, 3);
$pname = substr($pname, 4);
$pvalue = $parm2[$pname];
if ($ns = $dom->getElementsByTagName($pname)->item(0))
{
while (($n = $ns->firstChild))
$ns->removeChild($n);
}
else
{
$ns = $dom->documentElement->appendChild($dom->createElement($pname));
}
switch ($ptype)
{
case "str":
$ns->appendChild($dom->createTextNode($pvalue));
break;
case "boo":
$ns->appendChild($dom->createTextNode($pvalue ? '1' : '0'));
break;
}
$xmlchanged = true;
}
return(
_("task::subdef:creation des sous definitions des documents d'origine")
);
}
return($dom->saveXML());
}
/**
* must fill the graphic form (using js) from xml
*
* @param string $xml
* @param string $form
* @return string
*/
public function xml2graphic($xml, $form)
{
if (($sxml = simplexml_load_string($xml)))
/**
* Returns task name
*
* @return string
*/
public function getName()
{
if ((int) ($sxml->period) < 10)
$sxml->period = 10;
elseif ((int) ($sxml->period) > 300)
$sxml->period = 300;
if ((string) ($sxml->flush) == '')
$sxml->flush = 10;
elseif ((int) ($sxml->flush) < 1)
$sxml->flush = 1;
elseif ((int) ($sxml->flush) > 100)
$sxml->flush = 100;
if ((string) ($sxml->maxrecs) == '')
$sxml->maxrecs = 100;
if ((int) ($sxml->maxrecs) < 10)
$sxml->maxrecs = 10;
elseif ((int) ($sxml->maxrecs) > 500)
$sxml->maxrecs = 500;
if ((string) ($sxml->maxmegs) == '')
$sxml->maxmegs = 6;
if ((int) ($sxml->maxmegs) < 3)
$sxml->maxmegs = 3;
elseif ((int) ($sxml->maxmegs) > 32)
$sxml->maxmegs = 32;
?>
<script type="text/javascript">
<?php echo $form ?>.period.value = "<?php echo p4string::MakeString($sxml->period, "js", '"') ?>";
<?php echo $form ?>.flush.value = "<?php echo p4string::MakeString($sxml->flush, "js", '"') ?>";
<?php echo $form ?>.maxrecs.value = "<?php echo p4string::MakeString($sxml->maxrecs, "js", '"') ?>";
<?php echo $form ?>.maxmegs.value = "<?php echo p4string::MakeString($sxml->maxmegs, "js", '"') ?>";
</script>
<?php
return("");
return(_('task::subdef:creation des sous definitions'));
}
else
/**
* must return the xml (text) version of the form
*
* @param string $oldxml
* @return string
*/
public function graphic2xml($oldxml)
{
return("BAD XML");
$request = http_request::getInstance();
$parm2 = $request->get_parms(
'period'
, 'flush'
, 'maxrecs'
, 'maxmegs'
);
$dom = new DOMDocument();
$dom->preserveWhiteSpace = false;
$dom->formatOutput = true;
if ($dom->loadXML($oldxml)) {
$xmlchanged = false;
foreach (array("str:period", "str:flush", "str:maxrecs", "str:maxmegs") as $pname) {
$ptype = substr($pname, 0, 3);
$pname = substr($pname, 4);
$pvalue = $parm2[$pname];
if ($ns = $dom->getElementsByTagName($pname)->item(0)) {
while (($n = $ns->firstChild))
$ns->removeChild($n);
} else {
$ns = $dom->documentElement->appendChild($dom->createElement($pname));
}
switch ($ptype) {
case "str":
$ns->appendChild($dom->createTextNode($pvalue));
break;
case "boo":
$ns->appendChild($dom->createTextNode($pvalue ? '1' : '0'));
break;
}
$xmlchanged = true;
}
}
return($dom->saveXML());
}
}
/**
*
* generates le code js de l'interface 'graphic view'
*
*/
public function printInterfaceJS()
{
?>
<script type="text/javascript">
function chgxmltxt(textinput, fieldname)
{
var limits = { 'period':{min:1, 'max':300} , 'flush':{min:1, 'max':100} , 'maxrecs':{min:10, 'max':1000} , 'maxmegs':{min:2, 'max':100} } ;
if(typeof(limits[fieldname])!='undefined')
{
var v = 0|textinput.value;
if(v < limits[fieldname].min)
v = limits[fieldname].min;
else if(v > limits[fieldname].max)
v = limits[fieldname].max;
textinput.value = v;
}
setDirty();
}
function chgxmlck_die(ck)
{
if(ck.checked)
{
if(document.forms['graphicForm'].maxrecs.value == "")
document.forms['graphicForm'].maxrecs.value = 500;
if(document.forms['graphicForm'].maxmegs.value == "")
document.forms['graphicForm'].maxmegs.value = 4;
document.forms['graphicForm'].maxrecs.disabled = document.forms['graphicForm'].maxmegs.disabled = false;
}
else
{
document.forms['graphicForm'].maxrecs.disabled = document.forms['graphicForm'].maxmegs.disabled = true;
}
setDirty();
}
function chgxmlck(checkinput, fieldname)
{
setDirty();
}
function chgxmlpopup(popupinput, fieldname)
{
setDirty();
}
</script>
<?php
}
public function getGraphicForm()
{
return true;
}
/**
* generates interface 'graphic view'
*
*/
public function printInterfaceHTML()
{
ob_start();
?>
<form name="graphicForm" onsubmit="return(false);" method="post">
<br/>
<?php echo _('task::_common_:periodicite de la tache') ?>&nbsp;:&nbsp;
<input type="text" name="period" style="width:40px;" onchange="chgxmltxt(this, 'period');" value="">
<?php echo _('task::_common_:secondes (unite temporelle)') ?><br/>
<br/>
<?php echo sprintf(_("task::_common_:passer tous les %s records a l'etape suivante"), '<input type="text" name="flush" style="width:40px;" onchange="chgxmltxt(this, \'flush\');" value="">'); ?>
<br/>
<br/>
<?php echo _('task::_common_:relancer la tache tous les') ?>&nbsp;
<input type="text" name="maxrecs" style="width:40px;" onchange="chgxmltxt(this, 'maxrecs');" value="">
<?php echo _('task::_common_:records, ou si la memoire depasse') ?>&nbsp;
<input type="text" name="maxmegs" style="width:40px;" onchange="chgxmltxt(this, 'maxmegs');" value="">
Mo
<br/>
</form>
<?php
$out = ob_get_clean();
return $out;
}
protected function flush_records_sbas()
{
$sql = implode(', ', $this->recs_to_write);
if ($sql != '')
/**
* must fill the graphic form (using js) from xml
*
* @param string $xml
* @param string $form
* @return string
*/
public function xml2graphic($xml, $form)
{
$this->log(sprintf(
'setting %d record(s) to subdef meta writing'
, count($this->recs_to_write)
));
if (($sxml = simplexml_load_string($xml))) {
if ((int) ($sxml->period) < 10)
$sxml->period = 10;
elseif ((int) ($sxml->period) > 300)
$sxml->period = 300;
try
{
$connbas = connection::getPDOConnection($this->sbas_id);
$sql = 'UPDATE record
if ((string) ($sxml->flush) == '')
$sxml->flush = 10;
elseif ((int) ($sxml->flush) < 1)
$sxml->flush = 1;
elseif ((int) ($sxml->flush) > 100)
$sxml->flush = 100;
if ((string) ($sxml->maxrecs) == '')
$sxml->maxrecs = 100;
if ((int) ($sxml->maxrecs) < 10)
$sxml->maxrecs = 10;
elseif ((int) ($sxml->maxrecs) > 500)
$sxml->maxrecs = 500;
if ((string) ($sxml->maxmegs) == '')
$sxml->maxmegs = 6;
if ((int) ($sxml->maxmegs) < 3)
$sxml->maxmegs = 3;
elseif ((int) ($sxml->maxmegs) > 32)
$sxml->maxmegs = 32;
?>
<script type="text/javascript">
<?php echo $form ?>.period.value = "<?php echo p4string::MakeString($sxml->period, "js", '"') ?>";
<?php echo $form ?>.flush.value = "<?php echo p4string::MakeString($sxml->flush, "js", '"') ?>";
<?php echo $form ?>.maxrecs.value = "<?php echo p4string::MakeString($sxml->maxrecs, "js", '"') ?>";
<?php echo $form ?>.maxmegs.value = "<?php echo p4string::MakeString($sxml->maxmegs, "js", '"') ?>";
</script>
<?php
return("");
}
else {
return("BAD XML");
}
}
/**
*
* generates le code js de l'interface 'graphic view'
*
*/
public function printInterfaceJS()
{
?>
<script type="text/javascript">
function chgxmltxt(textinput, fieldname)
{
var limits = { 'period':{min:1, 'max':300} , 'flush':{min:1, 'max':100} , 'maxrecs':{min:10, 'max':1000} , 'maxmegs':{min:2, 'max':100} } ;
if(typeof(limits[fieldname])!='undefined')
{
var v = 0|textinput.value;
if(v < limits[fieldname].min)
v = limits[fieldname].min;
else if(v > limits[fieldname].max)
v = limits[fieldname].max;
textinput.value = v;
}
setDirty();
}
function chgxmlck_die(ck)
{
if(ck.checked)
{
if(document.forms['graphicForm'].maxrecs.value == "")
document.forms['graphicForm'].maxrecs.value = 500;
if(document.forms['graphicForm'].maxmegs.value == "")
document.forms['graphicForm'].maxmegs.value = 4;
document.forms['graphicForm'].maxrecs.disabled = document.forms['graphicForm'].maxmegs.disabled = false;
}
else
{
document.forms['graphicForm'].maxrecs.disabled = document.forms['graphicForm'].maxmegs.disabled = true;
}
setDirty();
}
function chgxmlck(checkinput, fieldname)
{
setDirty();
}
function chgxmlpopup(popupinput, fieldname)
{
setDirty();
}
</script>
<?php
}
public function getGraphicForm()
{
return true;
}
/**
* generates interface 'graphic view'
*
*/
public function printInterfaceHTML()
{
ob_start();
?>
<form name="graphicForm" onsubmit="return(false);" method="post">
<br/>
<?php echo _('task::_common_:periodicite de la tache') ?>&nbsp;:&nbsp;
<input type="text" name="period" style="width:40px;" onchange="chgxmltxt(this, 'period');" value="">
<?php echo _('task::_common_:secondes (unite temporelle)') ?><br/>
<br/>
<?php echo sprintf(_("task::_common_:passer tous les %s records a l'etape suivante"), '<input type="text" name="flush" style="width:40px;" onchange="chgxmltxt(this, \'flush\');" value="">'); ?>
<br/>
<br/>
<?php echo _('task::_common_:relancer la tache tous les') ?>&nbsp;
<input type="text" name="maxrecs" style="width:40px;" onchange="chgxmltxt(this, 'maxrecs');" value="">
<?php echo _('task::_common_:records, ou si la memoire depasse') ?>&nbsp;
<input type="text" name="maxmegs" style="width:40px;" onchange="chgxmltxt(this, 'maxmegs');" value="">
Mo
<br/>
</form>
<?php
$out = ob_get_clean();
return $out;
}
protected function flush_records_sbas()
{
$sql = implode(', ', $this->recs_to_write);
if ($sql != '') {
$this->log(sprintf(
'setting %d record(s) to subdef meta writing'
, count($this->recs_to_write)
));
try {
$connbas = connection::getPDOConnection($this->sbas_id);
$sql = 'UPDATE record
SET status=(status & ~0x03),
jeton=(jeton | ' . JETON_WRITE_META_SUBDEF . ')
WHERE record_id IN (' . $sql . ')';
$stmt = $connbas->prepare($sql);
$stmt->execute();
$stmt->closeCursor();
}
catch (Exception $e)
{
$this->log($e->getMessage());
}
}
$this->recs_to_write = array();
$stmt = $connbas->prepare($sql);
$stmt->execute();
$stmt->closeCursor();
} catch (Exception $e) {
$this->log($e->getMessage());
}
}
$this->recs_to_write = array();
return $this;
}
return $this;
}
public function retrieve_sbas_content(databox $databox)
{
$connbas = $databox->get_connection();
public function retrieve_sbas_content(databox $databox)
{
$connbas = $databox->get_connection();
$sql = 'SELECT coll_id, record_id
$sql = 'SELECT coll_id, record_id
FROM record
WHERE jeton & ' . JETON_MAKE_SUBDEF . ' > 0
AND parent_record_id = 0
ORDER BY record_id DESC LIMIT 0, 20';
$stmt = $connbas->prepare($sql);
$stmt->execute();
$rs = $stmt->fetchAll(PDO::FETCH_ASSOC);
$stmt->closeCursor();
$stmt = $connbas->prepare($sql);
$stmt->execute();
$rs = $stmt->fetchAll(PDO::FETCH_ASSOC);
$stmt->closeCursor();
return $rs;
}
return $rs;
}
public function process_one_content(databox $databox, Array $row)
{
$record_id = $row['record_id'];
$this->log(sprintf(
public function process_one_content(databox $databox, Array $row)
{
$record_id = $row['record_id'];
$this->log(sprintf(
"Generate subdefs for : sbas_id %s / record %s "
, $this->sbas_id, $record_id));
$record = new record_adapter($this->sbas_id, $record_id);
$record = new record_adapter($this->sbas_id, $record_id);
$record->generate_subdefs($databox, null);
$record->generate_subdefs($databox, null);
$this->recs_to_write[] = $record->get_record_id();
$this->recs_to_write[] = $record->get_record_id();
if (count($this->recs_to_write) >= $this->record_buffer_size)
{
$this->flush_records_sbas();
}
unset($record);
if (count($this->recs_to_write) >= $this->record_buffer_size) {
$this->flush_records_sbas();
}
unset($record);
return $this;
}
return $this;
}
protected function post_process_one_content(databox $databox, Array $row)
{
$connbas = $databox->get_connection();
$sql = 'UPDATE record
protected function post_process_one_content(databox $databox, Array $row)
{
$connbas = $databox->get_connection();
$sql = 'UPDATE record
SET jeton=(jeton & ~' . JETON_MAKE_SUBDEF . '), moddate=NOW()
WHERE record_id=:record_id';
$stmt = $connbas->prepare($sql);
$stmt->execute(array(':record_id' => $row['record_id']));
$stmt->closeCursor();
$stmt = $connbas->prepare($sql);
$stmt->execute(array(':record_id' => $row['record_id']));
$stmt->closeCursor();
return $this;
}
}
return $this;
}
}

View File

@@ -18,35 +18,34 @@
class task_period_test extends task_appboxAbstract
{
public function getName()
{
return "Test";
}
public function getName()
{
return "Test";
}
public function help()
{
return "just saying what i'm doing";
}
public function help()
{
return "just saying what i'm doing";
}
protected function retrieve_content(appbox $appbox)
{
$this->log('test class, retrive content');
protected function retrieve_content(appbox $appbox)
{
$this->log('test class, retrive content');
return array('hello', 'world');
}
return array('hello', 'world');
}
protected function process_one_content(appbox $appbox, Array $row)
{
$this->log(sprintf("test class, process content : `%s`", implode(' ', $row)));
protected function process_one_content(appbox $appbox, Array $row)
{
$this->log(sprintf("test class, process content : `%s`", implode(' ', $row)));
return $this;
}
return $this;
}
protected function post_process_one_content(appbox $appbox, Array $row)
{
$this->log(sprintf("test class, post process content, they were %s", count($row)));
return $this;
}
protected function post_process_one_content(appbox $appbox, Array $row)
{
$this->log(sprintf("test class, post process content, they were %s", count($row)));
return $this;
}
}

View File

@@ -18,175 +18,159 @@
class task_period_upgradetov31 extends task_abstract
{
// ==========================================================================
// ===== les interfaces de settings (task2.php) pour ce type de tache
// ==========================================================================
// ====================================================================
// getName() : must return the name of this kind of task (utf8), MANDATORY
// ====================================================================
public function getName()
{
return(_("upgrade to v3.1"));
}
public static function interfaceAvailable()
{
return false;
}
public function help()
{
return(utf8_encode("Upgrade some database values"));
}
protected function run2()
{
printf("taskid %s starting." . PHP_EOL, $this->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')))
// ==========================================================================
// ===== les interfaces de settings (task2.php) pour ce type de tache
// ==========================================================================
// ====================================================================
// getName() : must return the name of this kind of task (utf8), MANDATORY
// ====================================================================
public function getName()
{
printf("Exiftool is not executable, script can not process\n");
return 'stopped';
return(_("upgrade to v3.1"));
}
$todo = $this->how_many_left();
$done = 0;
$appbox = appbox::get_instance(\bootstrap::getCore());
$ret = 'stopped';
$this->setProgress($done, $todo);
while ($running)
public static function interfaceAvailable()
{
return false;
}
foreach ($appbox->get_databoxes() as $databox)
{
$connbas = $databox->get_connection();
public function help()
{
return(utf8_encode("Upgrade some database values"));
}
$sql = 'SELECT r.type, r.record_id, s.path, s.file, r.xml
protected function run2()
{
printf("taskid %s starting." . PHP_EOL, $this->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();
$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();
}
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';
$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();
$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";
echo "mise a jour du record " . $row['record_id'] . " avec uuid " . $uuid . "\n";
$done++;
$this->setProgress($done, $todo);
$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());
$todo = $this->how_many_left() + $done;
sleep(1);
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();
printf("good bye world I was task upgrade to version 3.1" . PHP_EOL);
$this->setProgress(0, 0);
$ret = 'todelete';
}
flush();
$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();
return $ret;
}
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)
private function how_many_left()
{
try
{
$connbas = $databox->get_connection();
$todo = 0;
$appbox = appbox::get_instance(\bootstrap::getCore());
$sql = 'SELECT count(r.record_id) as total FROM record r, subdef s
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();
$stmt = $connbas->prepare($sql);
$stmt->execute();
$row = $stmt->fetch(PDO::FETCH_ASSOC);
$stmt->closeCursor();
if ($row)
{
$todo += (int) $row['total'];
if ($row) {
$todo += (int) $row['total'];
}
} catch (Excepiton $e) {
}
}
}
catch (Excepiton $e)
{
}
return $todo;
}
return $todo;
}
}
?>

View File

@@ -17,237 +17,208 @@
*/
class task_period_upgradetov32 extends task_abstract
{
protected $sbas_id;
protected $sbas_id;
// ==========================================================================
// ===== les interfaces de settings (task2.php) pour ce type de tache
// ==========================================================================
// ====================================================================
// getName() : must return the name of this kind of task (utf8), MANDATORY
// ====================================================================
public function getName()
{
return(_("upgrade to v3.2"));
}
// ==========================================================================
// ===== les interfaces de settings (task2.php) pour ce type de tache
// ==========================================================================
// ====================================================================
// getName() : must return the name of this kind of task (utf8), MANDATORY
// ====================================================================
public function getName()
{
return(_("upgrade to v3.2"));
}
public static function interfaceAvailable()
{
return false;
}
public static function interfaceAvailable()
{
return false;
}
// ==========================================================================
// help() : text displayed if --help
// ==========================================================================
public function help()
{
return(utf8_encode("Upgrade some database values"));
}
// ==========================================================================
// help() : text displayed if --help
// ==========================================================================
public function help()
{
return(utf8_encode("Upgrade some database values"));
}
// ==========================================================================
// run() : the real code executed by each task, MANDATORY
// ==========================================================================
// ==========================================================================
// run() : the real code executed by each task, MANDATORY
// ==========================================================================
protected function load_settings(SimpleXMLElement $sx_task_settings)
{
$this->sbas_id = (int) $sx_task_settings->sbas_id;
parent::load_settings($sx_task_settings);
protected function load_settings(SimpleXMLElement $sx_task_settings)
{
$this->sbas_id = (int) $sx_task_settings->sbas_id;
parent::load_settings($sx_task_settings);
return $this;
}
return $this;
}
protected function run2()
{
printf("taskid %s starting." . PHP_EOL, $this->get_task_id());
protected function run2()
{
printf("taskid %s starting." . PHP_EOL, $this->get_task_id());
$registry = registry::get_instance();
$registry = registry::get_instance();
// $registry->set('GV_cache_server_type', 'nocache', \registry::TYPE_STRING);
$registry->set('GV_sphinx', false, \registry::TYPE_BOOLEAN);
$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;
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;
}
try
{
foreach ($databox->get_meta_structure()->get_elements() as $struct_el)
{
if ($struct_el instanceof databox_fieldUnknown)
{
throw new Exception('Bad field');
return;
}
}
}
catch (Exception $e)
{
printf("Please verify all your databox meta fields before migrating, It seems somes are wrong\n");
$this->return_value = self::RETURNSTATUS_STOPPED;
return 'stopped';
}
try {
$databox = databox::get_instance($this->sbas_id);
$connbas = connection::getPDOConnection($this->sbas_id);
} catch (Exception $e) {
$this->return_value = self::RETURNSTATUS_STOPPED;
$this->running = true;
return;
}
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)
{
try {
foreach ($databox->get_meta_structure()->get_elements() as $struct_el) {
if ($struct_el instanceof databox_fieldUnknown) {
throw new Exception('Bad field');
}
}
} catch (Exception $e) {
printf("Please verify all your databox meta fields before migrating, It seems somes are wrong\n");
$this->return_value = self::RETURNSTATUS_STOPPED;
}
return 'stopped';
}
$n_done = 0;
$this->running = true;
while ($this->running)
{
try
{
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) {
$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'];
$n_done = 0;
$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();
while ($this->running) {
try {
$done = 0;
if ($row)
$done = $row['total'];
$sql = 'SELECT COUNT(record_id) as total FROM record';
$stmt = $connbas->prepare($sql);
$stmt->execute();
$row = $stmt->fetch(PDO::FETCH_ASSOC);
$stmt->closeCursor();
$this->setProgress($done, $total);
$total = 0;
if ($row)
$total = $row['total'];
$this->running = false;
$sql = 'select record_id, coll_id, xml, BIN(status) as status
$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();
$stmt = $connbas->prepare($sql);
$stmt->execute();
$rs = $stmt->fetchAll(PDO::FETCH_ASSOC);
$stmt->closeCursor();
if (count($rs) > 0)
{
$this->running = true;
}
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)
{
$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();
}
}
$connbas->commit();
$sql = 'select record_id, coll_id, xml, BIN(status) as status
$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();
$stmt = $connbas->prepare($sql);
$stmt->execute();
$rs = $stmt->fetchAll(PDO::FETCH_ASSOC);
$stmt->closeCursor();
if (count($rs) > 0)
{
$this->running = true;
}
if (count($rs) > 0) {
$this->running = true;
}
$sql = 'REPLACE INTO technical_datas (id, record_id, name, value)
$sql = 'REPLACE INTO technical_datas (id, record_id, name, value)
VALUES (null, :record_id, :name, :value)';
$stmt = $connbas->prepare($sql);
$connbas->beginTransaction();
$stmt = $connbas->prepare($sql);
$connbas->beginTransaction();
foreach ($rs as $row)
{
try
{
$record = new record_adapter($this->sbas_id, $row['record_id']);
$system_file = $record->get_hd_file();
foreach ($rs as $row) {
try {
$record = new record_adapter($this->sbas_id, $row['record_id']);
$system_file = $record->get_hd_file();
if (!$system_file instanceof system_file)
continue;
if ( ! $system_file instanceof system_file)
continue;
$tc_datas = $system_file->get_technical_datas();
$tc_datas = $system_file->get_technical_datas();
foreach ($tc_datas as $name => $value)
{
if (is_null($value))
continue;
foreach ($tc_datas as $name => $value) {
if (is_null($value))
continue;
$stmt->execute(array(
':record_id' => $record->get_record_id()
, ':name' => $name
, ':value' => $value
));
}
}
catch (Exception $e)
{
$stmt->execute(array(
':record_id' => $record->get_record_id()
, ':name' => $name
, ':value' => $value
));
}
} catch (Exception $e) {
}
}
}
}
$connbas->commit();
$stmt->closeCursor();
$connbas->commit();
$stmt->closeCursor();
@@ -258,166 +229,140 @@ class task_period_upgradetov32 extends task_abstract
$sql = 'select record_id, coll_id, xml, BIN(status) as status
$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'])) {
$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();
$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';
$sql = "DELETE from technical_datas WHERE name='DONE'";
$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']))
{
$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->execute();
$stmt->closeCursor();
unset($stmt);
$connbas->commit();
$n_done += 500;
$conn = connection::getPDOConnection();
$memory = memory_get_usage() >> 20;
printf("taskid %s ending." . PHP_EOL, $this->get_task_id());
sleep(1);
printf("good bye world I was task upgrade to version 3.2" . PHP_EOL);
if ($n_done >= 5000)
{
$this->return_value = task_abstract::RETURNSTATUS_TORESTART;
$sql = 'UPDATE task2 SET status="tostop" WHERE task_id = :task_id';
return;
}
if ($memory > 100)
{
$this->return_value = task_abstract::RETURNSTATUS_TORESTART;
$stmt = $conn->prepare($sql);
$stmt->execute(array(':task_id' => $this->get_task_id()));
$stmt->closeCursor();
return;
}
}
catch (Exception $e)
{
$this->setProgress(0, 0);
}
usleep(500000);
$this->return_value = self::RETURNSTATUS_TODELETE;
flush();
return;
}
$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->get_task_id());
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->get_task_id()));
$stmt->closeCursor();
$this->setProgress(0, 0);
$this->return_value = self::RETURNSTATUS_TODELETE;
flush();
return;
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -16,380 +16,355 @@
*/
class task_period_writemeta extends task_databoxAbstract
{
protected $clear_doc;
protected $metasubdefs = array();
protected $clear_doc;
protected $metasubdefs = array();
function help()
{
return(_("task::writemeta:(re)ecriture des metadatas dans les documents (et subdefs concernees)"));
}
protected function load_settings(SimpleXMLElement $sx_task_settings)
{
$this->clear_doc = p4field::isyes($sx_task_settings->cleardoc);
parent::load_settings($sx_task_settings);
return $this;
}
public function getName()
{
return(_('task::writemeta:ecriture des metadatas'));
}
public function graphic2xml($oldxml)
{
$request = http_request::getInstance();
$parm2 = $request->get_parms(
"period"
, 'cleardoc'
, 'maxrecs'
, 'maxmegs'
);
$dom = new DOMDocument();
$dom->preserveWhiteSpace = false;
$dom->formatOutput = true;
if ($dom->loadXML($oldxml))
function help()
{
$xmlchanged = false;
foreach (array("str:period", 'str:maxrecs', 'str:maxmegs', 'boo:cleardoc') as $pname)
{
$ptype = substr($pname, 0, 3);
$pname = substr($pname, 4);
$pvalue = $parm2[$pname];
if ($ns = $dom->getElementsByTagName($pname)->item(0))
{
// le champ existait dans le xml, on supprime son ancienne valeur (tout le contenu)
while (($n = $ns->firstChild))
$ns->removeChild($n);
}
else
{
// le champ n'existait pas dans le xml, on le cree
$dom->documentElement->appendChild($dom->createTextNode("\t"));
$ns = $dom->documentElement->appendChild($dom->createElement($pname));
$dom->documentElement->appendChild($dom->createTextNode("\n"));
}
// on fixe sa valeur
switch ($ptype)
{
case "str":
$ns->appendChild($dom->createTextNode($pvalue));
break;
case "boo":
$ns->appendChild($dom->createTextNode($pvalue ? '1' : '0'));
break;
}
$xmlchanged = true;
}
return(_("task::writemeta:(re)ecriture des metadatas dans les documents (et subdefs concernees)"));
}
return($dom->saveXML());
}
public function xml2graphic($xml, $form)
{
if (($sxml = simplexml_load_string($xml))) // in fact XML IS always valid here...
protected function load_settings(SimpleXMLElement $sx_task_settings)
{
// ... but we could check for safe values (ex. 0 < period < 3600)
if ((int) ($sxml->period) < 10)
$sxml->period = 10;
elseif ((int) ($sxml->period) > 300)
$sxml->period = 300;
$this->clear_doc = p4field::isyes($sx_task_settings->cleardoc);
parent::load_settings($sx_task_settings);
if ((string) ($sxml->maxrecs) == '')
$sxml->maxrecs = 100;
if ((int) ($sxml->maxrecs) < 10)
$sxml->maxrecs = 10;
elseif ((int) ($sxml->maxrecs) > 500)
$sxml->maxrecs = 500;
if ((string) ($sxml->maxmegs) == '')
$sxml->maxmegs = 6;
if ((int) ($sxml->maxmegs) < 3)
$sxml->maxmegs = 3;
elseif ((int) ($sxml->maxmegs) > 32)
$sxml->maxmegs = 32;
?>
<script type="text/javascript">
<?php echo $form ?>.period.value = "<?php echo p4string::MakeString($sxml->period, "js", '"') ?>";
<?php echo $form ?>.cleardoc.checked = <?php echo p4field::isyes($sxml->cleardoc) ? "true" : 'false' ?>;
<?php echo $form ?>.maxrecs.value = "<?php echo p4string::MakeString($sxml->maxrecs, "js", '"') ?>";
<?php echo $form ?>.maxmegs.value = "<?php echo p4string::MakeString($sxml->maxmegs, "js", '"') ?>";
</script>
<?php
return("");
return $this;
}
else // ... so we NEVER come here
public function getName()
{
// bad xml
return("BAD XML");
return(_('task::writemeta:ecriture des metadatas'));
}
}
public function printInterfaceJS()
{
?>
<script type="text/javascript">
function chgxmltxt(textinput, fieldname)
{
var limits = { 'period':{min:1, 'max':300} , 'maxrecs':{min:10, 'max':1000} , 'maxmegs':{min:2, 'max':100} } ;
if(typeof(limits[fieldname])!='undefined')
{
var v = 0|textinput.value;
if(v < limits[fieldname].min)
v = limits[fieldname].min;
else if(v > limits[fieldname].max)
v = limits[fieldname].max;
textinput.value = v;
public function graphic2xml($oldxml)
{
$request = http_request::getInstance();
$parm2 = $request->get_parms(
"period"
, 'cleardoc'
, 'maxrecs'
, 'maxmegs'
);
$dom = new DOMDocument();
$dom->preserveWhiteSpace = false;
$dom->formatOutput = true;
if ($dom->loadXML($oldxml)) {
$xmlchanged = false;
foreach (array("str:period", 'str:maxrecs', 'str:maxmegs', 'boo:cleardoc') as $pname) {
$ptype = substr($pname, 0, 3);
$pname = substr($pname, 4);
$pvalue = $parm2[$pname];
if ($ns = $dom->getElementsByTagName($pname)->item(0)) {
// le champ existait dans le xml, on supprime son ancienne valeur (tout le contenu)
while (($n = $ns->firstChild))
$ns->removeChild($n);
} else {
// le champ n'existait pas dans le xml, on le cree
$dom->documentElement->appendChild($dom->createTextNode("\t"));
$ns = $dom->documentElement->appendChild($dom->createElement($pname));
$dom->documentElement->appendChild($dom->createTextNode("\n"));
}
// on fixe sa valeur
switch ($ptype) {
case "str":
$ns->appendChild($dom->createTextNode($pvalue));
break;
case "boo":
$ns->appendChild($dom->createTextNode($pvalue ? '1' : '0'));
break;
}
$xmlchanged = true;
}
}
setDirty();
}
function chgxmlck_die(ck)
{
if(ck.checked)
{
if(document.forms['graphicForm'].maxrecs.value == "")
document.forms['graphicForm'].maxrecs.value = 500;
if(document.forms['graphicForm'].maxmegs.value == "")
document.forms['graphicForm'].maxmegs.value = 4;
document.forms['graphicForm'].maxrecs.disabled = document.forms['graphicForm'].maxmegs.disabled = false;
}
else
{
document.forms['graphicForm'].maxrecs.disabled = document.forms['graphicForm'].maxmegs.disabled = true;
}
setDirty();
}
function chgxmlck(checkinput, fieldname)
{
setDirty();
}
function chgxmlpopup(popupinput, fieldname)
{
setDirty();
}
</script>
<?php
}
function getGraphicForm()
{
return true;
}
public function printInterfaceHTML()
{
$appbox = appbox::get_instance(\bootstrap::getCore());
$session = $appbox->get_session();
$sbas_ids = User_Adapter::getInstance($session->get_usr_id(), $appbox)
->ACL()->get_granted_sbas(array('bas_manage'));
ob_start();
if (count($sbas_ids) > 0)
{
?>
<form name="graphicForm" onsubmit="return(false);" method="post">
<br/>
<?php echo _('task::_common_:periodicite de la tache') ?>&nbsp;:&nbsp;
<input type="text" name="period" style="width:40px;" onchange="chgxmltxt(this, 'period');" value="">
<?php echo _('task::_common_:secondes (unite temporelle)') ?><br/>
<br/>
<input type="checkbox" name="cleardoc" onchange="chgxmlck(this)">
<?php echo _('task::writemeta:effacer les metadatas non presentes dans la structure') ?>
<br/>
<br/>
<?php echo _('task::_common_:relancer la tache tous les') ?>&nbsp;
<input type="text" name="maxrecs" style="width:40px;" onchange="chgxmltxt(this, 'maxrecs');" value="">
<?php echo _('task::_common_:records, ou si la memoire depasse') ?>&nbsp;
<input type="text" name="maxmegs" style="width:40px;" onchange="chgxmltxt(this, 'maxmegs');" value="">
Mo
<br/>
</form>
<?php
}
$out = ob_get_clean();
return $out;
}
protected function retrieve_sbas_content(databox $databox)
{
$connbas = $databox->get_connection();
$subdefgroups = $databox->get_subdef_structure();
$metasubdefs = array();
foreach ($subdefgroups as $type => $subdefs)
{
foreach ($subdefs as $sub)
{
$name = $sub->get_name();
if ($sub->meta_writeable())
$metasubdefs[$name . '_' . $type] = true;
}
return($dom->saveXML());
}
$this->metasubdefs = $metasubdefs;
public function xml2graphic($xml, $form)
{
if (($sxml = simplexml_load_string($xml))) { // in fact XML IS always valid here...
// ... but we could check for safe values (ex. 0 < period < 3600)
if ((int) ($sxml->period) < 10)
$sxml->period = 10;
elseif ((int) ($sxml->period) > 300)
$sxml->period = 300;
$sql = 'SELECT record_id, coll_id, jeton
if ((string) ($sxml->maxrecs) == '')
$sxml->maxrecs = 100;
if ((int) ($sxml->maxrecs) < 10)
$sxml->maxrecs = 10;
elseif ((int) ($sxml->maxrecs) > 500)
$sxml->maxrecs = 500;
if ((string) ($sxml->maxmegs) == '')
$sxml->maxmegs = 6;
if ((int) ($sxml->maxmegs) < 3)
$sxml->maxmegs = 3;
elseif ((int) ($sxml->maxmegs) > 32)
$sxml->maxmegs = 32;
?>
<script type="text/javascript">
<?php echo $form ?>.period.value = "<?php echo p4string::MakeString($sxml->period, "js", '"') ?>";
<?php echo $form ?>.cleardoc.checked = <?php echo p4field::isyes($sxml->cleardoc) ? "true" : 'false' ?>;
<?php echo $form ?>.maxrecs.value = "<?php echo p4string::MakeString($sxml->maxrecs, "js", '"') ?>";
<?php echo $form ?>.maxmegs.value = "<?php echo p4string::MakeString($sxml->maxmegs, "js", '"') ?>";
</script>
<?php
return("");
}
else { // ... so we NEVER come here
// bad xml
return("BAD XML");
}
}
public function printInterfaceJS()
{
?>
<script type="text/javascript">
function chgxmltxt(textinput, fieldname)
{
var limits = { 'period':{min:1, 'max':300} , 'maxrecs':{min:10, 'max':1000} , 'maxmegs':{min:2, 'max':100} } ;
if(typeof(limits[fieldname])!='undefined')
{
var v = 0|textinput.value;
if(v < limits[fieldname].min)
v = limits[fieldname].min;
else if(v > limits[fieldname].max)
v = limits[fieldname].max;
textinput.value = v;
}
setDirty();
}
function chgxmlck_die(ck)
{
if(ck.checked)
{
if(document.forms['graphicForm'].maxrecs.value == "")
document.forms['graphicForm'].maxrecs.value = 500;
if(document.forms['graphicForm'].maxmegs.value == "")
document.forms['graphicForm'].maxmegs.value = 4;
document.forms['graphicForm'].maxrecs.disabled = document.forms['graphicForm'].maxmegs.disabled = false;
}
else
{
document.forms['graphicForm'].maxrecs.disabled = document.forms['graphicForm'].maxmegs.disabled = true;
}
setDirty();
}
function chgxmlck(checkinput, fieldname)
{
setDirty();
}
function chgxmlpopup(popupinput, fieldname)
{
setDirty();
}
</script>
<?php
}
function getGraphicForm()
{
return true;
}
public function printInterfaceHTML()
{
$appbox = appbox::get_instance(\bootstrap::getCore());
$session = $appbox->get_session();
$sbas_ids = User_Adapter::getInstance($session->get_usr_id(), $appbox)
->ACL()->get_granted_sbas(array('bas_manage'));
ob_start();
if (count($sbas_ids) > 0) {
?>
<form name="graphicForm" onsubmit="return(false);" method="post">
<br/>
<?php echo _('task::_common_:periodicite de la tache') ?>&nbsp;:&nbsp;
<input type="text" name="period" style="width:40px;" onchange="chgxmltxt(this, 'period');" value="">
<?php echo _('task::_common_:secondes (unite temporelle)') ?><br/>
<br/>
<input type="checkbox" name="cleardoc" onchange="chgxmlck(this)">
<?php echo _('task::writemeta:effacer les metadatas non presentes dans la structure') ?>
<br/>
<br/>
<?php echo _('task::_common_:relancer la tache tous les') ?>&nbsp;
<input type="text" name="maxrecs" style="width:40px;" onchange="chgxmltxt(this, 'maxrecs');" value="">
<?php echo _('task::_common_:records, ou si la memoire depasse') ?>&nbsp;
<input type="text" name="maxmegs" style="width:40px;" onchange="chgxmltxt(this, 'maxmegs');" value="">
Mo
<br/>
</form>
<?php
}
$out = ob_get_clean();
return $out;
}
protected function retrieve_sbas_content(databox $databox)
{
$connbas = $databox->get_connection();
$subdefgroups = $databox->get_subdef_structure();
$metasubdefs = array();
foreach ($subdefgroups as $type => $subdefs) {
foreach ($subdefs as $sub) {
$name = $sub->get_name();
if ($sub->meta_writeable())
$metasubdefs[$name . '_' . $type] = true;
}
}
$this->metasubdefs = $metasubdefs;
$sql = 'SELECT record_id, coll_id, jeton
FROM record WHERE (jeton & ' . JETON_WRITE_META . ' > 0)';
$stmt = $connbas->prepare($sql);
$stmt->execute();
$rs = $stmt->fetchAll(PDO::FETCH_ASSOC);
$stmt->closeCursor();
$stmt = $connbas->prepare($sql);
$stmt->execute();
$rs = $stmt->fetchAll(PDO::FETCH_ASSOC);
$stmt->closeCursor();
return $rs;
}
protected function format_value($type, $value)
{
if ($type == 'date')
{
$value = str_replace(array("-", ":", "/", "."), array(" ", " ", " ", " "), $value);
$ip_date_yyyy = 0;
$ip_date_mm = 0;
$ip_date_dd = 0;
$ip_date_hh = 0;
$ip_date_nn = 0;
$ip_date_ss = 0;
switch (sscanf($value, "%d %d %d %d %d %d", $ip_date_yyyy, $ip_date_mm, $ip_date_dd, $ip_date_hh, $ip_date_nn, $ip_date_ss))
{
case 1:
$value = sprintf("%04d:00:00", $ip_date_yyyy);
break;
case 2:
$value = sprintf("%04d:%02d:00", $ip_date_yyyy, $ip_date_mm);
break;
case 3:
case 4:
case 5:
case 6:
$value = sprintf("%04d:%02d:%02d", $ip_date_yyyy, $ip_date_mm, $ip_date_dd);
break;
default:
$value = '0000:00:00';
}
}
return $value;
}
protected function process_one_content(databox $databox, Array $row)
{
$coll_id = $row['coll_id'];
$record_id = $row['record_id'];
$jeton = $row['jeton'];
$record = new record_adapter($this->sbas_id, $record_id);
$type = $record->get_type();
$subdefs = $record->get_subdefs();
$tsub = array();
foreach ($subdefs as $name => $subdef)
{
$write_document = (($jeton & JETON_WRITE_META_DOC) && $name == 'document');
$write_subdef = (($jeton & JETON_WRITE_META_SUBDEF) && isset($this->metasubdefs[$name . '_' . $type]));
if ($write_document || $write_subdef)
{
$tsub[$name] = $subdef->get_pathfile();
}
}
$registry = $databox->get_registry();
$fields = $record->get_caption()->get_fields();
$subCMD = '';
if ($record->get_uuid())
{
$subCMD .= ' -XMP-exif:ImageUniqueID=';
$subCMD .= escapeshellarg($record->get_uuid());
$subCMD .= ' -IPTC:UniqueDocumentID=';
$subCMD .= escapeshellarg($record->get_uuid());
}
foreach ($fields as $field)
{
$meta = $field->get_databox_field();
/* @var $meta \databox_field */
if (trim($meta->get_metadata_source()) === '')
{
continue;
}
$multi = $meta->is_multi();
$type = $meta->get_type();
$datas = $field->get_values();
if ($multi)
{
foreach ($datas as $value)
{
$value = $this->format_value($type, $value->getValue());
$subCMD .= ' -'.$meta->get_metadata_namespace().':'.$meta->get_metadata_tagname().'=';
$subCMD .= escapeshellarg($value).' ';
return $rs;
}
}
else
{
$value = array_pop($datas);
$datas = $this->format_value($type, $value->getValue());
$subCMD .= ' -'.$meta->get_metadata_namespace().':'.$meta->get_metadata_tagname().'=';
$subCMD .= escapeshellarg($datas).' ';
}
}
protected function format_value($type, $value)
{
if ($type == 'date') {
$value = str_replace(array("-", ":", "/", "."), array(" ", " ", " ", " "), $value);
$ip_date_yyyy = 0;
$ip_date_mm = 0;
$ip_date_dd = 0;
$ip_date_hh = 0;
$ip_date_nn = 0;
$ip_date_ss = 0;
switch (sscanf($value, "%d %d %d %d %d %d", $ip_date_yyyy, $ip_date_mm, $ip_date_dd, $ip_date_hh, $ip_date_nn, $ip_date_ss)) {
case 1:
$value = sprintf("%04d:00:00", $ip_date_yyyy);
break;
case 2:
$value = sprintf("%04d:%02d:00", $ip_date_yyyy, $ip_date_mm);
break;
case 3:
case 4:
case 5:
case 6:
$value = sprintf("%04d:%02d:%02d", $ip_date_yyyy, $ip_date_mm, $ip_date_dd);
break;
default:
$value = '0000:00:00';
}
}
foreach ($tsub as $name => $file)
{
$cmd = '';
if ($this->system == 'WINDOWS')
$cmd = 'start /B /LOW ';
$cmd .= ( $registry->get('GV_exiftool') . ' -m -overwrite_original ');
if ($name != 'document' || $this->clear_doc)
$cmd .= ' -all:all= ';
return $value;
}
$cmd .= ' -codedcharacterset=utf8 ';
protected function process_one_content(databox $databox, Array $row)
{
$coll_id = $row['coll_id'];
$record_id = $row['record_id'];
$jeton = $row['jeton'];
$cmd .= $subCMD.' '.escapeshellarg($file);
$record = new record_adapter($this->sbas_id, $record_id);
$this->log(sprintf(('writing meta for sbas_id=%1$d - record_id=%2$d (%3$s)'), $this->sbas_id, $record_id, $name));
$type = $record->get_type();
$subdefs = $record->get_subdefs();
$s = trim(shell_exec($cmd));
$tsub = array();
$this->log("\t" . $s);
}
foreach ($subdefs as $name => $subdef) {
$write_document = (($jeton & JETON_WRITE_META_DOC) && $name == 'document');
$write_subdef = (($jeton & JETON_WRITE_META_SUBDEF) && isset($this->metasubdefs[$name . '_' . $type]));
return $this;
}
if ($write_document || $write_subdef) {
$tsub[$name] = $subdef->get_pathfile();
}
}
protected function flush_records_sbas()
{
return $this;
}
$registry = $databox->get_registry();
protected function post_process_one_content(databox $databox, Array $row)
{
$connbas = $databox->get_connection();
$fields = $record->get_caption()->get_fields();
$sql = 'UPDATE record SET jeton=jeton & ~' . JETON_WRITE_META . '
$subCMD = '';
if ($record->get_uuid()) {
$subCMD .= ' -XMP-exif:ImageUniqueID=';
$subCMD .= escapeshellarg($record->get_uuid());
$subCMD .= ' -IPTC:UniqueDocumentID=';
$subCMD .= escapeshellarg($record->get_uuid());
}
foreach ($fields as $field) {
$meta = $field->get_databox_field();
/* @var $meta \databox_field */
if (trim($meta->get_metadata_source()) === '') {
continue;
}
$multi = $meta->is_multi();
$type = $meta->get_type();
$datas = $field->get_values();
if ($multi) {
foreach ($datas as $value) {
$value = $this->format_value($type, $value->getValue());
$subCMD .= ' -' . $meta->get_metadata_namespace() . ':' . $meta->get_metadata_tagname() . '=';
$subCMD .= escapeshellarg($value) . ' ';
}
} else {
$value = array_pop($datas);
$datas = $this->format_value($type, $value->getValue());
$subCMD .= ' -' . $meta->get_metadata_namespace() . ':' . $meta->get_metadata_tagname() . '=';
$subCMD .= escapeshellarg($datas) . ' ';
}
}
foreach ($tsub as $name => $file) {
$cmd = '';
if ($this->system == 'WINDOWS')
$cmd = 'start /B /LOW ';
$cmd .= ( $registry->get('GV_exiftool') . ' -m -overwrite_original ');
if ($name != 'document' || $this->clear_doc)
$cmd .= ' -all:all= ';
$cmd .= ' -codedcharacterset=utf8 ';
$cmd .= $subCMD . ' ' . escapeshellarg($file);
$this->log(sprintf(('writing meta for sbas_id=%1$d - record_id=%2$d (%3$s)'), $this->sbas_id, $record_id, $name));
$s = trim(shell_exec($cmd));
$this->log("\t" . $s);
}
return $this;
}
protected function flush_records_sbas()
{
return $this;
}
protected function post_process_one_content(databox $databox, Array $row)
{
$connbas = $databox->get_connection();
$sql = 'UPDATE record SET jeton=jeton & ~' . JETON_WRITE_META . '
WHERE record_id = :record_id';
$stmt = $connbas->prepare($sql);
$stmt->execute(array(':record_id' => $row['record_id']));
$stmt->closeCursor();
$stmt = $connbas->prepare($sql);
$stmt->execute(array(':record_id' => $row['record_id']));
$stmt->closeCursor();
return $this;
}
return $this;
}
}
}