NEW A module can add its entries into cron module.
This commit is contained in:
parent
047390f661
commit
5edef2f02f
@ -167,6 +167,12 @@ class modMyModule extends DolibarrModules
|
|||||||
// Example:
|
// Example:
|
||||||
//$this->boxes=array(array(0=>array('file'=>'myboxa.php','note'=>'','enabledbydefaulton'=>'Home'),1=>array('file'=>'myboxb.php','note'=>''),2=>array('file'=>'myboxc.php','note'=>'')););
|
//$this->boxes=array(array(0=>array('file'=>'myboxa.php','note'=>'','enabledbydefaulton'=>'Home'),1=>array('file'=>'myboxb.php','note'=>''),2=>array('file'=>'myboxc.php','note'=>'')););
|
||||||
|
|
||||||
|
// Cronjobs
|
||||||
|
$this->cronjobs = array(); // List of cron jobs entries to add
|
||||||
|
// Example: $this->cronjobs=array(0=>array('label'=>'My label', 'jobtype'=>'method', 'class'=>'MyClass', 'method'=>'myMethod', 'parameters'=>'', 'comment'=>'Comment', 'frequency'=>3600, 'unitfrequency'=>3600),
|
||||||
|
// 1=>array('label'=>'My label', 'jobtype'=>'command', 'command'=>'', 'parameters'=>'', 'comment'=>'Comment', 'frequency'=>3600, 'unitfrequency'=>3600)
|
||||||
|
// );
|
||||||
|
|
||||||
// Permissions
|
// Permissions
|
||||||
$this->rights = array(); // Permission array used by this module
|
$this->rights = array(); // Permission array used by this module
|
||||||
$r=0;
|
$r=0;
|
||||||
@ -180,7 +186,6 @@ class modMyModule extends DolibarrModules
|
|||||||
// $this->rights[$r][5] = 'level2'; // In php code, permission will be checked by test if ($user->rights->permkey->level1->level2)
|
// $this->rights[$r][5] = 'level2'; // In php code, permission will be checked by test if ($user->rights->permkey->level1->level2)
|
||||||
// $r++;
|
// $r++;
|
||||||
|
|
||||||
|
|
||||||
// Main menu entries
|
// Main menu entries
|
||||||
$this->menu = array(); // List of menus to add
|
$this->menu = array(); // List of menus to add
|
||||||
$r=0;
|
$r=0;
|
||||||
|
|||||||
@ -5,7 +5,7 @@
|
|||||||
* Copyright (C) 2004 Eric Seigne <eric.seigne@ryxeo.com>
|
* Copyright (C) 2004 Eric Seigne <eric.seigne@ryxeo.com>
|
||||||
* Copyright (C) 2005-2012 Regis Houssin <regis.houssin@capnetworks.com>
|
* Copyright (C) 2005-2012 Regis Houssin <regis.houssin@capnetworks.com>
|
||||||
* Copyright (C) 2011 Juanjo Menent <jmenent@2byte.es>
|
* Copyright (C) 2011 Juanjo Menent <jmenent@2byte.es>
|
||||||
* Copyright (C) 2015 Jean-François Ferry <jfefe@aternatik.fr>
|
* Copyright (C) 2015 Jean-François Ferry <jfefe@aternatik.fr>
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* This program is free software; you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
|||||||
@ -833,6 +833,7 @@ function unActivateModule($value, $requiredby=1)
|
|||||||
{
|
{
|
||||||
$objMod = new $modName($db);
|
$objMod = new $modName($db);
|
||||||
$result=$objMod->remove();
|
$result=$objMod->remove();
|
||||||
|
if ($result <= 0) $ret=$objMod->error;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -846,7 +847,7 @@ function unActivateModule($value, $requiredby=1)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Desactivation des modules qui dependent de lui
|
// Desactivation des modules qui dependent de lui
|
||||||
if ($requiredby)
|
if (! $ret && $requiredby)
|
||||||
{
|
{
|
||||||
$countrb=count($objMod->requiredby);
|
$countrb=count($objMod->requiredby);
|
||||||
for ($i = 0; $i < $countrb; $i++)
|
for ($i = 0; $i < $countrb; $i++)
|
||||||
|
|||||||
@ -60,6 +60,11 @@ abstract class DolibarrModules
|
|||||||
*/
|
*/
|
||||||
public $const = array();
|
public $const = array();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var array Module cron jobs entries
|
||||||
|
*/
|
||||||
|
public $cronjobs = array();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var array Module access rights
|
* @var array Module access rights
|
||||||
*/
|
*/
|
||||||
@ -209,18 +214,21 @@ abstract class DolibarrModules
|
|||||||
// Insert activation module constant
|
// Insert activation module constant
|
||||||
if (! $err) $err+=$this->_active();
|
if (! $err) $err+=$this->_active();
|
||||||
|
|
||||||
// Insert new pages for tabs into llx_const
|
// Insert new pages for tabs (into llx_const)
|
||||||
if (! $err) $err+=$this->insert_tabs();
|
if (! $err) $err+=$this->insert_tabs();
|
||||||
|
|
||||||
// Insert activation of module's parts
|
// Insert activation of module's parts
|
||||||
if (! $err) $err+=$this->insert_module_parts();
|
if (! $err) $err+=$this->insert_module_parts();
|
||||||
|
|
||||||
// Insert constant defined by modules, into llx_const
|
// Insert constant defined by modules (into llx_const)
|
||||||
if (! $err) $err+=$this->insert_const();
|
if (! $err) $err+=$this->insert_const();
|
||||||
|
|
||||||
// Insert boxes def into llx_boxes_def and boxes setup into llx_boxes
|
// Insert boxes def into llx_boxes_def and boxes setup (into llx_boxes)
|
||||||
if (! $err && ! preg_match('/noboxes/',$options)) $err+=$this->insert_boxes($options);
|
if (! $err && ! preg_match('/noboxes/',$options)) $err+=$this->insert_boxes($options);
|
||||||
|
|
||||||
|
// Insert cron job entries (entry in llx_cronjobs)
|
||||||
|
if (! $err) $err+=$this->insert_cronjobs();
|
||||||
|
|
||||||
// Insert permission definitions of module into llx_rights_def. If user is admin, grant this permission to user.
|
// Insert permission definitions of module into llx_rights_def. If user is admin, grant this permission to user.
|
||||||
if (! $err) $err+=$this->insert_permissions(1);
|
if (! $err) $err+=$this->insert_permissions(1);
|
||||||
|
|
||||||
@ -307,6 +315,9 @@ abstract class DolibarrModules
|
|||||||
// Remove list of module's available boxes (entry in llx_boxes)
|
// Remove list of module's available boxes (entry in llx_boxes)
|
||||||
if (! $err && ! preg_match('/(newboxdefonly|noboxes)/',$options)) $err+=$this->delete_boxes(); // We don't have to delete if option ask to keep boxes safe or ask to add new box def only
|
if (! $err && ! preg_match('/(newboxdefonly|noboxes)/',$options)) $err+=$this->delete_boxes(); // We don't have to delete if option ask to keep boxes safe or ask to add new box def only
|
||||||
|
|
||||||
|
// Remove list of module's cron job entries (entry in llx_cronjobs)
|
||||||
|
if (! $err) $err+=$this->delete_cronjobs();
|
||||||
|
|
||||||
// Remove module's permissions from list of available permissions (entries in llx_rights_def)
|
// Remove module's permissions from list of available permissions (entries in llx_rights_def)
|
||||||
if (! $err) $err+=$this->delete_permissions();
|
if (! $err) $err+=$this->delete_permissions();
|
||||||
|
|
||||||
@ -823,6 +834,130 @@ abstract class DolibarrModules
|
|||||||
return $err;
|
return $err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds cronjobs
|
||||||
|
*
|
||||||
|
* @return int Error count (0 if OK)
|
||||||
|
*/
|
||||||
|
function insert_cronjobs()
|
||||||
|
{
|
||||||
|
require_once DOL_DOCUMENT_ROOT . '/core/class/infobox.class.php';
|
||||||
|
|
||||||
|
global $conf;
|
||||||
|
|
||||||
|
$err=0;
|
||||||
|
|
||||||
|
if (is_array($this->cronjobs))
|
||||||
|
{
|
||||||
|
foreach ($this->cronjobs as $key => $value)
|
||||||
|
{
|
||||||
|
$label = isset($this->cronjobs[$key]['label'])?$this->cronjobs[$key]['label']:'';
|
||||||
|
$jobtype = isset($this->cronjobs[$key]['jobtype'])?$this->cronjobs[$key]['jobtype']:'';
|
||||||
|
$class = isset($this->cronjobs[$key]['class'])?$this->cronjobs[$key]['class']:'';
|
||||||
|
$method = isset($this->cronjobs[$key]['method'])?$this->cronjobs[$key]['method']:'';
|
||||||
|
$command = isset($this->cronjobs[$key]['command'])?$this->cronjobs[$key]['command']:'';
|
||||||
|
$parameters = isset($this->cronjobs[$key]['parameters'])?$this->cronjobs[$key]['parameters']:'';
|
||||||
|
$comment = isset($this->cronjobs[$key]['comment'])?$this->cronjobs[$key]['comment']:'';
|
||||||
|
$frequency = isset($this->cronjobs[$key]['frequency'])?$this->cronjobs[$key]['frequency']:'';
|
||||||
|
$unitfrequency = isset($this->cronjobs[$key]['unitfrequency'])?$this->cronjobs[$key]['unitfrequency']:'';
|
||||||
|
|
||||||
|
// Search if boxes def already present
|
||||||
|
$sql = "SELECT count(*) as nb FROM ".MAIN_DB_PREFIX."cronjob";
|
||||||
|
$sql.= " WHERE module_name = '".$this->db->escape($this->rights_class)."'";
|
||||||
|
if ($class) $sql.= " AND classesname = '".$this->db->escape($class)."'";
|
||||||
|
if ($method) $sql.= " AND methodename = '".$this->db->escape($method)."'";
|
||||||
|
if ($command) $sql.= " AND command = '".$this->db->escape($command)."'";
|
||||||
|
$sql.= " AND entity = ".$conf->entity;
|
||||||
|
|
||||||
|
$now=dol_now();
|
||||||
|
|
||||||
|
dol_syslog(get_class($this)."::insert_cronjobs", LOG_DEBUG);
|
||||||
|
$result=$this->db->query($sql);
|
||||||
|
if ($result)
|
||||||
|
{
|
||||||
|
$obj = $this->db->fetch_object($result);
|
||||||
|
if ($obj->nb == 0)
|
||||||
|
{
|
||||||
|
$this->db->begin();
|
||||||
|
|
||||||
|
if (! $err)
|
||||||
|
{
|
||||||
|
$sql = "INSERT INTO ".MAIN_DB_PREFIX."cronjob (module_name, datec, label, jobtype, classesname, methodename, command, params, note, frequency, unitfrequency, entity)";
|
||||||
|
$sql.= " VALUES (";
|
||||||
|
$sql.= "'".$this->db->escape($this->rights_class)."', ";
|
||||||
|
$sql.= "'".$this->db->idate($now)."', ";
|
||||||
|
$sql.= "'".$this->db->escape($label)."', ";
|
||||||
|
$sql.= "'".$this->db->escape($jobtype)."', ";
|
||||||
|
$sql.= ($class?"'".$this->db->escape($class)."'":"null").",";
|
||||||
|
$sql.= ($method?"'".$this->db->escape($method)."'":"null").",";
|
||||||
|
$sql.= ($command?"'".$this->db->escape($command)."'":"null").",";
|
||||||
|
$sql.= ($parameters?"'".$this->db->escape($parameters)."'":"null").",";
|
||||||
|
$sql.= ($comment?"'".$this->db->escape($comment)."'":"null").",";
|
||||||
|
$sql.= "'".$this->db->escape($frequency)."', ";
|
||||||
|
$sql.= "'".$this->db->escape($unitfrequency)."', ";
|
||||||
|
$sql.= $conf->entity;
|
||||||
|
$sql.= ")";
|
||||||
|
print $sql;
|
||||||
|
|
||||||
|
dol_syslog(get_class($this)."::insert_cronjobs", LOG_DEBUG);
|
||||||
|
$resql=$this->db->query($sql);
|
||||||
|
if (! $resql) $err++;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! $err)
|
||||||
|
{
|
||||||
|
$this->db->commit();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$this->error=$this->db->lasterror();
|
||||||
|
$this->db->rollback();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// else box already registered into database
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$this->error=$this->db->lasterror();
|
||||||
|
$err++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $err;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes boxes
|
||||||
|
*
|
||||||
|
* @return int Error count (0 if OK)
|
||||||
|
*/
|
||||||
|
function delete_cronjobs()
|
||||||
|
{
|
||||||
|
global $conf;
|
||||||
|
|
||||||
|
$err=0;
|
||||||
|
|
||||||
|
if (is_array($this->cronjobs))
|
||||||
|
{
|
||||||
|
$sql = "DELETE FROM ".MAIN_DB_PREFIX."cronjob";
|
||||||
|
$sql.= " WHERE module_name = '".$this->db->escape($this->rights_class)."'";
|
||||||
|
$sql.= " AND entity = ".$conf->entity;
|
||||||
|
|
||||||
|
dol_syslog(get_class($this)."::delete_cronjobs", LOG_DEBUG);
|
||||||
|
$resql=$this->db->query($sql);
|
||||||
|
if (! $resql)
|
||||||
|
{
|
||||||
|
$this->error=$this->db->lasterror();
|
||||||
|
$err++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $err;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Removes tabs
|
* Removes tabs
|
||||||
*
|
*
|
||||||
|
|||||||
@ -99,6 +99,13 @@ class modGravatar extends DolibarrModules
|
|||||||
//$r++;
|
//$r++;
|
||||||
|
|
||||||
|
|
||||||
|
// Cronjobs
|
||||||
|
$this->cronjobs = array(); // List of cron jobs entries to add
|
||||||
|
// Example: $this->cronjobs=array(0=>array('label'=>'My label', 'jobtype'=>'method', 'class'=>'MyClass', 'method'=>'myMethod', 'parameters'=>'', 'comment'=>'Comment', 'frequency'=>3600, 'unitfrequency'=>3600),
|
||||||
|
// 1=>array('label'=>'My label', 'jobtype'=>'command', 'command'=>'', 'parameters'=>'', 'comment'=>'Comment', 'frequency'=>3600, 'unitfrequency'=>3600)
|
||||||
|
// );
|
||||||
|
$r=0;
|
||||||
|
|
||||||
// Permissions
|
// Permissions
|
||||||
$this->rights = array(); // Permission array used by this module
|
$this->rights = array(); // Permission array used by this module
|
||||||
$r=0;
|
$r=0;
|
||||||
|
|||||||
@ -32,7 +32,9 @@ insert into llx_c_tva(rowid,fk_pays,taux,recuperableonly,note,active) values ( 2
|
|||||||
ALTER TABLE llx_societe_rib ADD COLUMN rum varchar(32) after default_rib;
|
ALTER TABLE llx_societe_rib ADD COLUMN rum varchar(32) after default_rib;
|
||||||
ALTER TABLE llx_societe_rib ADD COLUMN frstrecur varchar(16) default 'FRST' after rum;
|
ALTER TABLE llx_societe_rib ADD COLUMN frstrecur varchar(16) default 'FRST' after rum;
|
||||||
|
|
||||||
|
ALTER TABLE llx_cronjob ADD COLUMN entity integer DEFAULT 0;
|
||||||
|
ALTER TABLE llx_cronjob MODIFY COLUMN params text NULL;
|
||||||
|
|
||||||
-- Loan
|
-- Loan
|
||||||
create table llx_loan
|
create table llx_loan
|
||||||
(
|
(
|
||||||
|
|||||||
@ -29,7 +29,7 @@ CREATE TABLE llx_cronjob
|
|||||||
classesname varchar(255),
|
classesname varchar(255),
|
||||||
objectname varchar(255),
|
objectname varchar(255),
|
||||||
methodename varchar(255),
|
methodename varchar(255),
|
||||||
params text NOT NULL,
|
params text,
|
||||||
md5params varchar(32),
|
md5params varchar(32),
|
||||||
module_name varchar(255),
|
module_name varchar(255),
|
||||||
priority integer DEFAULT 0,
|
priority integer DEFAULT 0,
|
||||||
@ -47,5 +47,6 @@ CREATE TABLE llx_cronjob
|
|||||||
fk_user_author integer DEFAULT NULL,
|
fk_user_author integer DEFAULT NULL,
|
||||||
fk_user_mod integer DEFAULT NULL,
|
fk_user_mod integer DEFAULT NULL,
|
||||||
note text,
|
note text,
|
||||||
libname varchar(255)
|
libname varchar(255),
|
||||||
|
entity integer DEFAULT 0
|
||||||
)ENGINE=innodb;
|
)ENGINE=innodb;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user