Add curly braces

This commit is contained in:
Romain Neutron
2012-04-26 01:55:12 +02:00
parent ade22295ad
commit 33b10d6746
86 changed files with 2969 additions and 2698 deletions

View File

@@ -34,8 +34,10 @@ class task_manager
public function old_get_tasks($refresh = false)
{
if ($this->tasks && ! $refresh)
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();
@@ -62,8 +64,9 @@ class task_manager
public function get_tasks($refresh = false)
{
if ($this->tasks && ! $refresh)
if ($this->tasks && ! $refresh) {
return $this->tasks;
}
$sql = "SELECT task2.* FROM task2 ORDER BY task_id ASC";
$stmt = $this->appbox->get_connection()->prepare($sql);

View File

@@ -153,9 +153,9 @@ class task_period_apibridge extends task_appboxAbstract
}
$element->set_connector_status($connector_status);
if ($status === $previous_status)
if ($status === $previous_status) {
return;
}
switch ($status) {
case Bridge_Element::STATUS_ERROR:

File diff suppressed because it is too large Load Diff

View File

@@ -273,17 +273,17 @@ class task_period_cindexer extends task_abstract
<br/>
<?php echo _('task::cindexer:host') ?>&nbsp;:&nbsp;<input type="text" name="host" style="width:100px;" onchange="chgxmltxt(this, 'host');" value="">
<br/>
<?php echo _('task::cindexer:port') ?>&nbsp;:&nbsp;<input type="text" name="port" style="width:100px;" onchange="chgxmltxt(this, 'port');" value="">
<?php echo _('task::cindexer:port') ?>&nbsp;:&nbsp;<input type="text" name="port" style="width:100px;" onchange="chgxmltxt(this, 'port');" value="">
<br/>
<?php echo _('task::cindexer:base') ?>&nbsp;:&nbsp;<input type="text" name="base" style="width:200px;" onchange="chgxmltxt(this, 'base');" value="">
<?php echo _('task::cindexer:base') ?>&nbsp;:&nbsp;<input type="text" name="base" style="width:200px;" onchange="chgxmltxt(this, 'base');" value="">
<br/>
<?php echo _('task::cindexer:user') ?>&nbsp;:&nbsp;<input type="text" name="user" style="width:200px;" onchange="chgxmltxt(this, 'user');" value="">
<br/>
<?php echo _('task::cindexer:password') ?>&nbsp;:&nbsp;<input type="text" name="password" style="width:200px;" onchange="chgxmltxt(this, 'password');" value="">
<?php echo _('task::cindexer:password') ?>&nbsp;:&nbsp;<input type="text" name="password" style="width:200px;" onchange="chgxmltxt(this, 'password');" value="">
<br/>
<br/>
<?php echo _('task::cindexer:control socket') ?>&nbsp;:&nbsp;<input type="text" name="socket" style="width:200px;" onchange="chgxmltxt(this, 'socket');" value="">
<?php echo _('task::cindexer:control socket') ?>&nbsp;:&nbsp;<input type="text" name="socket" style="width:200px;" onchange="chgxmltxt(this, 'socket');" value="">
<br/>
<br/>
@@ -292,7 +292,7 @@ class task_period_cindexer extends task_abstract
<br/>
</div>
<?php echo _('task::cindexer:MySQL charset') ?>&nbsp;:&nbsp;<input type="text" name="charset" style="width:200px;" onchange="chgxmltxt(this, 'charset');" value="">
<?php echo _('task::cindexer:MySQL charset') ?>&nbsp;:&nbsp;<input type="text" name="charset" style="width:200px;" onchange="chgxmltxt(this, 'charset');" value="">
<br/>
<br/>
@@ -315,60 +315,60 @@ class task_period_cindexer extends task_abstract
<center>
<div style="margin:10px; padding:5px; border:1px #000000 solid; font-family:monospace; font-size:16px; text-align:left; color:#00e000; background-color:#404040" id="cmd">cmd</div>
</center>
<?php
$out = ob_get_clean();
<?php
$out = ob_get_clean();
return $out;
return $out;
}
/**
*
* @param SimpleXMLElement $sx_task_settings
* @return task_cindexer
*/
protected function load_settings(SimpleXMLElement $sx_task_settings)
{
$this->host = trim($sx_task_settings->host);
$this->port = trim($sx_task_settings->port);
$this->base = trim($sx_task_settings->base);
$this->user = trim($sx_task_settings->user);
$this->password = trim($sx_task_settings->password);
$this->socket = trim($sx_task_settings->socket);
$this->use_sbas = p4field::isyes(trim($sx_task_settings->use_sbas));
$this->charset = trim($sx_task_settings->charset);
$this->nolog = p4field::isyes(trim($sx_task_settings->nolog));
$this->winsvc_run = p4field::isyes(trim($sx_task_settings->winsvc_run));
$this->binpath = p4string::addEndSlash(trim($sx_task_settings->binpath));
parent::load_settings($sx_task_settings);
return $this;
}
/**
*
* @return string
*/
protected function run2()
{
$this->method = self::METHOD_PROC_OPEN;
$this->method = self::METHOD_FORK;
$this->method = self::METHOD_EXEC;
$cmd = $this->binpath . 'phraseanet_indexer';
$nullfile = '/dev/null';
if ($this->system == 'WINDOWS') {
$cmd .= '.exe';
$nullfile = 'NULL';
}
/**
*
* @param SimpleXMLElement $sx_task_settings
* @return task_cindexer
*/
protected function load_settings(SimpleXMLElement $sx_task_settings)
{
$this->host = trim($sx_task_settings->host);
$this->port = trim($sx_task_settings->port);
$this->base = trim($sx_task_settings->base);
$this->user = trim($sx_task_settings->user);
$this->password = trim($sx_task_settings->password);
$this->socket = trim($sx_task_settings->socket);
$this->use_sbas = p4field::isyes(trim($sx_task_settings->use_sbas));
$this->charset = trim($sx_task_settings->charset);
$this->nolog = p4field::isyes(trim($sx_task_settings->nolog));
$this->winsvc_run = p4field::isyes(trim($sx_task_settings->winsvc_run));
$this->binpath = p4string::addEndSlash(trim($sx_task_settings->binpath));
if ( ! file_exists($cmd) || ! is_executable($cmd)) {
$this->log(sprintf(_('task::cindexer:file \'%s\' does not exists'), $cmd));
parent::load_settings($sx_task_settings);
return $this;
return;
}
/**
*
* @return string
*/
protected function run2()
{
$this->method = self::METHOD_PROC_OPEN;
$this->method = self::METHOD_FORK;
$this->method = self::METHOD_EXEC;
$cmd = $this->binpath . 'phraseanet_indexer';
$nullfile = '/dev/null';
if ($this->system == 'WINDOWS') {
$cmd .= '.exe';
$nullfile = 'NULL';
}
if ( ! file_exists($cmd) || ! is_executable($cmd)) {
$this->log(sprintf(_('task::cindexer:file \'%s\' does not exists'), $cmd));
return;
}
// $cmd .= $this->host ? " -h=" . $this->host : '';
// $cmd .= $this->port ? " -P=" . $this->port : '';
// $cmd .= $this->base ? " -b=" . $this->base : '';
@@ -380,196 +380,135 @@ class task_period_cindexer extends task_abstract
// $cmd .= $this->nolog ? " -n" : '';
// $cmd .= $this->winsvc_run ? " --run" : '';
$args = array();
if ($this->host)
$args[] = '-h=' . $this->host;
if ($this->port)
;
$args[] = '-P=' . $this->port;
if ($this->base)
$args[] = '-b=' . $this->base;
if ($this->user)
$args[] = '-u=' . $this->user;
if ($this->password)
$args[] = '-p=' . $this->password;
if ($this->socket)
$args[] = '--socket=' . $this->socket;
if ($this->use_sbas)
$args[] = '-o';
if ($this->charset)
$args[] = '--default-character-set=' . $this->charset;
if ($this->nolog)
$args[] = '-n';
if ($this->winsvc_run)
$args[] = '--run';
$args = array();
if ($this->host)
$args[] = '-h=' . $this->host;
if ($this->port)
;
$args[] = '-P=' . $this->port;
if ($this->base)
$args[] = '-b=' . $this->base;
if ($this->user)
$args[] = '-u=' . $this->user;
if ($this->password)
$args[] = '-p=' . $this->password;
if ($this->socket)
$args[] = '--socket=' . $this->socket;
if ($this->use_sbas)
$args[] = '-o';
if ($this->charset)
$args[] = '--default-character-set=' . $this->charset;
if ($this->nolog)
$args[] = '-n';
if ($this->winsvc_run)
$args[] = '--run';
$registry = registry::get_instance();
$logdir = p4string::addEndSlash($registry->get('GV_RootPath') . 'logs');
$registry = registry::get_instance();
$logdir = p4string::addEndSlash($registry->get('GV_RootPath') . 'logs');
$this->return_value = self::RETURNSTATUS_STOPPED; // will be normal ending
$this->return_value = self::RETURNSTATUS_STOPPED; // will be normal ending
if ($this->method == self::METHOD_PROC_OPEN) {
$descriptors = array();
if ($this->method == self::METHOD_PROC_OPEN) {
$descriptors = array();
// $descriptors[1] = array("file", $logdir . "/phraseanet_indexer_" . $this->get_task_id() . ".log", "a+");
// $descriptors[2] = array("file", $logdir . "/phraseanet_indexer_" . $this->get_task_id() . ".error.log", "a+");
$descriptors[1] = array("file", $nullfile, "a+");
$descriptors[2] = array("file", $nullfile, "a+");
$descriptors[1] = array("file", $nullfile, "a+");
$descriptors[2] = array("file", $nullfile, "a+");
$pipes = array();
$pipes = array();
$this->log(sprintf('cmd=\'%s %s\'', $cmd, implode(' ', $args)));
$process = proc_open($cmd . ' ' . implode(' ', $args), $descriptors, $pipes, $this->binpath, null, array('bypass_shell' => true));
$this->log(sprintf('cmd=\'%s %s\'', $cmd, implode(' ', $args)));
$process = proc_open($cmd . ' ' . implode(' ', $args), $descriptors, $pipes, $this->binpath, null, array('bypass_shell' => true));
$pid = NULL;
if (is_resource($process)) {
$proc_status = proc_get_status($process);
if ($proc_status['running'])
$pid = $proc_status['pid'];
}
$qsent = '';
$timetokill = NULL;
$sock = NULL;
$this->running = true;
while ($this->running) {
$this->check_task_status();
if ($this->task_status == self::STATUS_TOSTOP && $this->socket > 0) {
// must quit task, so send 'Q' to port 127.0.0.1:XXXX to cindexer
if ( ! $qsent && (($sock = socket_create(AF_INET, SOCK_STREAM, 0)) !== false)) {
if (socket_connect($sock, '127.0.0.1', $this->socket) === true) {
socket_write($sock, 'Q', 1);
socket_write($sock, "\r\n", strlen("\r\n"));
for ($i = 0; $this->running && $i < 5; $i ++ )
sleep(1);
$qsent = 'Q';
$timetokill = time() + 10;
} else {
socket_close($sock);
$sock = NULL;
}
}
}
$proc_status = proc_get_status($process);
if ( ! $proc_status['running']) {
// the cindexer died
if ($qsent == 'Q') {
$this->log(_('task::cindexer:the cindexer clean-quit'));
} elseif ($qsent == 'K') {
$this->log(_('task::cindexer:the cindexer has been killed'));
} else {
$this->log(_('task::cindexer:the cindexer crashed'));
$this->return_value = NULL; // NOT normal ending will enforce restart from scheduler
}
$this->running = false;
} else {
if ($qsent == 'Q') {
if (time() > $timetokill) {
// must kill cindexer
$this->log(_('task::cindexer:killing the cindexer'));
$qsent = 'K';
proc_terminate($process); // sigint
}
}
}
for ($i = 0; $this->running && $i < 5; $i ++ )
sleep(1);
}
if ($sock) {
socket_close($sock);
$sock = NULL;
}
foreach (array_keys($pipes) as $offset) {
if (is_resource($pipes[$offset]))
fclose($pipes[$offset]);
}
proc_terminate($process); // sigint
proc_close($process);
$pid = NULL;
if (is_resource($process)) {
$proc_status = proc_get_status($process);
if ($proc_status['running'])
$pid = $proc_status['pid'];
}
elseif ($this->method == self::METHOD_FORK) {
$pid = pcntl_fork();
if ($pid == -1) {
die("failed to fork");
} elseif ($pid == 0) {
// child
umask(0);
// openlog('MyLog', LOG_PID | LOG_PERROR, LOG_LOCAL0);
if (posix_setsid() < 0)
die("Forked process could not detach from terminal\n");
//chdir(dirname(__FILE__));
fclose(STDIN);
fclose(STDOUT);
fclose(STDERR);
$fdIN = fopen($nullfile, 'r');
// $fdOUT = fopen($nullfile, 'a+');
// $fdERR = fopen($nullfile, 'a+');
$fdOUT = fopen($logdir . "/task_o_" . $this->get_task_id() . ".log", "a+");
$fdERR = fopen($logdir . "/task_e_" . $this->get_task_id() . ".log", "a+");
pcntl_exec($cmd, $args);
$qsent = '';
$timetokill = NULL;
$sock = NULL;
sleep(2);
}
else {
// parent
$this->running = true;
$this->running = true;
$sigsent = NULL;
while ($this->running) {
// is the cindexer alive ?
if ( ! posix_kill($pid, 0)) {
// dead...
if ($sigsent === NULL) {
// but it's not my fault
$this->log(_('task::cindexer:the cindexer crashed'));
$this->running = false;
// return self::RETURNSTATUS_STOPPED;
break;
}
}
while ($this->running) {
$this->check_task_status();
$this->check_task_status();
if ($this->task_status == self::STATUS_TOSTOP) {
posix_kill($pid, ($sigsent = SIGINT));
sleep(2);
}
$status = NULL;
if (pcntl_wait($status, WNOHANG) == $pid) {
// child (indexer) has exited
if ($sigsent == SIGINT) {
$this->log(_('task::cindexer:the cindexer clean-quit'));
} elseif ($sigsent == SIGKILL) {
$this->log(_('task::cindexer:the cindexer has been killed'));
} else {
$this->log(_('task::cindexer:the cindexer crashed'));
$this->return_value = NULL; // NOT normal ending will enforce restart from scheduler
}
$this->running = false;
if ($this->task_status == self::STATUS_TOSTOP && $this->socket > 0) {
// must quit task, so send 'Q' to port 127.0.0.1:XXXX to cindexer
if ( ! $qsent && (($sock = socket_create(AF_INET, SOCK_STREAM, 0)) !== false)) {
if (socket_connect($sock, '127.0.0.1', $this->socket) === true) {
socket_write($sock, 'Q', 1);
socket_write($sock, "\r\n", strlen("\r\n"));
for ($i = 0; $this->running && $i < 5; $i ++ )
sleep(1);
$qsent = 'Q';
$timetokill = time() + 10;
} else {
if ($sigsent == SIGINT && time() > $timetokill) {
// must kill cindexer
$this->log(_('task::cindexer:killing the cindexer'));
$qsent = 'K';
posix_kill($pid, ($sigsent = SIGKILL));
}
sleep(2);
socket_close($sock);
$sock = NULL;
}
} // while running (method fork)
}
}
} elseif ($this->method == self::METHOD_EXEC) {
$proc_status = proc_get_status($process);
if ( ! $proc_status['running']) {
// the cindexer died
if ($qsent == 'Q') {
$this->log(_('task::cindexer:the cindexer clean-quit'));
} elseif ($qsent == 'K') {
$this->log(_('task::cindexer:the cindexer has been killed'));
} else {
$this->log(_('task::cindexer:the cindexer crashed'));
$this->return_value = NULL; // NOT normal ending will enforce restart from scheduler
}
$this->running = false;
} else {
if ($qsent == 'Q') {
if (time() > $timetokill) {
// must kill cindexer
$this->log(_('task::cindexer:killing the cindexer'));
$qsent = 'K';
proc_terminate($process); // sigint
}
}
}
for ($i = 0; $this->running && $i < 5; $i ++ )
sleep(1);
}
if ($sock) {
socket_close($sock);
$sock = NULL;
}
foreach (array_keys($pipes) as $offset) {
if (is_resource($pipes[$offset]))
fclose($pipes[$offset]);
}
proc_terminate($process); // sigint
proc_close($process);
}
elseif ($this->method == self::METHOD_FORK) {
$pid = pcntl_fork();
if ($pid == -1) {
die("failed to fork");
} elseif ($pid == 0) {
// child
umask(0);
// openlog('MyLog', LOG_PID | LOG_PERROR, LOG_LOCAL0);
if (posix_setsid() < 0)
die("Forked process could not detach from terminal\n");
//chdir(dirname(__FILE__));
fclose(STDIN);
fclose(STDOUT);
fclose(STDERR);
$fdIN = fopen($nullfile, 'r');
// $fdOUT = fopen($nullfile, 'a+');
// $fdERR = fopen($nullfile, 'a+');
$fdOUT = fopen($logdir . "/task_o_" . $this->get_task_id() . ".log", "a+");
$fdERR = fopen($logdir . "/task_e_" . $this->get_task_id() . ".log", "a+");
@@ -577,8 +516,69 @@ class task_period_cindexer extends task_abstract
sleep(2);
}
else {
// parent
$this->running = true;
return($this->return_value);
$sigsent = NULL;
while ($this->running) {
// is the cindexer alive ?
if ( ! posix_kill($pid, 0)) {
// dead...
if ($sigsent === NULL) {
// but it's not my fault
$this->log(_('task::cindexer:the cindexer crashed'));
$this->running = false;
// return self::RETURNSTATUS_STOPPED;
break;
}
}
$this->check_task_status();
if ($this->task_status == self::STATUS_TOSTOP) {
posix_kill($pid, ($sigsent = SIGINT));
sleep(2);
}
$status = NULL;
if (pcntl_wait($status, WNOHANG) == $pid) {
// child (indexer) has exited
if ($sigsent == SIGINT) {
$this->log(_('task::cindexer:the cindexer clean-quit'));
} elseif ($sigsent == SIGKILL) {
$this->log(_('task::cindexer:the cindexer has been killed'));
} else {
$this->log(_('task::cindexer:the cindexer crashed'));
$this->return_value = NULL; // NOT normal ending will enforce restart from scheduler
}
$this->running = false;
} else {
if ($sigsent == SIGINT && time() > $timetokill) {
// must kill cindexer
$this->log(_('task::cindexer:killing the cindexer'));
$qsent = 'K';
posix_kill($pid, ($sigsent = SIGKILL));
}
sleep(2);
}
} // while running (method fork)
}
} elseif ($this->method == self::METHOD_EXEC) {
umask(0);
fclose(STDIN);
fclose(STDOUT);
fclose(STDERR);
$fdIN = fopen($nullfile, 'r');
$fdOUT = fopen($logdir . "/task_o_" . $this->get_task_id() . ".log", "a+");
$fdERR = fopen($logdir . "/task_e_" . $this->get_task_id() . ".log", "a+");
pcntl_exec($cmd, $args);
sleep(2);
}
}
return($this->return_value);
}
}

View File

@@ -160,542 +160,543 @@ class task_period_ftp extends task_appboxAbstract
<input type="text" name="period" style="width:40px;" onchange="chgxmltxt(this, 'period');">
&nbsp;<?php echo('task::_common_:secondes (unite temporelle)') ?><br/>
</form>
<?php
$out = ob_get_clean();
<?php
$out = ob_get_clean();
return $out;
}
return $out;
}
public function saveChanges(connection_pdo $conn, $taskid, &$taskrow)
{
$request = http_request::getInstance();
public function saveChanges(connection_pdo $conn, $taskid, &$taskrow)
{
$request = http_request::getInstance();
$parm = $request->get_parms("xml", "name", "active", "proxy", "proxyport", "period", "debug");
$parm = $request->get_parms("xml", "name", "active", "proxy", "proxyport", "period", "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") 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 ($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") 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();
}
if ($xmlchanged)
$parm["xml"] = $domTaskSettings->saveXML();
}
}
// si on doit changer le xml, on verifie qu'il est valide
if ($parm["xml"] && ! @DOMDocument::loadXML($parm["xml"]))
return(false);
// si on doit changer le xml, on verifie qu'il est valide
if ($parm["xml"] && ! @DOMDocument::loadXML($parm["xml"])) {
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'];
}
$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'];
}
if ($sql) {
try {
$sql = "UPDATE task2 SET $sql WHERE task_id = :task_id";
$stmt = $conn->prepare($sql);
$stmt->execute($params);
$stmt->closeCursor();
if ($sql) {
try {
$sql = "UPDATE task2 SET $sql WHERE task_id = :task_id";
$stmt = $conn->prepare($sql);
$stmt->execute($params);
$stmt->closeCursor();
return true;
} catch (Exception $e) {
return false;
}
} else {
return true;
} catch (Exception $e) {
return false;
}
} else {
return true;
}
protected $proxy;
protected $proxyport;
protected $debug;
}
protected $proxy;
protected $proxyport;
protected $debug;
protected function load_settings(SimpleXMLElement $sx_task_settings)
{
$this->proxy = (string) $sx_task_settings->proxy;
$this->proxyport = (string) $sx_task_settings->proxyport;
protected function load_settings(SimpleXMLElement $sx_task_settings)
{
$this->proxy = (string) $sx_task_settings->proxy;
$this->proxyport = (string) $sx_task_settings->proxyport;
parent::load_settings($sx_task_settings);
parent::load_settings($sx_task_settings);
return $this;
}
return $this;
}
protected function retrieve_content(appbox $appbox)
{
$conn = $appbox->get_connection();
protected function retrieve_content(appbox $appbox)
{
$conn = $appbox->get_connection();
$time2sleep = null;
$ftp_exports = array();
$time2sleep = null;
$ftp_exports = array();
$period = $this->period;
$time2sleep = (int) ($period);
$period = $this->period;
$time2sleep = (int) ($period);
$sql = "SELECT id FROM ftp_export WHERE crash>=nbretry
$sql = "SELECT id FROM ftp_export WHERE crash>=nbretry
AND date < :date";
$params = array(':date' => phraseadate::format_mysql(new DateTime('-30 days')));
$params = array(':date' => phraseadate::format_mysql(new DateTime('-30 days')));
$stmt = $conn->prepare($sql);
$stmt->execute($params);
$rs = $stmt->fetchAll(PDO::FETCH_ASSOC);
$stmt->closeCursor();
foreach ($rs as $rowtask) {
$sql = "DELETE FROM ftp_export WHERE id = :export_id";
$stmt = $conn->prepare($sql);
$stmt->execute($params);
$rs = $stmt->fetchAll(PDO::FETCH_ASSOC);
$stmt->execute(array(':export_id' => $rowtask['id']));
$stmt->closeCursor();
foreach ($rs as $rowtask) {
$sql = "DELETE FROM ftp_export WHERE id = :export_id";
$stmt = $conn->prepare($sql);
$stmt->execute(array(':export_id' => $rowtask['id']));
$stmt->closeCursor();
$sql = "DELETE FROM ftp_export_elements WHERE ftp_export_id = :export_id";
$stmt = $conn->prepare($sql);
$stmt->execute(array(':export_id' => $rowtask['id']));
$stmt->closeCursor();
}
$sql = "SELECT * FROM ftp_export WHERE crash<nbretry ORDER BY id";
$sql = "DELETE FROM ftp_export_elements WHERE ftp_export_id = :export_id";
$stmt = $conn->prepare($sql);
$stmt->execute();
$rs = $stmt->fetchAll(PDO::FETCH_ASSOC);
$stmt->execute(array(':export_id' => $rowtask['id']));
$stmt->closeCursor();
}
foreach ($rs as $row) {
$ftp_exports[$row["id"]] = array_merge(array('files' => array()), $row);
}
$sql = "SELECT * FROM ftp_export WHERE crash<nbretry ORDER BY id";
$stmt = $conn->prepare($sql);
$stmt->execute();
$rs = $stmt->fetchAll(PDO::FETCH_ASSOC);
$stmt->closeCursor();
$sql = "SELECT e.* from ftp_export f
foreach ($rs as $row) {
$ftp_exports[$row["id"]] = array_merge(array('files' => array()), $row);
}
$sql = "SELECT e.* from ftp_export f
INNER JOIN ftp_export_elements e
ON (f.id=e.ftp_export_id AND f.crash<f.nbretry
AND (e.done = 0 or error=1))
ORDER BY f.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();
foreach ($rs as $rowtask) {
if (isset($ftp_exports[$rowtask["ftp_export_id"]]))
$ftp_exports[$rowtask["ftp_export_id"]]["files"][] = $rowtask;
}
return $ftp_exports;
foreach ($rs as $rowtask) {
if (isset($ftp_exports[$rowtask["ftp_export_id"]]))
$ftp_exports[$rowtask["ftp_export_id"]]["files"][] = $rowtask;
}
protected function process_one_content(appbox $appbox, Array $ftp_export)
{
$conn = $appbox->get_connection();
$registry = $appbox->get_registry();
return $ftp_exports;
}
$id = $ftp_export['id'];
$ftp_export[$id]["crash"] = $ftp_export["crash"];
$ftp_export[$id]["nbretry"] = $ftp_export["nbretry"] < 1 ? 3 : (int) $ftp_export["nbretry"];
protected function process_one_content(appbox $appbox, Array $ftp_export)
{
$conn = $appbox->get_connection();
$registry = $appbox->get_registry();
$state = "";
$ftp_server = $ftp_export["addr"];
$ftp_user_name = $ftp_export["login"];
$ftp_user_pass = $ftp_export["pwd"];
$usr_id = (int) $ftp_export["usr_id"];
$id = $ftp_export['id'];
$ftp_export[$id]["crash"] = $ftp_export["crash"];
$ftp_export[$id]["nbretry"] = $ftp_export["nbretry"] < 1 ? 3 : (int) $ftp_export["nbretry"];
$ftpLog = $ftp_user_name . "@" . p4string::addEndSlash($ftp_server) . $ftp_export["destfolder"];
$state = "";
$ftp_server = $ftp_export["addr"];
$ftp_user_name = $ftp_export["login"];
$ftp_user_pass = $ftp_export["pwd"];
$usr_id = (int) $ftp_export["usr_id"];
if ($ftp_export["crash"] == 0) {
$state .= $line = sprintf(
_('task::ftp:Etat d\'envoi FTP vers le serveur' .
' "%1$s" avec le compte "%2$s" et pour destination le dossier : "%3$s"') . PHP_EOL
, $ftp_server
, $ftp_user_name
, $ftp_export["destfolder"]
);
if ($this->debug)
echo $line;
}
$ftpLog = $ftp_user_name . "@" . p4string::addEndSlash($ftp_server) . $ftp_export["destfolder"];
if ($ftp_export["crash"] == 0) {
$state .= $line = sprintf(
_("task::ftp:TENTATIVE no %s, %s")
, $ftp_export["crash"] + 1
, " (" . date('r') . ")"
) . PHP_EOL;
_('task::ftp:Etat d\'envoi FTP vers le serveur' .
' "%1$s" avec le compte "%2$s" et pour destination le dossier : "%3$s"') . PHP_EOL
, $ftp_server
, $ftp_user_name
, $ftp_export["destfolder"]
);
if ($this->debug)
echo $line;
}
if (($ses_id = phrasea_create_session($usr_id)) == null) {
echo "Unable to create session\n";
continue;
$state .= $line = sprintf(
_("task::ftp:TENTATIVE no %s, %s")
, $ftp_export["crash"] + 1
, " (" . date('r') . ")"
) . PHP_EOL;
if ($this->debug)
echo $line;
if (($ses_id = phrasea_create_session($usr_id)) == null) {
echo "Unable to create session\n";
continue;
}
if ( ! ($ph_session = phrasea_open_session($ses_id, $usr_id))) {
echo "Unable to open session\n";
phrasea_close_session($ses_id);
continue;
}
try {
$ssl = ($ftp_export['ssl'] == '1');
$ftp_client = new ftpclient($ftp_server, 21, 300, $ssl, $this->proxy, $this->proxyport);
$ftp_client->login($ftp_user_name, $ftp_user_pass);
if ($ftp_export["passif"] == "1") {
try {
$ftp_client->passive(true);
} catch (Exception $e) {
echo $e->getMessage();
}
}
if ( ! ($ph_session = phrasea_open_session($ses_id, $usr_id))) {
echo "Unable to open session\n";
phrasea_close_session($ses_id);
continue;
if (trim($ftp_export["destfolder"]) != '') {
try {
$ftp_client->chdir($ftp_export["destfolder"]);
$ftp_export["destfolder"] = '/' . $ftp_export["destfolder"];
} catch (Exception $e) {
echo $e->getMessage();
}
} else {
$ftp_export["destfolder"] = '/';
}
try {
$ssl = ($ftp_export['ssl'] == '1');
$ftp_client = new ftpclient($ftp_server, 21, 300, $ssl, $this->proxy, $this->proxyport);
$ftp_client->login($ftp_user_name, $ftp_user_pass);
if ($ftp_export["passif"] == "1") {
try {
$ftp_client->passive(true);
} catch (Exception $e) {
echo $e->getMessage();
}
if (trim($ftp_export["foldertocreate"]) != '') {
try {
$ftp_client->mkdir($ftp_export["foldertocreate"]);
} catch (Exception $e) {
echo $e->getMessage();
}
if (trim($ftp_export["destfolder"]) != '') {
try {
$ftp_client->chdir($ftp_export["destfolder"]);
$ftp_export["destfolder"] = '/' . $ftp_export["destfolder"];
} catch (Exception $e) {
echo $e->getMessage();
}
} else {
$ftp_export["destfolder"] = '/';
try {
$new_dir = $ftp_client->add_end_slash($ftp_export["destfolder"])
. $ftp_export["foldertocreate"];
$ftp_client->chdir($new_dir);
} catch (Exception $e) {
echo $e->getMessage();
}
}
if (trim($ftp_export["foldertocreate"]) != '') {
try {
$ftp_client->mkdir($ftp_export["foldertocreate"]);
} catch (Exception $e) {
echo $e->getMessage();
}
try {
$new_dir = $ftp_client->add_end_slash($ftp_export["destfolder"])
. $ftp_export["foldertocreate"];
$ftp_client->chdir($new_dir);
} catch (Exception $e) {
echo $e->getMessage();
}
}
$obj = array();
$obj = array();
$basefolder = '';
if ( ! in_array(trim($ftp_export["destfolder"]), array('.', './', '')))
$basefolder = p4string::addEndSlash($ftp_export["destfolder"]);
$basefolder = '';
if ( ! in_array(trim($ftp_export["destfolder"]), array('.', './', '')))
$basefolder = p4string::addEndSlash($ftp_export["destfolder"]);
$basefolder .= $ftp_export["foldertocreate"];
$basefolder .= $ftp_export["foldertocreate"];
if (in_array(trim($basefolder), array('.', './', '')))
$basefolder = '/';
if (in_array(trim($basefolder), array('.', './', '')))
$basefolder = '/';
foreach ($ftp_export['files'] as $fileid => $file) {
$base_id = $file["base_id"];
$record_id = $file["record_id"];
$subdef = $file['subdef'];
foreach ($ftp_export['files'] as $fileid => $file) {
$base_id = $file["base_id"];
$record_id = $file["record_id"];
$subdef = $file['subdef'];
try {
$sbas_id = phrasea::sbasFromBas($base_id);
$record = new record_adapter($sbas_id, $record_id);
try {
$sbas_id = phrasea::sbasFromBas($base_id);
$record = new record_adapter($sbas_id, $record_id);
$sdcaption = $record->get_caption()->serialize(caption_record::SERIALIZE_XML, $ftp_export["businessfields"]);
$sdcaption = $record->get_caption()->serialize(caption_record::SERIALIZE_XML, $ftp_export["businessfields"]);
$remotefile = $file["filename"];
$remotefile = $file["filename"];
if ($subdef == 'caption') {
$desc = $record->get_caption()->serialize(\caption_record::SERIALIZE_XML, $ftp_export["businessfields"]);
if ($subdef == 'caption') {
$desc = $record->get_caption()->serialize(\caption_record::SERIALIZE_XML, $ftp_export["businessfields"]);
$localfile = $registry->get('GV_RootPath') . 'tmp/' . md5($desc . time() . mt_rand());
if (file_put_contents($localfile, $desc) === false) {
throw new Exception('Impossible de creer un fichier temporaire');
}
} elseif ($subdef == 'caption-yaml') {
$desc = $record->get_caption()->serialize(\caption_record::SERIALIZE_YAML, $ftp_export["businessfields"]);
$localfile = $registry->get('GV_RootPath') . 'tmp/' . md5($desc . time() . mt_rand());
if (file_put_contents($localfile, $desc) === false) {
throw new Exception('Impossible de creer un fichier temporaire');
}
} elseif ($subdef == 'caption-yaml') {
$desc = $record->get_caption()->serialize(\caption_record::SERIALIZE_YAML, $ftp_export["businessfields"]);
$localfile = $registry->get('GV_RootPath') . 'tmp/' . md5($desc . time() . mt_rand());
if (file_put_contents($localfile, $desc) === false) {
throw new Exception('Impossible de creer un fichier temporaire');
}
} else {
$sd = $record->get_subdefs();
$localfile = $registry->get('GV_RootPath') . 'tmp/' . md5($desc . time() . mt_rand());
if (file_put_contents($localfile, $desc) === false) {
throw new Exception('Impossible de creer un fichier temporaire');
}
} else {
$sd = $record->get_subdefs();
if ( ! $sd || ! isset($sd[$subdef])) {
continue;
}
$localfile = $sd[$subdef]->get_pathfile();
if ( ! file_exists($localfile)) {
throw new Exception('Le fichier local n\'existe pas');
}
if ( ! $sd || ! isset($sd[$subdef])) {
continue;
}
$current_folder = p4string::delEndSlash(str_replace('//', '/', $basefolder . $file['folder']));
if ($ftp_client->pwd() != $current_folder) {
try {
$ftp_client->chdir($current_folder);
} catch (Exception $e) {
echo $e->getMessage();
}
$localfile = $sd[$subdef]->get_pathfile();
if ( ! file_exists($localfile)) {
throw new Exception('Le fichier local n\'existe pas');
}
}
$ftp_client->put($remotefile, $localfile);
$current_folder = p4string::delEndSlash(str_replace('//', '/', $basefolder . $file['folder']));
$obj[] = array(
"name" => $subdef, "size" => filesize($localfile),
"shortXml" => ($sdcaption ? $sdcaption : '')
);
if ($subdef == 'caption') {
unlink($localfile);
if ($ftp_client->pwd() != $current_folder) {
try {
$ftp_client->chdir($current_folder);
} catch (Exception $e) {
echo $e->getMessage();
}
}
$sql = "UPDATE ftp_export_elements
$ftp_client->put($remotefile, $localfile);
$obj[] = array(
"name" => $subdef, "size" => filesize($localfile),
"shortXml" => ($sdcaption ? $sdcaption : '')
);
if ($subdef == 'caption') {
unlink($localfile);
}
$sql = "UPDATE ftp_export_elements
SET done='1', error='0' WHERE id = :file_id";
$stmt = $conn->prepare($sql);
$stmt->execute(array(':file_id' => $file['id']));
$stmt->closeCursor();
$this->logexport($appbox->get_session(), $record, $obj, $ftpLog);
} catch (Exception $e) {
$state .= $line = sprintf(_('task::ftp:File "%1$s" (record %2$s) de la base "%3$s"' .
' (Export du Document) : Transfert cancelled (le document n\'existe plus)')
, basename($localfile), $record_id
, phrasea::sbas_names(phrasea::sbasFromBas($base_id))) . "\n<br/>";
$stmt = $conn->prepare($sql);
$stmt->execute(array(':file_id' => $file['id']));
$stmt->closeCursor();
$this->logexport($appbox->get_session(), $record, $obj, $ftpLog);
} catch (Exception $e) {
$state .= $line = sprintf(_('task::ftp:File "%1$s" (record %2$s) de la base "%3$s"' .
' (Export du Document) : Transfert cancelled (le document n\'existe plus)')
, basename($localfile), $record_id
, phrasea::sbas_names(phrasea::sbasFromBas($base_id))) . "\n<br/>";
if ($this->debug)
echo $line;
$done = $file['error'];
$sql = "UPDATE ftp_export_elements
SET done = :done, error='1' WHERE id = :file_id";
$stmt = $conn->prepare($sql);
$stmt->execute(array(':done' => $done, ':file_id' => $file['id']));
$stmt->closeCursor();
}
}
if ($ftp_export['logfile']) {
if ($this->debug)
echo "\nlogfile \n";
echo $line;
$date = new DateTime();
$remote_file = $date->format('U');
$done = $file['error'];
$sql = 'SELECT filename, folder
$sql = "UPDATE ftp_export_elements
SET done = :done, error='1' WHERE id = :file_id";
$stmt = $conn->prepare($sql);
$stmt->execute(array(':done' => $done, ':file_id' => $file['id']));
$stmt->closeCursor();
}
}
if ($ftp_export['logfile']) {
if ($this->debug)
echo "\nlogfile \n";
$date = new DateTime();
$remote_file = $date->format('U');
$sql = 'SELECT filename, folder
FROM ftp_export_elements
WHERE ftp_export_id = :ftp_export_id
AND error = "0" AND done="1"';
$stmt = $conn->prepare($sql);
$stmt->execute(array(':ftp_export_id' => $id));
$rs = $stmt->fetchAll(\PDO::FETCH_ASSOC);
$stmt->closeCursor();
$buffer = '#transfert finished ' . $date->format(DATE_ATOM) . "\n\n";
foreach ($rs as $row) {
$filename = $row['filename'];
$folder = $row['folder'];
$root = $ftp_export['foldertocreate'];
$buffer .= $root . '/' . $folder . $filename . "\n";
}
$tmpfile = $registry->get('GV_RootPath') . 'tmp/tmpftpbuffer' . $date->format('U') . '.txt';
file_put_contents($tmpfile, $buffer);
$remotefile = $date->format('U') . '-transfert.log';
$ftp_client->chdir($ftp_export["destfolder"]);
$ftp_client->put($remotefile, $tmpfile);
unlink($tmpfile);
}
$ftp_client->close();
unset($ftp_client);
} catch (Exception $e) {
$state .= $line = $e . "\n";
if ($this->debug)
echo $line;
$sql = "UPDATE ftp_export SET crash=crash+1,date=now()
WHERE id = :export_id";
$stmt = $conn->prepare($sql);
$stmt->execute(array(':export_id' => $ftp_export['id']));
$stmt->execute(array(':ftp_export_id' => $id));
$rs = $stmt->fetchAll(\PDO::FETCH_ASSOC);
$stmt->closeCursor();
unset($ftp_client);
}
$this->finalize($appbox, $id);
phrasea_close_session($ses_id);
}
$buffer = '#transfert finished ' . $date->format(DATE_ATOM) . "\n\n";
foreach ($rs as $row) {
$filename = $row['filename'];
$folder = $row['folder'];
$root = $ftp_export['foldertocreate'];
$buffer .= $root . '/' . $folder . $filename . "\n";
}
$tmpfile = $registry->get('GV_RootPath') . 'tmp/tmpftpbuffer' . $date->format('U') . '.txt';
file_put_contents($tmpfile, $buffer);
$remotefile = $date->format('U') . '-transfert.log';
$ftp_client->chdir($ftp_export["destfolder"]);
$ftp_client->put($remotefile, $tmpfile);
unlink($tmpfile);
}
$ftp_client->close();
unset($ftp_client);
} catch (Exception $e) {
$state .= $line = $e . "\n";
if ($this->debug)
echo $line;
$sql = "UPDATE ftp_export SET crash=crash+1,date=now()
WHERE id = :export_id";
$stmt = $conn->prepare($sql);
$stmt->execute(array(':export_id' => $ftp_export['id']));
$stmt->closeCursor();
unset($ftp_client);
}
$this->finalize($appbox, $id);
phrasea_close_session($ses_id);
}
protected function post_process_one_content(appbox $appbox, Array $row)
{
return $this;
}
function finalize(appbox $appbox, $id)
{
$conn = $appbox->get_connection();
$sql = 'SELECT crash, nbretry FROM ftp_export
WHERE id = :export_id';
$stmt = $conn->prepare($sql);
$stmt->execute(array(':export_id' => $id));
$row = $stmt->fetch(PDO::FETCH_ASSOC);
$stmt->closeCursor();
if ($row && $row['crash'] >= $row['nbretry']) {
$this->send_mails($appbox, $id);
protected function post_process_one_content(appbox $appbox, Array $row)
{
return $this;
}
function finalize(appbox $appbox, $id)
{
$conn = $appbox->get_connection();
$sql = 'SELECT crash, nbretry FROM ftp_export
WHERE id = :export_id';
$stmt = $conn->prepare($sql);
$stmt->execute(array(':export_id' => $id));
$row = $stmt->fetch(PDO::FETCH_ASSOC);
$stmt->closeCursor();
if ($row && $row['crash'] >= $row['nbretry']) {
$this->send_mails($appbox, $id);
return $this;
}
$sql = 'SELECT count(id) as total, sum(error) as errors, sum(done) as done
$sql = 'SELECT count(id) as total, sum(error) as errors, sum(done) as done
FROM ftp_export_elements WHERE ftp_export_id = :export_id';
$stmt = $conn->prepare($sql);
$stmt->execute(array(':export_id' => $id));
$row = $stmt->fetch(PDO::FETCH_ASSOC);
$stmt->closeCursor();
$stmt = $conn->prepare($sql);
$stmt->execute(array(':export_id' => $id));
$row = $stmt->fetch(PDO::FETCH_ASSOC);
$stmt->closeCursor();
if ($row && $row['done'] == (int) $row['total']) {
$this->send_mails($appbox, $id);
if ($row && $row['done'] == (int) $row['total']) {
$this->send_mails($appbox, $id);
if ((int) $row['errors'] === 0) {
$sql = 'DELETE FROM ftp_export WHERE id = :export_id';
$stmt = $conn->prepare($sql);
$stmt->execute(array(':export_id' => $id));
$stmt->closeCursor();
$sql = 'DELETE FROM ftp_export_elements WHERE ftp_export_id = :export_id';
$stmt = $conn->prepare($sql);
$stmt->execute(array(':export_id' => $id));
$stmt->closeCursor();
} else {
$sql = 'UPDATE ftp_export SET crash = nbretry';
$stmt = $conn->prepare($sql);
$stmt->execute();
$stmt->closeCursor();
$sql = 'DELET FROM ftp_export_elements WHERE ftp_export_id = :export_id AND error="0"';
$stmt = $conn->prepare($sql);
$stmt->execute(array(':export_id' => $id));
$stmt->closeCursor();
}
return $this;
}
}
function send_mails(appbox $appbox, $id)
{
$conn = $appbox->get_connection();
$registry = registry::get_instance();
$sql = 'SELECT filename, base_id, record_id, subdef, error, done
FROM ftp_export_elements WHERE ftp_export_id = :export_id';
$transferts = array();
$transfert_status = _('task::ftp:Tous les documents ont ete transferes avec succes');
$stmt = $conn->prepare($sql);
$stmt->execute(array(':export_id' => $id));
$rs = $stmt->fetchAll(PDO::FETCH_ASSOC);
$stmt->closeCursor();
foreach ($rs as $row) {
if ($row['error'] == '0' && $row['done'] == '1') {
$transferts[] =
'<li>' . sprintf(_('task::ftp:Record %1$s - %2$s de la base (%3$s - %4$s) - %5$s')
, $row["record_id"], $row["filename"]
, phrasea::sbas_names(phrasea::sbasFromBas($row["base_id"]))
, phrasea::bas_names($row['base_id']), $row['subdef']) . ' : ' . _('Transfert OK') . '</li>';
} else {
$transferts[] =
'<li>' . sprintf(_('task::ftp:Record %1$s - %2$s de la base (%3$s - %4$s) - %5$s')
, $row["record_id"], $row["filename"]
, phrasea::sbas_names(phrasea::sbasFromBas($row["base_id"])), phrasea::bas_names($row['base_id'])
, $row['subdef']) . ' : ' . _('Transfert Annule') . '</li>';
$transfert_status = _('task::ftp:Certains documents n\'ont pas pu etre tranferes');
}
}
$sql = 'SELECT addr, crash, nbretry, sendermail, mail, text_mail_sender, text_mail_receiver
FROM ftp_export WHERE id = :export_id';
$stmt = $conn->prepare($sql);
$stmt->execute(array(':export_id' => $id));
$row = $stmt->fetch(PDO::FETCH_ASSOC);
$stmt->closeCursor();
if ($row) {
if ($row['crash'] >= $row['nbretry'])
$connection_status = _('Des difficultes ont ete rencontres a la connection au serveur distant');
else
$connection_status = _('La connection vers le serveur distant est OK');
$text_mail_sender = $row['text_mail_sender'];
$text_mail_receiver = $row['text_mail_receiver'];
$mail = $row['mail'];
$sendermail = $row['sendermail'];
$ftp_server = $row['addr'];
}
$message = "\n<br/>----------------------------------------<br/>\n";
$message = "<div>" . $connection_status . "</div>\n";
$message .= "<div>" . $transfert_status . "</div>\n";
$message .= "<div>" . _("task::ftp:Details des fichiers") . "</div>\n";
$message .= "<ul>";
$message .= implode("\n", $transferts);
$message .= "</ul>";
$sender_message = $text_mail_sender . $message;
$receiver_message = $text_mail_receiver . $message;
$subject = sprintf(
_('task::ftp:Status about your FTP transfert from %1$s to %2$s')
, $registry->get('GV_homeTitle'), $ftp_server
);
mail::ftp_sent($sendermail, $subject, $sender_message);
mail::ftp_receive($mail, $receiver_message);
}
function logexport(Session_Handler $session, record_adapter $record, $obj, $ftpLog)
{
foreach ($obj as $oneObj) {
$session->get_logger($record->get_databox())
->log($record, Session_Logger::EVENT_EXPORTFTP, $ftpLog, '');
if ((int) $row['errors'] === 0) {
$sql = 'DELETE FROM ftp_export WHERE id = :export_id';
$stmt = $conn->prepare($sql);
$stmt->execute(array(':export_id' => $id));
$stmt->closeCursor();
$sql = 'DELETE FROM ftp_export_elements WHERE ftp_export_id = :export_id';
$stmt = $conn->prepare($sql);
$stmt->execute(array(':export_id' => $id));
$stmt->closeCursor();
} else {
$sql = 'UPDATE ftp_export SET crash = nbretry';
$stmt = $conn->prepare($sql);
$stmt->execute();
$stmt->closeCursor();
$sql = 'DELET FROM ftp_export_elements WHERE ftp_export_id = :export_id AND error="0"';
$stmt = $conn->prepare($sql);
$stmt->execute(array(':export_id' => $id));
$stmt->closeCursor();
}
return $this;
}
}
function send_mails(appbox $appbox, $id)
{
$conn = $appbox->get_connection();
$registry = registry::get_instance();
$sql = 'SELECT filename, base_id, record_id, subdef, error, done
FROM ftp_export_elements WHERE ftp_export_id = :export_id';
$transferts = array();
$transfert_status = _('task::ftp:Tous les documents ont ete transferes avec succes');
$stmt = $conn->prepare($sql);
$stmt->execute(array(':export_id' => $id));
$rs = $stmt->fetchAll(PDO::FETCH_ASSOC);
$stmt->closeCursor();
foreach ($rs as $row) {
if ($row['error'] == '0' && $row['done'] == '1') {
$transferts[] =
'<li>' . sprintf(_('task::ftp:Record %1$s - %2$s de la base (%3$s - %4$s) - %5$s')
, $row["record_id"], $row["filename"]
, phrasea::sbas_names(phrasea::sbasFromBas($row["base_id"]))
, phrasea::bas_names($row['base_id']), $row['subdef']) . ' : ' . _('Transfert OK') . '</li>';
} else {
$transferts[] =
'<li>' . sprintf(_('task::ftp:Record %1$s - %2$s de la base (%3$s - %4$s) - %5$s')
, $row["record_id"], $row["filename"]
, phrasea::sbas_names(phrasea::sbasFromBas($row["base_id"])), phrasea::bas_names($row['base_id'])
, $row['subdef']) . ' : ' . _('Transfert Annule') . '</li>';
$transfert_status = _('task::ftp:Certains documents n\'ont pas pu etre tranferes');
}
}
$sql = 'SELECT addr, crash, nbretry, sendermail, mail, text_mail_sender, text_mail_receiver
FROM ftp_export WHERE id = :export_id';
$stmt = $conn->prepare($sql);
$stmt->execute(array(':export_id' => $id));
$row = $stmt->fetch(PDO::FETCH_ASSOC);
$stmt->closeCursor();
if ($row) {
if ($row['crash'] >= $row['nbretry'])
$connection_status = _('Des difficultes ont ete rencontres a la connection au serveur distant');
else
$connection_status = _('La connection vers le serveur distant est OK');
$text_mail_sender = $row['text_mail_sender'];
$text_mail_receiver = $row['text_mail_receiver'];
$mail = $row['mail'];
$sendermail = $row['sendermail'];
$ftp_server = $row['addr'];
}
$message = "\n<br/>----------------------------------------<br/>\n";
$message = "<div>" . $connection_status . "</div>\n";
$message .= "<div>" . $transfert_status . "</div>\n";
$message .= "<div>" . _("task::ftp:Details des fichiers") . "</div>\n";
$message .= "<ul>";
$message .= implode("\n", $transferts);
$message .= "</ul>";
$sender_message = $text_mail_sender . $message;
$receiver_message = $text_mail_receiver . $message;
$subject = sprintf(
_('task::ftp:Status about your FTP transfert from %1$s to %2$s')
, $registry->get('GV_homeTitle'), $ftp_server
);
mail::ftp_sent($sendermail, $subject, $sender_message);
mail::ftp_receive($mail, $receiver_message);
}
function logexport(Session_Handler $session, record_adapter $record, $obj, $ftpLog)
{
foreach ($obj as $oneObj) {
$session->get_logger($record->get_databox())
->log($record, Session_Logger::EVENT_EXPORTFTP, $ftpLog, '');
}
return $this;
}
}

View File

@@ -139,14 +139,14 @@ class task_period_ftpPull extends task_appboxAbstract
?>
<form name="graphicForm" onsubmit="return(false);" method="post">
<br/>
<?php echo('task::ftp:proxy') ?>
<?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') ?>
<?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') ?>
<?php echo('task::ftp:host') ?>
<input type="text" name="host" style="width:400px;" onchange="chgxmltxt(this, 'host');"><br/>
<br/>
<?php echo('task::ftp:port') ?>
@@ -155,13 +155,13 @@ class task_period_ftpPull extends task_appboxAbstract
<?php echo('task::ftp:user') ?>
<input type="text" name="user" style="width:400px;" onchange="chgxmltxt(this, 'user');"><br/>
<br/>
<?php echo('task::ftp:password') ?>
<?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') ?>
<?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') ?>
<?php echo('task::ftp:localpath') ?>
<input type="text" name="localpath" style="width:400px;" onchange="chgxmltxt(this, 'localpath');"><br/>
<br/>
@@ -218,8 +218,9 @@ class task_period_ftpPull extends task_appboxAbstract
}
// si on doit changer le xml, on verifie qu'il est valide
if ($parm["xml"] && ! DOMDocument::loadXML($parm["xml"]))
if ($parm["xml"] && ! DOMDocument::loadXML($parm["xml"])) {
return(false);
}
$sql = "";
$params = array(':task_id' => $taskid);

View File

@@ -399,16 +399,16 @@ class task_period_outofdate extends task_abstract
$sbas_list = $user->ACL()->get_granted_sbas(array('bas_manage'));
?>
<form name="graphicForm" onsubmit="return(false);" method="post">
<?php echo _('task::outofdate:Base') ?>&nbsp;:&nbsp;
<?php echo _('task::outofdate:Base') ?>&nbsp;:&nbsp;
<select onchange="chgsbas(this);setDirty();" name="sbas_id">
<option value="">...</option>
<?php
foreach ($sbas_list as $databox) {
$selected = '';
print("\t\t\t\t<option value=\"" . $databox->get_sbas_id() . "\" $selected>" . p4string::MakeString($databox->get_viewname(), "form") . "</option>\n");
}
?>
<?php
foreach ($sbas_list as $databox) {
$selected = '';
print("\t\t\t\t<option value=\"" . $databox->get_sbas_id() . "\" $selected>" . p4string::MakeString($databox->get_viewname(), "form") . "</option>\n");
}
?>
</select>
&nbsp;
@@ -416,9 +416,9 @@ class task_period_outofdate extends task_abstract
<br/>
<br/>
<?php echo _('task::_common_:periodicite de la tache') ?>&nbsp;:&nbsp;
<?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_:minutes (unite temporelle)') ?><br/>
<?php echo _('task::_common_:minutes (unite temporelle)') ?><br/>
<br/>
<table id="OUTOFDATETAB" style="margin-right:10px; ">
@@ -427,7 +427,7 @@ class task_period_outofdate extends task_abstract
&nbsp;
</td>
<td style="width:20%;">
<?php echo _('task::outofdate:before') ?>&nbsp;
<?php echo _('task::outofdate:before') ?>&nbsp;
</td>
<td colspan="2" style="width:20%; white-space:nowrap;">
<select style="width:100px" name="field1" id="field1" onchange="chgxmlpopup(this, 'field1');"></select>
@@ -439,7 +439,7 @@ class task_period_outofdate extends task_abstract
<input name="fieldDv1" id="fieldDv1" onchange="chgxmltxt(this, 'fieldDv1');" type="text" style="width:30px" value="0"></input>&nbsp;<?php echo _('admin::taskoutofdate: days ') ?>
</td>
<td style="width:20%; padding-left:20px; padding-right:20px;">
<?php echo _('task::outofdate:between') ?>&nbsp;
<?php echo _('task::outofdate:between') ?>&nbsp;
</td>
<td colspan="2" style="width:20%; white-space:nowrap;">
<select style="width:100px" name="field2" id="field2" onchange="chgxmlpopup(this, 'field2');"></select>
@@ -451,12 +451,12 @@ class task_period_outofdate extends task_abstract
<input name="fieldDv2" id="fieldDv2" onchange="chgxmltxt(this, 'fieldDv2');" type="text" style="width:30px" value="0"></input>&nbsp;<?php echo _('admin::taskoutofdate: days ') ?>
</td>
<td style="width:20%;">
<?php echo _('task::outofdate:after') ?>&nbsp;
<?php echo _('task::outofdate:after') ?>&nbsp;
</td>
</tr>
<tr>
<td style="white-space:nowrap;">
<?php echo _('task::outofdate:coll.') ?>&nbsp;:
<?php echo _('task::outofdate:coll.') ?>&nbsp;:
</td>
<td colspan="2" style="border-right:1px solid #000000">
<select name="coll0" id="coll0" onchange="chgxmlpopup(this, 'coll0');"></select>
@@ -470,7 +470,7 @@ class task_period_outofdate extends task_abstract
</tr>
<tr>
<td style="white-space:nowrap;">
<?php echo _('task::outofdate:status') ?>&nbsp;:<br/>
<?php echo _('task::outofdate:status') ?>&nbsp;:<br/>
</td>
<td colspan="2" style="border-right:1px solid #000000">
<select name="status0" id="status0" onchange="chgxmlpopup(this, 'status0');"></select>

View File

@@ -215,104 +215,104 @@ class task_period_subdef extends task_databoxAbstract
?>
<form name="graphicForm" onsubmit="return(false);" method="post">
<br/>
<?php echo _('task::_common_:periodicite de la tache') ?>&nbsp;:&nbsp;
<?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/>
<?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="">'); ?>
<?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;
<?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();
<?php
$out = ob_get_clean();
return $out;
}
return $out;
}
protected function flush_records_sbas()
{
$sql = implode(', ', $this->recs_to_write);
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)
));
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
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());
}
$stmt = $connbas->prepare($sql);
$stmt->execute();
$stmt->closeCursor();
} catch (Exception $e) {
$this->log($e->getMessage());
}
$this->recs_to_write = array();
return $this;
}
$this->recs_to_write = array();
public function retrieve_sbas_content(databox $databox)
{
$connbas = $databox->get_connection();
return $this;
}
$sql = 'SELECT coll_id, record_id
public function retrieve_sbas_content(databox $databox)
{
$connbas = $databox->get_connection();
$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(
"Generate subdefs for : sbas_id %s / record %s "
, $this->sbas_id, $record_id));
$record = new record_adapter($this->sbas_id, $record_id);
$record->generate_subdefs($databox, null);
$this->recs_to_write[] = $record->get_record_id();
if (count($this->recs_to_write) >= $this->record_buffer_size) {
$this->flush_records_sbas();
}
unset($record);
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);
return $this;
}
$record->generate_subdefs($databox, null);
$this->recs_to_write[] = $record->get_record_id();
if (count($this->recs_to_write) >= $this->record_buffer_size) {
$this->flush_records_sbas();
}
unset($record);
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

@@ -115,7 +115,7 @@ class task_period_workflow01 extends task_databoxAbstract
parent.chgsbas(<?php echo $form ?>[pops[j].name]);
}
<?php echo $form ?>.period.value = "<?php echo p4string::MakeString($sxml->period, "js", '"') ?>";
parent.calccmd();
parent.calccmd();
</script>
<?php
return("");
@@ -305,16 +305,16 @@ class task_period_workflow01 extends task_databoxAbstract
ob_start();
?>
<form name="graphicForm" onsubmit="return(false);" method="post">
<?php echo _('task::outofdate:Base') ?>&nbsp;:&nbsp;
<?php echo _('task::outofdate:Base') ?>&nbsp;:&nbsp;
<select onchange="chgsbas(this);setDirty();" name="sbas_id">
<option value="">...</option>
<?php
$sbas_ids = $user->ACL()->get_granted_sbas(array('bas_manage'));
foreach ($sbas_ids as $databox) {
print('<option value="' . $databox->get_sbas_id() . '">' . p4string::MakeString($databox->get_viewname(), "form") . '</option>');
}
?>
<?php
$sbas_ids = $user->ACL()->get_granted_sbas(array('bas_manage'));
foreach ($sbas_ids as $databox) {
print('<option value="' . $databox->get_sbas_id() . '">' . p4string::MakeString($databox->get_viewname(), "form") . '</option>');
}
?>
</select>
&nbsp;
@@ -322,9 +322,9 @@ class task_period_workflow01 extends task_databoxAbstract
<br/>
<br/>
<?php echo _('task::_common_:periodicite de la tache') ?>&nbsp;:&nbsp;
<?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_:minutes (unite temporelle)') ?><br/>
<?php echo _('task::_common_:minutes (unite temporelle)') ?><br/>
<br/>
<table id="OUTOFDATETAB" style="margin-right:10px; ">

View File

@@ -183,188 +183,188 @@ class task_period_writemeta extends task_databoxAbstract
?>
<form name="graphicForm" onsubmit="return(false);" method="post">
<br/>
<?php echo _('task::_common_:periodicite de la tache') ?>&nbsp;:&nbsp;
<?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/>
<?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') ?>
<?php echo _('task::writemeta:effacer les metadatas non presentes dans la structure') ?>
<br/>
<br/>
<?php echo _('task::_common_:relancer la tache tous les') ?>&nbsp;
<?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;
<?php
}
$out = ob_get_clean();
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();
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) . ' ';
}
} 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();
return $this;
}
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();
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) . ' ';
}
} 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();
return $this;
}
}