forked from extern/egroupware
modernized asyncservice class and renamed phpgw_async to egw_async
This commit is contained in:
parent
550ce8314d
commit
f2a058fccf
@ -15,12 +15,13 @@
|
|||||||
|
|
||||||
/* $Id$ */
|
/* $Id$ */
|
||||||
|
|
||||||
/*!
|
/**
|
||||||
@class asyncservice
|
* The class implements a general eGW service to execute callbacks at a given time.
|
||||||
@author Ralf Becker
|
*
|
||||||
@copyright GPL - GNU General Public License
|
* see http://www.egroupware.org/wiki/TimedAsyncServices
|
||||||
@abstract The class implements a general eGW service to execute callbacks at a given time.
|
*
|
||||||
@discussion see http://www.egroupware.org/wiki/TimedAsyncServices
|
* @author Ralf Becker
|
||||||
|
* @copyright GPL - GNU General Public License
|
||||||
*/
|
*/
|
||||||
class asyncservice
|
class asyncservice
|
||||||
{
|
{
|
||||||
@ -36,39 +37,37 @@
|
|||||||
var $php = '';
|
var $php = '';
|
||||||
var $crontab = '';
|
var $crontab = '';
|
||||||
var $db;
|
var $db;
|
||||||
var $db_table = 'phpgw_async';
|
var $db_table = 'egw_async';
|
||||||
var $debug = 0;
|
var $debug = 0;
|
||||||
|
|
||||||
/*!
|
/**
|
||||||
@function asyncservice
|
* constructor of the class
|
||||||
@abstract constructor of the class
|
|
||||||
*/
|
*/
|
||||||
function asyncservice()
|
function asyncservice()
|
||||||
{
|
{
|
||||||
$this->db = is_object($GLOBALS['phpgw']->db) ? $GLOBALS['phpgw']->db : $GLOBALS['phpgw_setup']->db;
|
$this->db = is_object($GLOBALS['egw']->db) ? $GLOBALS['egw']->db : $GLOBALS['phpgw_setup']->db;
|
||||||
$this->db->set_app('phpgwapi');
|
$this->db->set_app('phpgwapi');
|
||||||
|
|
||||||
$this->cronline = PHPGW_SERVER_ROOT . '/phpgwapi/cron/asyncservices.php '.$GLOBALS['phpgw_info']['user']['domain'];
|
$this->cronline = EGW_SERVER_ROOT . '/phpgwapi/cron/asyncservices.php '.$GLOBALS['egw_info']['user']['domain'];
|
||||||
|
|
||||||
$this->only_fallback = substr(php_uname(), 0, 7) == "Windows"; // atm cron-jobs dont work on win
|
$this->only_fallback = substr(php_uname(), 0, 7) == "Windows"; // atm cron-jobs dont work on win
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/**
|
||||||
@function set_timer
|
* calculates the next run of the timer and puts that with the rest of the data in the db for later execution.
|
||||||
@abstract calculates the next run of the timer and puts that with the rest of the data in the db for later execution.
|
*
|
||||||
@syntax set_timer($times,$id,$method,$data,$account_id=False)
|
* @param int/array $times unix timestamp or array('min','hour','dow','day','month','year') with execution time.
|
||||||
@param $times unix timestamp or array('min','hour','dow','day','month','year') with execution time.
|
* Repeated events are possible to shedule by setting the array only partly, eg.
|
||||||
Repeated events are possible to shedule by setting the array only partly, eg.
|
* array('day' => 1) for first day in each month 0am or array('min' => '* /5', 'hour' => '9-17')
|
||||||
array('day' => 1) for first day in each month 0am or array('min' => '* /5', 'hour' => '9-17')
|
* for every 5mins in the time from 9am to 5pm.
|
||||||
for every 5mins in the time from 9am to 5pm.
|
* @param string $id unique id to cancel the request later, if necessary. Should be in a form like
|
||||||
@param $id unique id to cancel the request later, if necessary. Should be in a form like
|
* eg. '<app><id>X' where id is the internal id of app and X might indicate the action.
|
||||||
eg. '<app><id>X' where id is the internal id of app and X might indicate the action.
|
* @param string $method Method to be called via ExecMethod($method,$data). $method has the form
|
||||||
@param $method Method to be called via ExecMethod($method,$data). $method has the form
|
* '<app>.<class>.<public function>'.
|
||||||
'<app>.<class>.<public function>'.
|
* @param mixed $data This data is passed back when the method is called. It might simply be an
|
||||||
@param $data This data is passed back when the method is called. It might simply be an
|
* integer id, but it can also be a complete array.
|
||||||
integer id, but it can also be a complete array.
|
* @param int $account_id account_id, under which the methode should be called or False for the actual user
|
||||||
@param $account_id account_id, under which the methode should be called or False for the actual user
|
* @return boolean False if $id already exists, else True
|
||||||
@result False if $id already exists, else True
|
|
||||||
*/
|
*/
|
||||||
function set_timer($times,$id,$method,$data,$account_id=False)
|
function set_timer($times,$id,$method,$data,$account_id=False)
|
||||||
{
|
{
|
||||||
@ -79,7 +78,7 @@
|
|||||||
}
|
}
|
||||||
if ($account_id === False)
|
if ($account_id === False)
|
||||||
{
|
{
|
||||||
$account_id = $GLOBALS['phpgw_info']['user']['account_id'];
|
$account_id = $GLOBALS['egw_info']['user']['account_id'];
|
||||||
}
|
}
|
||||||
$job = array(
|
$job = array(
|
||||||
'id' => $id,
|
'id' => $id,
|
||||||
@ -94,23 +93,22 @@
|
|||||||
return True;
|
return True;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/**
|
||||||
@function next_run
|
* calculates the next execution time for $times
|
||||||
@abstract calculates the next execution time for $times
|
*
|
||||||
@syntax next_run($times)
|
* @param int/array $times unix timestamp or array('year'=>$year,'month'=>$month,'dow'=>$dow,'day'=>$day,'hour'=>$hour,'min'=>$min)
|
||||||
@param $times unix timestamp or array('year'=>$year,'month'=>$month,'dow'=>$dow,'day'=>$day,'hour'=>$hour,'min'=>$min)
|
* with execution time. Repeated execution is possible to shedule by setting the array only partly,
|
||||||
with execution time. Repeated execution is possible to shedule by setting the array only partly,
|
* eg. array('day' => 1) for first day in each month 0am or array('min' => '/5', 'hour' => '9-17')
|
||||||
eg. array('day' => 1) for first day in each month 0am or array('min' => '/5', 'hour' => '9-17')
|
* for every 5mins in the time from 9am to 5pm. All not set units before the smallest one set,
|
||||||
for every 5mins in the time from 9am to 5pm. All not set units before the smallest one set,
|
* are taken into account as every possible value, all after as the smallest possible value.
|
||||||
are taken into account as every possible value, all after as the smallest possible value.
|
* @param boolean $debug if True some debug-messages about syntax-errors in $times are echoed
|
||||||
@param $debug if True some debug-messages about syntax-errors in $times are echoed
|
* @return int a unix timestamp of the next execution time or False if no more executions
|
||||||
@result a unix timestamp of the next execution time or False if no more executions
|
|
||||||
*/
|
*/
|
||||||
function next_run($times,$debug=False)
|
function next_run($times,$debug=False)
|
||||||
{
|
{
|
||||||
if ($this->debug)
|
if ($this->debug)
|
||||||
{
|
{
|
||||||
echo "<p>next_run("; print_r($times); ",'$debug')</p>\n";
|
echo "<p>next_run("; print_r($times); echo ",'$debug')</p>\n";
|
||||||
$debug = True; // enable syntax-error messages too
|
$debug = True; // enable syntax-error messages too
|
||||||
}
|
}
|
||||||
$now = time();
|
$now = time();
|
||||||
@ -313,25 +311,24 @@
|
|||||||
return mktime($found['hour'],$found['min'],0,$found['month'],$found['day'],$found['year']);
|
return mktime($found['hour'],$found['min'],0,$found['month'],$found['day'],$found['year']);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/**
|
||||||
@function cancel_timer
|
* cancels a timer
|
||||||
@abstract cancels a timer
|
*
|
||||||
@syntax cancel_timer($id)
|
* @param string $id has to be the one used to set it.
|
||||||
@param $id has to be the one used to set it.
|
* @return boolean True if the timer exists and is not expired.
|
||||||
@result True if the timer exists and is not expired.
|
|
||||||
*/
|
*/
|
||||||
function cancel_timer($id)
|
function cancel_timer($id)
|
||||||
{
|
{
|
||||||
return $this->delete($id);
|
return $this->delete($id);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/**
|
||||||
@function last_check_run
|
* checks when the last check_run was run or set the run-semaphore if $semaphore == True
|
||||||
@abstract checks when the last check_run was run or set the run-semaphore if $semaphore == True
|
*
|
||||||
@param $semaphore if False only check, if true try to set/release the semaphore
|
* @param boolean $semaphore if False only check, if true try to set/release the semaphore
|
||||||
@param $release if $semaphore == True, tells if we should set or release the semaphore
|
* @param boolean $release if $semaphore == True, tells if we should set or release the semaphore
|
||||||
@result if !$set array('start' => $start,'end' => $end) with timestamps of last check_run start and end, \
|
* @return mixed if !$set array('start' => $start,'end' => $end) with timestamps of last check_run start and end, \
|
||||||
!$end means check_run is just running. If $set returns True if it was able to get the semaphore, else False
|
* !$end means check_run is just running. If $set returns True if it was able to get the semaphore, else False
|
||||||
*/
|
*/
|
||||||
function last_check_run($semaphore=False,$release=False,$run_by='')
|
function last_check_run($semaphore=False,$release=False,$run_by='')
|
||||||
{
|
{
|
||||||
@ -390,9 +387,8 @@
|
|||||||
return True;
|
return True;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/**
|
||||||
@function check_run
|
* checks if there are any jobs ready to run (timer expired) and executes them
|
||||||
@abstract checks if there are any jobs ready to run (timer expired) and executes them
|
|
||||||
*/
|
*/
|
||||||
function check_run($run_by='')
|
function check_run($run_by='')
|
||||||
{
|
{
|
||||||
@ -408,32 +404,32 @@
|
|||||||
{
|
{
|
||||||
// checking / setting up phpgw_info/user
|
// checking / setting up phpgw_info/user
|
||||||
//
|
//
|
||||||
if ($GLOBALS['phpgw_info']['user']['account_id'] != $job['account_id'])
|
if ($GLOBALS['egw_info']['user']['account_id'] != $job['account_id'])
|
||||||
{
|
{
|
||||||
$domain = $GLOBALS['phpgw_info']['user']['domain'];
|
$domain = $GLOBALS['egw_info']['user']['domain'];
|
||||||
$lang = $GLOBALS['phpgw_info']['user']['preferences']['common']['lang'];
|
$lang = $GLOBALS['egw_info']['user']['preferences']['common']['lang'];
|
||||||
unset($GLOBALS['phpgw_info']['user']);
|
unset($GLOBALS['egw_info']['user']);
|
||||||
|
|
||||||
if ($GLOBALS['phpgw']->session->account_id = $job['account_id'])
|
if ($GLOBALS['egw']->session->account_id = $job['account_id'])
|
||||||
{
|
{
|
||||||
$GLOBALS['phpgw']->session->account_lid = $GLOBALS['phpgw']->accounts->id2name($job['account_id']);
|
$GLOBALS['egw']->session->account_lid = $GLOBALS['egw']->accounts->id2name($job['account_id']);
|
||||||
$GLOBALS['phpgw']->session->account_domain = $domain;
|
$GLOBALS['egw']->session->account_domain = $domain;
|
||||||
$GLOBALS['phpgw']->session->read_repositories(False,False);
|
$GLOBALS['egw']->session->read_repositories(False,False);
|
||||||
$GLOBALS['phpgw_info']['user'] = $GLOBALS['phpgw']->session->user;
|
$GLOBALS['egw_info']['user'] = $GLOBALS['egw']->session->user;
|
||||||
|
|
||||||
if ($lang != $GLOBALS['phpgw_info']['user']['preferences']['common']['lang'])
|
if ($lang != $GLOBALS['egw_info']['user']['preferences']['common']['lang'])
|
||||||
{
|
{
|
||||||
unset($GLOBALS['lang']);
|
unset($GLOBALS['lang']);
|
||||||
$GLOBALS['phpgw']->translation->add_app('common');
|
$GLOBALS['egw']->translation->add_app('common');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$GLOBALS['phpgw_info']['user']['domain'] = $domain;
|
$GLOBALS['egw_info']['user']['domain'] = $domain;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
list($app) = explode('.',$job['method']);
|
list($app) = explode('.',$job['method']);
|
||||||
$GLOBALS['phpgw']->translation->add_app($app);
|
$GLOBALS['egw']->translation->add_app($app);
|
||||||
|
|
||||||
ExecMethod($job['method'],$job['data']);
|
ExecMethod($job['method'],$job['data']);
|
||||||
|
|
||||||
@ -459,17 +455,16 @@
|
|||||||
return $jobs ? count($jobs) : False;
|
return $jobs ? count($jobs) : False;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/**
|
||||||
@function read
|
* reads all matching db-rows / jobs
|
||||||
@abstract reads all matching db-rows / jobs
|
*
|
||||||
@syntax reay($id=0)
|
* @param string $id =0 reads all expired rows / jobs ready to run\
|
||||||
@param $id =0 reads all expired rows / jobs ready to run\
|
* != 0 reads all rows/jobs matching $id (sql-wildcards '%' and '_' can be used)
|
||||||
!= 0 reads all rows/jobs matching $id (sql-wildcards '%' and '_' can be used)
|
* @return array/boolean db-rows / jobs as array or False if no matches
|
||||||
@result db-rows / jobs as array or False if no matches
|
|
||||||
*/
|
*/
|
||||||
function read($id=0)
|
function read($id=0)
|
||||||
{
|
{
|
||||||
if (strpos($id,'%') !== False || strpos($id,'_') !== False)
|
if (!is_array($id) && (strpos($id,'%') !== False || strpos($id,'_') !== False))
|
||||||
{
|
{
|
||||||
$id = $this->db->quote($id);
|
$id = $this->db->quote($id);
|
||||||
$where = "async_id LIKE $id AND async_id != '##last-check-run##'";
|
$where = "async_id LIKE $id AND async_id != '##last-check-run##'";
|
||||||
@ -506,12 +501,11 @@
|
|||||||
return $jobs;
|
return $jobs;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/**
|
||||||
@function write
|
* write a job / db-row to the db
|
||||||
@abstract write a job / db-row to the db
|
*
|
||||||
@syntax write($job,$exists = False)
|
* @param array $job db-row as array
|
||||||
@param $job db-row as array
|
* @param boolean $exits if True, we do an update, else we check if update or insert necesary
|
||||||
@param $exits if True, we do an update, else we check if update or insert necesary
|
|
||||||
*/
|
*/
|
||||||
function write($job,$exists = False)
|
function write($job,$exists = False)
|
||||||
{
|
{
|
||||||
@ -532,10 +526,10 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/**
|
||||||
@function delete
|
* delete db-row / job with $id
|
||||||
@abstract delete db-row / job with $id
|
*
|
||||||
@result False if $id not found else True
|
* @return boolean False if $id not found else True
|
||||||
*/
|
*/
|
||||||
function delete($id)
|
function delete($id)
|
||||||
{
|
{
|
||||||
@ -562,6 +556,7 @@
|
|||||||
$binarys = array(
|
$binarys = array(
|
||||||
'php' => '/usr/bin/php',
|
'php' => '/usr/bin/php',
|
||||||
'php4' => '/usr/bin/php4', // this is for debian
|
'php4' => '/usr/bin/php4', // this is for debian
|
||||||
|
'php5' => '/usr/bin/php5', // SuSE 9.3 with php5
|
||||||
'crontab' => '/usr/bin/crontab'
|
'crontab' => '/usr/bin/crontab'
|
||||||
);
|
);
|
||||||
foreach ($binarys as $name => $path)
|
foreach ($binarys as $name => $path)
|
||||||
@ -600,16 +595,19 @@
|
|||||||
{
|
{
|
||||||
$this->php = $this->php4;
|
$this->php = $this->php4;
|
||||||
}
|
}
|
||||||
|
if ($this->php5[0] == '/') // we found a php5 binary
|
||||||
|
{
|
||||||
|
$this->php = $this->php5;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/**
|
||||||
@function installed
|
* checks if phpgwapi/cron/asyncservices.php is installed as cron-job
|
||||||
@abstract checks if phpgwapi/cron/asyncservices.php is installed as cron-job
|
*
|
||||||
@syntax installed()
|
* @return array the times asyncservices are run (normaly 'min'=>'* /5') or False if not installed or 0 if crontab not found
|
||||||
@result the times asyncservices are run (normaly 'min'=>'* /5') or False if not installed or 0 if crontab not found
|
* Not implemented for Windows at the moment, always returns 0
|
||||||
@note Not implemented for Windows at the moment, always returns 0
|
|
||||||
*/
|
*/
|
||||||
function installed()
|
function installed()
|
||||||
{
|
{
|
||||||
@ -659,15 +657,15 @@
|
|||||||
return $times;
|
return $times;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/**
|
||||||
@function insall
|
* installs /phpgwapi/cron/asyncservices.php as cron-job
|
||||||
@abstract installs /phpgwapi/cron/asyncservices.php as cron-job
|
*
|
||||||
@syntax install($times)
|
* Not implemented for Windows at the moment, always returns 0
|
||||||
@param $times array with keys 'min','hour','day','month','dow', not set is equal to '*'.
|
*
|
||||||
False means de-install our own crontab line
|
* @param array $times array with keys 'min','hour','day','month','dow', not set is equal to '*'.
|
||||||
@result the times asyncservices are run, False if they are not installed,
|
* False means de-install our own crontab line
|
||||||
0 if crontab not found and ' ' if crontab is deinstalled
|
* @return mixed the times asyncservices are run, False if they are not installed,
|
||||||
@note Not implemented for Windows at the moment, always returns 0
|
* 0 if crontab not found and ' ' if crontab is deinstalled
|
||||||
*/
|
*/
|
||||||
function install($times)
|
function install($times)
|
||||||
{
|
{
|
||||||
@ -693,7 +691,7 @@
|
|||||||
{
|
{
|
||||||
$cronline .= (isset($times[$cu]) ? $times[$cu] : '*') . ' ';
|
$cronline .= (isset($times[$cu]) ? $times[$cu] : '*') . ' ';
|
||||||
}
|
}
|
||||||
$cronline .= $this->php.' -q '.$this->cronline."\n";
|
$cronline .= $this->php.' -qC '.$this->cronline."\n";
|
||||||
//echo "<p>Installing: '$cronline'</p>\n";
|
//echo "<p>Installing: '$cronline'</p>\n";
|
||||||
fwrite($crontab,$cronline);
|
fwrite($crontab,$cronline);
|
||||||
}
|
}
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
/* Basic information about this app */
|
/* Basic information about this app */
|
||||||
$setup_info['phpgwapi']['name'] = 'phpgwapi';
|
$setup_info['phpgwapi']['name'] = 'phpgwapi';
|
||||||
$setup_info['phpgwapi']['title'] = 'phpgwapi';
|
$setup_info['phpgwapi']['title'] = 'phpgwapi';
|
||||||
$setup_info['phpgwapi']['version'] = '1.0.1.006';
|
$setup_info['phpgwapi']['version'] = '1.0.1.007';
|
||||||
$setup_info['phpgwapi']['versions']['current_header'] = '1.28';
|
$setup_info['phpgwapi']['versions']['current_header'] = '1.28';
|
||||||
$setup_info['phpgwapi']['enable'] = 3;
|
$setup_info['phpgwapi']['enable'] = 3;
|
||||||
$setup_info['phpgwapi']['app_order'] = 1;
|
$setup_info['phpgwapi']['app_order'] = 1;
|
||||||
@ -40,7 +40,7 @@
|
|||||||
$setup_info['phpgwapi']['tables'][] = 'phpgw_interserv';
|
$setup_info['phpgwapi']['tables'][] = 'phpgw_interserv';
|
||||||
$setup_info['phpgwapi']['tables'][] = 'egw_vfs';
|
$setup_info['phpgwapi']['tables'][] = 'egw_vfs';
|
||||||
$setup_info['phpgwapi']['tables'][] = 'phpgw_history_log';
|
$setup_info['phpgwapi']['tables'][] = 'phpgw_history_log';
|
||||||
$setup_info['phpgwapi']['tables'][] = 'phpgw_async';
|
$setup_info['phpgwapi']['tables'][] = 'egw_async';
|
||||||
$setup_info['phpgwapi']['tables'][] = 'egw_api_content_history';
|
$setup_info['phpgwapi']['tables'][] = 'egw_api_content_history';
|
||||||
|
|
||||||
$setup_info['phpgwapi']['tables'][] = 'phpgw_vfs2_mimetypes';
|
$setup_info['phpgwapi']['tables'][] = 'phpgw_vfs2_mimetypes';
|
||||||
|
@ -355,7 +355,7 @@
|
|||||||
'ix' => array(array('history_appname','history_record_id','history_status','history_timestamp')),
|
'ix' => array(array('history_appname','history_record_id','history_status','history_timestamp')),
|
||||||
'uc' => array()
|
'uc' => array()
|
||||||
),
|
),
|
||||||
'phpgw_async' => array(
|
'egw_async' => array(
|
||||||
'fd' => array(
|
'fd' => array(
|
||||||
'async_id' => array('type' => 'varchar','precision' => '255','nullable' => False),
|
'async_id' => array('type' => 'varchar','precision' => '255','nullable' => False),
|
||||||
'async_next' => array('type' => 'int','precision' => '4','nullable' => False),
|
'async_next' => array('type' => 'int','precision' => '4','nullable' => False),
|
||||||
|
@ -360,4 +360,12 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
$test[] = '1.0.1.006';
|
||||||
|
function phpgwapi_upgrade1_0_1_006()
|
||||||
|
{
|
||||||
|
$GLOBALS['phpgw_setup']->oProc->RenameTable('phpgw_async','egw_async');
|
||||||
|
|
||||||
|
$GLOBALS['setup_info']['phpgwapi']['currentver'] = '1.0.1.007';
|
||||||
|
return $GLOBALS['setup_info']['phpgwapi']['currentver'];
|
||||||
|
}
|
||||||
?>
|
?>
|
||||||
|
Loading…
Reference in New Issue
Block a user