Alternc  3.2
Alternc logiel libre pour l'hébergement
 All Data Structures Namespaces Files Functions Variables Pages
m_cron Class Reference

This class manage web-cron tasks. More...

Public Member Functions

 m_cron ()
 Constructor.
 schedule ()
 lst_cron ()
 List the crontab for the current user.
 hook_menu ()
 update ($arr)
 update the crontab
 delete_one ($id)
 delete a crontab
 valid_schedule ($s)
 validate a crontab schedule
 hook_quota_get ()
 hook for quota computation

Private Member Functions

 _update_one ($url, $user, $password, $email, $schedule, $id=null)
 update a crontab,

Detailed Description

This class manage web-cron tasks.

Definition at line 29 of file m_cron.php.

Member Function Documentation

_update_one (   $url,
  $user,
  $password,
  $email,
  $schedule,
  $id = null 
)
private

update a crontab,

Returns
boolean TRUE if the crontab has been edited

Definition at line 115 of file m_cron.php.

References $cuid, $db, $err, $password, $q, $query, $user, checkmail(), delete_one(), and valid_schedule().

Referenced by update().

{
global $db,$err,$quota,$cuid;
$err->log("cron","update_one");
if (empty($url) && !is_null($id)) {
return $this->delete_one($id);
}
if(filter_var($url,FILTER_VALIDATE_URL)===false){
$err->raise("cron",_("URL not valid"));
return false;
}
$url=urlencode($url);
$user=urlencode($user);
if (empty($user)) $password='';
$password=urlencode($password);
if (!empty($email) && ! checkmail($email) == 0 ){
$err->raise("cron",_("Email address is not valid"));
return false;
}
$email=urlencode($email);
if (! $this->valid_schedule($schedule)) return false;
if (is_null($id)) { // if a new insert, quotacheck
$q = $quota->getquota("cron");
if ( $q["u"] >= $q["t"] ) {
$err->raise("cron",_("You quota of cron entries is over. You cannot create more cron entries"));
return false;
}
} else { // if not a new insert, check the $cuid
$db->query("SELECT uid FROM cron WHERE id = $id;");
if (! $db->next_record()) {
return "false";
} // return false if pb
if ( $db->f('uid') != $cuid ) {
$err->raise("cron",_("Identity problem"));
return false;
}
}
$query = "REPLACE INTO cron (id, uid, url, user, password, schedule, email) VALUES ('$id', '$cuid', '$url', '$user', '$password', '$schedule', '$email') ;";
return $db->query("$query");
}
delete_one (   $id)

delete a crontab

Parameters
$idthe id of the crontab to delete
Returns
boolean TRUE if the crontab has been deleted

Definition at line 104 of file m_cron.php.

References $cuid, $db, and $err.

Referenced by _update_one().

{
global $db,$err,$cuid;
$err->log("cron","delete_one");
return $db->query("DELETE FROM cron WHERE id=".intval($id)." AND uid=$cuid LIMIT 1;");
}
hook_menu ( )

Definition at line 70 of file m_cron.php.

{
$obj = array(
'title' => _("Scheduled tasks"),
'ico' => 'images/schedule.png',
'link' => 'cron.php',
'pos' => 90,
) ;
return $obj;
}
hook_quota_get ( )

hook for quota computation

Definition at line 178 of file m_cron.php.

References $cuid, $db, $err, and $q.

{
global $cuid,$db,$err;
$err->log("cron","alternc_get_quota");
$q=Array("name"=>"cron", "description"=>_("Scheduled tasks"), "used"=>0);
$db->query("select count(*) as cnt from cron where uid = $cuid;");
if ($db->next_record()) {
$q['used']=$db->f('cnt');
}
return $q;
}
lst_cron ( )

List the crontab for the current user.

Returns
array an hash for each crontab.

Definition at line 51 of file m_cron.php.

References $cuid, $db, $err, and $r.

{
global $cuid,$db,$err;
$err->log("cron","lst_cron");
$db->query("SELECT * FROM cron WHERE uid = $cuid ORDER BY url;");
$r=Array();
while ($db->next_record()) {
$tmp=Array();
$tmp['id']=$db->f('id');
$tmp['url']=urldecode($db->f('url'));
$tmp['user']=urldecode($db->f('user'));
$tmp['password']=urldecode($db->f('password'));
$tmp['schedule']=$db->f('schedule');
$tmp['email']=urldecode($db->f('email'));
$tmp['next_execution']=$db->f('next_execution');
$r[]=$tmp;
}
return $r;
}
m_cron ( )

Constructor.

Definition at line 35 of file m_cron.php.

{
}
schedule ( )

Definition at line 38 of file m_cron.php.

Referenced by valid_schedule().

{
return Array(
Array('unit'=>1440, 'name'=>_("Daily")),
Array('unit'=>60, 'name'=>_("Hour")),
Array('unit'=>30, 'name'=>_("Half Hour")),
);
}
update (   $arr)

update the crontab

Parameters
$arrarray the crontab information, including its ID
Returns
boolean TRUE if the crontab has been edited

Definition at line 86 of file m_cron.php.

References _update_one(), and isset.

{
$ok=true;
foreach ($arr as $a) {
if (! isset($a['id'])) $a['id']=null;
if (empty($a['url']) && is_null($a['id'])) continue;
if (! $this->_update_one($a['url'], $a['user'], $a['password'], $a['email'], $a['schedule'], $a['id']) ) {
$ok=false;
}
}
return $ok;
}
valid_schedule (   $s)

validate a crontab schedule

Parameters
$sarray schedule paramters
Returns
boolean TRUE if the schedule is valid

Definition at line 165 of file m_cron.php.

References $r, and schedule().

Referenced by _update_one().

{
$s2 = intval($s);
if ($s2 != $s) return false;
$r=false;
foreach ($this->schedule() as $cs ) {
if ($cs['unit'] == $s) return true;
}
return $r;
}

The documentation for this class was generated from the following file: