mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-11 03:53:13 +00:00
CS & remove mysql-only sql
This commit is contained in:
@@ -297,9 +297,10 @@ abstract class task_abstract
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* 'active' means 'auto-start when scheduler starts'
|
||||||
*
|
*
|
||||||
* @return boolean
|
* @return boolean
|
||||||
* 'active' means 'auto-start when scheduler starts'
|
*
|
||||||
*/
|
*/
|
||||||
public function isActive()
|
public function isActive()
|
||||||
{
|
{
|
||||||
@@ -339,7 +340,7 @@ abstract class task_abstract
|
|||||||
|
|
||||||
$this->running = false;
|
$this->running = false;
|
||||||
|
|
||||||
return('');
|
return '';
|
||||||
}
|
}
|
||||||
$sql = 'SELECT crashed, pid, status, active, settings, name, completed, runner
|
$sql = 'SELECT crashed, pid, status, active, settings, name, completed, runner
|
||||||
FROM task2 WHERE task_id = :taskid';
|
FROM task2 WHERE task_id = :taskid';
|
||||||
@@ -466,8 +467,8 @@ abstract class task_abstract
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @return variant
|
* @return null|integer
|
||||||
* pid (int) of the task, or NULL if the pid file
|
* pid (int) of the task
|
||||||
* NULL : the pid file is not locked (task no running)
|
* NULL : the pid file is not locked (task no running)
|
||||||
*/
|
*/
|
||||||
public function getPID()
|
public function getPID()
|
||||||
@@ -491,9 +492,9 @@ abstract class task_abstract
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* @param boolean $stat
|
|
||||||
* set to false to ask the task to quit its loop
|
* set to false to ask the task to quit its loop
|
||||||
|
* @param boolean $stat
|
||||||
|
*
|
||||||
*/
|
*/
|
||||||
public function setRunning($stat)
|
public function setRunning($stat)
|
||||||
{
|
{
|
||||||
@@ -546,7 +547,7 @@ abstract class task_abstract
|
|||||||
$lockdir = $core->getRegistry()->get('GV_RootPath') . 'tmp/locks/';
|
$lockdir = $core->getRegistry()->get('GV_RootPath') . 'tmp/locks/';
|
||||||
$lockfilePath = ($lockdir . 'task_' . $this->getID() . '.lock');
|
$lockfilePath = ($lockdir . 'task_' . $this->getID() . '.lock');
|
||||||
|
|
||||||
return($lockfilePath);
|
return $lockfilePath;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -836,7 +837,7 @@ abstract class task_abstract
|
|||||||
$t .= "\t" . $n . $v["usage"] . "\n";
|
$t .= "\t" . $n . $v["usage"] . "\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
return($t);
|
return $t;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -22,7 +22,7 @@ class task_period_workflow02 extends task_appboxAbstract
|
|||||||
*/
|
*/
|
||||||
public function getName()
|
public function getName()
|
||||||
{
|
{
|
||||||
return(_("task::workflow02"));
|
return _("task::workflow02");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -34,9 +34,12 @@ class task_period_workflow02 extends task_appboxAbstract
|
|||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
// ====================================================================
|
/**
|
||||||
// graphic2xml : must return the xml (text) version of the form
|
* return the xml (text) version of the form filled by the gui
|
||||||
// ====================================================================
|
*
|
||||||
|
* @param string $oldxml
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
public function graphic2xml($oldxml)
|
public function graphic2xml($oldxml)
|
||||||
{
|
{
|
||||||
$request = http_request::getInstance();
|
$request = http_request::getInstance();
|
||||||
@@ -58,16 +61,16 @@ class task_period_workflow02 extends task_appboxAbstract
|
|||||||
$pname = substr($pname, 4);
|
$pname = substr($pname, 4);
|
||||||
$pvalue = $parm2[$pname];
|
$pvalue = $parm2[$pname];
|
||||||
if (($ns = $dom->getElementsByTagName($pname)->item(0))) {
|
if (($ns = $dom->getElementsByTagName($pname)->item(0))) {
|
||||||
// le champ existait dans le xml, on supprime son ancienne valeur (tout le contenu)
|
// field did exists, remove thevalue
|
||||||
while (($n = $ns->firstChild))
|
while (($n = $ns->firstChild))
|
||||||
$ns->removeChild($n);
|
$ns->removeChild($n);
|
||||||
} else {
|
} else {
|
||||||
// le champ n'existait pas dans le xml, on le cr<63>e
|
// field did not exists, create it
|
||||||
$dom->documentElement->appendChild($dom->createTextNode("\t"));
|
$dom->documentElement->appendChild($dom->createTextNode("\t"));
|
||||||
$ns = $dom->documentElement->appendChild($dom->createElement($pname));
|
$ns = $dom->documentElement->appendChild($dom->createElement($pname));
|
||||||
$dom->documentElement->appendChild($dom->createTextNode("\n"));
|
$dom->documentElement->appendChild($dom->createTextNode("\n"));
|
||||||
}
|
}
|
||||||
// on fixe sa valeur
|
// set the value
|
||||||
switch ($ptype) {
|
switch ($ptype) {
|
||||||
case "str":
|
case "str":
|
||||||
$ns->appendChild($dom->createTextNode($pvalue));
|
$ns->appendChild($dom->createTextNode($pvalue));
|
||||||
@@ -79,12 +82,16 @@ class task_period_workflow02 extends task_appboxAbstract
|
|||||||
$xmlchanged = true;
|
$xmlchanged = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return($dom->saveXML());
|
return $dom->saveXML();
|
||||||
}
|
}
|
||||||
|
|
||||||
// ====================================================================
|
/**
|
||||||
// xml2graphic : must fill the graphic form (using js) from xml
|
* must fill the gui (using js) from xml
|
||||||
// ====================================================================
|
*
|
||||||
|
* @param string $xml
|
||||||
|
* @param form-object $form
|
||||||
|
* @return string "" or error message
|
||||||
|
*/
|
||||||
public function xml2graphic($xml, $form)
|
public function xml2graphic($xml, $form)
|
||||||
{
|
{
|
||||||
if (($sxml = simplexml_load_string($xml))) { // in fact XML IS always valid here...
|
if (($sxml = simplexml_load_string($xml))) { // in fact XML IS always valid here...
|
||||||
@@ -190,17 +197,17 @@ class task_period_workflow02 extends task_appboxAbstract
|
|||||||
|
|
||||||
</script>
|
</script>
|
||||||
<?php
|
<?php
|
||||||
return("");
|
return "";
|
||||||
}
|
}
|
||||||
else { // ... so we NEVER come here
|
else { // ... so we NEVER come here
|
||||||
// bad xml
|
// bad xml
|
||||||
return("BAD XML");
|
return "BAD XML";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ====================================================================
|
/**
|
||||||
// printInterfaceHEAD() :
|
* PRINT head for the gui
|
||||||
// ====================================================================
|
*/
|
||||||
public function printInterfaceHEAD()
|
public function printInterfaceHEAD()
|
||||||
{
|
{
|
||||||
?>
|
?>
|
||||||
@@ -256,9 +263,9 @@ class task_period_workflow02 extends task_appboxAbstract
|
|||||||
<?php
|
<?php
|
||||||
}
|
}
|
||||||
|
|
||||||
// ====================================================================
|
/**
|
||||||
// printInterfaceJS() : generer le code js de l'interface 'graphic view'
|
* PRINT js of the gui
|
||||||
// ====================================================================
|
*/
|
||||||
public function printInterfaceJS()
|
public function printInterfaceJS()
|
||||||
{
|
{
|
||||||
?>
|
?>
|
||||||
@@ -300,17 +307,19 @@ class task_period_workflow02 extends task_appboxAbstract
|
|||||||
<?php
|
<?php
|
||||||
}
|
}
|
||||||
|
|
||||||
// ====================================================================
|
/**
|
||||||
// getInterfaceHTML(..) : retourner l'interface 'graphic view' !! EN UTF-8 !!
|
* RETURN the html gui
|
||||||
// ====================================================================
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
public function getInterfaceHTML()
|
public function getInterfaceHTML()
|
||||||
{
|
{
|
||||||
ob_start();
|
ob_start();
|
||||||
?>
|
?>
|
||||||
<form name="graphicForm" onsubmit="return(false);" method="post">
|
<form name="graphicForm" onsubmit="return(false);" method="post">
|
||||||
Périodicité :
|
<?php echo _('task::_common_:periodicite de la tache') ?>
|
||||||
<input type="text" name="period" style="width:40px;" onchange="chgxmltxt(this, 'period');" value="" />
|
<input type="text" name="period" style="width:40px;" onchange="chgxmltxt(this, 'period');" value="" />
|
||||||
seconds
|
<?php echo _('task::_common_:secondes (unite temporelle)') ?>
|
||||||
|
|
||||||
<input type="checkbox" name="logsql" onchange="chgxmlck(this, 'logsql');" /> log changes
|
<input type="checkbox" name="logsql" onchange="chgxmlck(this, 'logsql');" /> log changes
|
||||||
</form>
|
</form>
|
||||||
@@ -320,18 +329,26 @@ class task_period_workflow02 extends task_appboxAbstract
|
|||||||
<?php
|
<?php
|
||||||
return ob_get_clean();
|
return ob_get_clean();
|
||||||
}
|
}
|
||||||
// ======================================================================================================
|
/**
|
||||||
// ===== run() : le code d'<27>x<EFBFBD>cution de la t<>che proprement dite
|
*
|
||||||
// ======================================================================================================
|
* retrieveContent & processOneContent : work done by the task
|
||||||
|
*/
|
||||||
|
private $sxTaskSettings = null; // settings in simplexml
|
||||||
|
|
||||||
private $sxTaskSettings = null; // les settings de la tache en simplexml
|
/**
|
||||||
|
* return array of records to work on, from sql generated by 'from' clause
|
||||||
|
*
|
||||||
|
* @param appbox $appbox
|
||||||
|
* @return array()
|
||||||
|
*/
|
||||||
|
|
||||||
protected function retrieveContent(appbox $appbox)
|
protected function retrieveContent(appbox $appbox)
|
||||||
{
|
{
|
||||||
$this->maxrecs = 1000;
|
$this->maxrecs = 1000;
|
||||||
$this->sxTaskSettings = @simplexml_load_string($this->getSettings());
|
$this->sxTaskSettings = @simplexml_load_string($this->getSettings());
|
||||||
if ( ! $this->sxTaskSettings)
|
if ( ! $this->sxTaskSettings) {
|
||||||
return array();
|
return array();
|
||||||
|
}
|
||||||
|
|
||||||
$ret = array();
|
$ret = array();
|
||||||
|
|
||||||
@@ -401,6 +418,13 @@ class task_period_workflow02 extends task_appboxAbstract
|
|||||||
return $ret;
|
return $ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* work on ONE record
|
||||||
|
*
|
||||||
|
* @param appbox $appbox
|
||||||
|
* @param array $row
|
||||||
|
* @return \task_period_workflow02
|
||||||
|
*/
|
||||||
protected function processOneContent(appbox $appbox, Array $row)
|
protected function processOneContent(appbox $appbox, Array $row)
|
||||||
{
|
{
|
||||||
$logsql = (int) ($this->sxTaskSettings->logsql) > 0;
|
$logsql = (int) ($this->sxTaskSettings->logsql) > 0;
|
||||||
@@ -454,11 +478,25 @@ class task_period_workflow02 extends task_appboxAbstract
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* all work done on processOneContent, so nothing to do here
|
||||||
|
*
|
||||||
|
* @param appbox $appbox
|
||||||
|
* @param array $row
|
||||||
|
* @return \task_period_workflow02
|
||||||
|
*/
|
||||||
protected function postProcessOneContent(appbox $appbox, Array $row)
|
protected function postProcessOneContent(appbox $appbox, Array $row)
|
||||||
{
|
{
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* compute sql for a task (<task> entry in settings)
|
||||||
|
*
|
||||||
|
* @param simplexml $sxtask
|
||||||
|
* @param boolean $playTest
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
private function calcSQL($sxtask, $playTest = false)
|
private function calcSQL($sxtask, $playTest = false)
|
||||||
{
|
{
|
||||||
$appbox = appbox::get_instance(\bootstrap::getCore());
|
$appbox = appbox::get_instance(\bootstrap::getCore());
|
||||||
@@ -501,12 +539,17 @@ class task_period_workflow02 extends task_appboxAbstract
|
|||||||
$ret['err_htmlencoded'] = htmlentities($ret['err']);
|
$ret['err_htmlencoded'] = htmlentities($ret['err']);
|
||||||
}
|
}
|
||||||
|
|
||||||
return($ret);
|
return $ret;
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
* compute entry for a UPDATE query
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* compute entry for a UPDATE query
|
||||||
|
*
|
||||||
|
* @param integer $sbas_id
|
||||||
|
* @param simplexml $sxtask
|
||||||
|
* @param boolean $playTest
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
private function calcUPDATE($sbas_id, &$sxtask, $playTest)
|
private function calcUPDATE($sbas_id, &$sxtask, $playTest)
|
||||||
{
|
{
|
||||||
$tws = array(); // NEGATION of updates, used to build the 'test' sql
|
$tws = array(); // NEGATION of updates, used to build the 'test' sql
|
||||||
@@ -541,10 +584,9 @@ class task_period_workflow02 extends task_appboxAbstract
|
|||||||
$where = '(' . implode(') AND (', $tw) . ')';
|
$where = '(' . implode(') AND (', $tw) . ')';
|
||||||
|
|
||||||
// build the TEST sql (select)
|
// build the TEST sql (select)
|
||||||
$sql_test = 'SELECT SQL_CALC_FOUND_ROWS record_id FROM record' . $join;
|
$sql_test = 'SELECT record_id FROM record' . $join;
|
||||||
if (count($tw) > 0)
|
if (count($tw) > 0)
|
||||||
$sql_test .= ' WHERE ' . ((count($tw) == 1) ? $tw[0] : '(' . implode(') AND (', $tw) . ')');
|
$sql_test .= ' WHERE ' . ((count($tw) == 1) ? $tw[0] : '(' . implode(') AND (', $tw) . ')');
|
||||||
$sql_test .= ' LIMIT 10';
|
|
||||||
|
|
||||||
// build the real sql (select)
|
// build the real sql (select)
|
||||||
$sql = 'SELECT record_id FROM record' . $join;
|
$sql = 'SELECT record_id FROM record' . $join;
|
||||||
@@ -568,12 +610,17 @@ class task_period_workflow02 extends task_appboxAbstract
|
|||||||
$ret['test']['result'] = $this->playTest($sbas_id, $sql_test);
|
$ret['test']['result'] = $this->playTest($sbas_id, $sql_test);
|
||||||
}
|
}
|
||||||
|
|
||||||
return($ret);
|
return $ret;
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
* compute entry for a DELETE task
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* compute entry for a DELETE task
|
||||||
|
*
|
||||||
|
* @param integer $sbas_id
|
||||||
|
* @param simplexml $sxtask
|
||||||
|
* @param boolean $playTest
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
private function calcDELETE($sbas_id, &$sxtask, $playTest)
|
private function calcDELETE($sbas_id, &$sxtask, $playTest)
|
||||||
{
|
{
|
||||||
// compute the 'where' clause
|
// compute the 'where' clause
|
||||||
@@ -607,14 +654,18 @@ class task_period_workflow02 extends task_appboxAbstract
|
|||||||
$ret['test']['result'] = $this->playTest($sbas_id, $sql_test);
|
$ret['test']['result'] = $this->playTest($sbas_id, $sql_test);
|
||||||
}
|
}
|
||||||
|
|
||||||
return($ret);
|
return $ret;
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
|
/**
|
||||||
* compute the 'where' clause
|
* compute the 'where' clause
|
||||||
* returns an array of clauses to be joined by 'and'
|
* returns an array of clauses to be joined by 'and'
|
||||||
* and a 'join' to needed tables
|
* and a 'join' to needed tables
|
||||||
|
*
|
||||||
|
* @param integer $sbas_id
|
||||||
|
* @param simplecms $sxtask
|
||||||
|
* @return array
|
||||||
*/
|
*/
|
||||||
|
|
||||||
private function calcWhere($sbas_id, &$sxtask)
|
private function calcWhere($sbas_id, &$sxtask)
|
||||||
{
|
{
|
||||||
$connbas = connection::getPDOConnection($sbas_id);
|
$connbas = connection::getPDOConnection($sbas_id);
|
||||||
@@ -709,20 +760,25 @@ class task_period_workflow02 extends task_appboxAbstract
|
|||||||
$where = '(' . implode(') AND (', $tw) . ')';
|
$where = '(' . implode(') AND (', $tw) . ')';
|
||||||
}
|
}
|
||||||
|
|
||||||
return(array($tw, $join));
|
return array($tw, $join);
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
* play a 'test' sql on sbas, return the number of records and the 10 first rids
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* play a 'test' sql on sbas, return the number of records and the 10 first rids
|
||||||
|
*
|
||||||
|
* @param integer $sbas_id
|
||||||
|
* @param string $sql
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
private function playTest($sbas_id, $sql)
|
private function playTest($sbas_id, $sql)
|
||||||
{
|
{
|
||||||
$connbas = connection::getPDOConnection($sbas_id);
|
$connbas = connection::getPDOConnection($sbas_id);
|
||||||
$result = array('rids' => array(), 'err' => '', 'n' => null);
|
$result = array('rids' => array(), 'err' => '', 'n' => null);
|
||||||
|
|
||||||
$stmt = $connbas->prepare($sql);
|
$result['n'] = $connbas->query('SELECT COUNT(*) AS n FROM (' . $sql . ') AS x')->fetchColumn();
|
||||||
|
|
||||||
|
$stmt = $connbas->prepare('SELECT record_id FROM (' . $sql . ') AS x LIMIT 10');
|
||||||
if ($stmt->execute(array())) {
|
if ($stmt->execute(array())) {
|
||||||
$result['n'] = $connbas->query("SELECT FOUND_ROWS()")->fetchColumn();
|
|
||||||
while (($row = $stmt->fetch(PDO::FETCH_ASSOC))) {
|
while (($row = $stmt->fetch(PDO::FETCH_ASSOC))) {
|
||||||
$result['rids'][] = $row['record_id'];
|
$result['rids'][] = $row['record_id'];
|
||||||
}
|
}
|
||||||
@@ -731,9 +787,12 @@ class task_period_workflow02 extends task_appboxAbstract
|
|||||||
$result['err'] = $connbas->last_error();
|
$result['err'] = $connbas->last_error();
|
||||||
}
|
}
|
||||||
|
|
||||||
return($result);
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* facility called by xhttp/jquery from interface for ex. when switching interface from gui<->xml
|
||||||
|
*/
|
||||||
public function facility()
|
public function facility()
|
||||||
{
|
{
|
||||||
$request = http_request::getInstance();
|
$request = http_request::getInstance();
|
||||||
@@ -765,7 +824,6 @@ class task_period_workflow02 extends task_appboxAbstract
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
print(json_encode($ret));
|
return json_encode($ret);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
?>
|
|
||||||
|
@@ -59,7 +59,6 @@ phrasea::headers();
|
|||||||
case 'XML2FORM':
|
case 'XML2FORM':
|
||||||
if ($ztask->hasInterfaceHTML()) {
|
if ($ztask->hasInterfaceHTML()) {
|
||||||
if ((simplexml_load_string($parm['txtareaxml']))) {
|
if ((simplexml_load_string($parm['txtareaxml']))) {
|
||||||
if (1) {
|
|
||||||
if (($msg = ($ztask->xml2graphic($parm['txtareaxml'], "parent.document.forms['graphicForm']"))) == "") {
|
if (($msg = ($ztask->xml2graphic($parm['txtareaxml'], "parent.document.forms['graphicForm']"))) == "") {
|
||||||
?>
|
?>
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
@@ -78,23 +77,13 @@ phrasea::headers();
|
|||||||
</script>
|
</script>
|
||||||
<?php
|
<?php
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
?>
|
|
||||||
<script type="text/javascript">
|
|
||||||
var d = parent.document;
|
|
||||||
d.getElementById('divGraph').style.display = "";
|
|
||||||
d.getElementById('divXml').style.display = "none";
|
|
||||||
d.getElementById('linkviewxml').className = "tabBack";
|
|
||||||
d.getElementById('linkviewgraph').className = "tabFront";
|
|
||||||
parent.jsTaskObj.currentView = "GRAPHIC";
|
|
||||||
</script>
|
|
||||||
<?php
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
?>
|
?>
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
if(confirm("<?php echo p4string::MakeString(_('admin::tasks: xml invalide, restaurer la version precedente ?'), 'js', '"') // xml invalide, restaurer la v. prec. ? ?>"))
|
if(confirm("<?php echo p4string::MakeString(_('admin::tasks: xml invalide, restaurer la version precedente ?'), 'js', '"') // xml invalide, restaurer la v. prec. ? ?>"))
|
||||||
|
{
|
||||||
parent.document.forms['fxml'].txtareaxml.value = parent.jsTaskObj.oldXML;
|
parent.document.forms['fxml'].txtareaxml.value = parent.jsTaskObj.oldXML;
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
<?php
|
<?php
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user