Alternc  3.2
Alternc logiel libre pour l'h├ębergement
 All Data Structures Namespaces Files Functions Variables Pages
m_action Class Reference

This class manage actions to be performed on the file system on behalf of alternc Classes It primary use is to store the actions to be performed ( creating file or folder, deleting, setting permissions etc..) in the action sql table. More...

Public Member Functions

 m_action ()
 Constructor.
 do_action ()
 Plans the cration of a file.
 create_file ($file, $content="", $user="root")
 Plans a file creation.
 create_dir ($dir, $user="root")
 Plans the cration of a dir.
 fix_user ($uid, $user="root")
 Plans a perms fix upon user creation.
 fix_dir ($dir, $user="root")
 Plans a dir fix.
 fix_file ($file, $user="root")
 Plans a file fix.
 del ($dir, $user="root")
 function to delete file / folder
 move ($src, $dst, $user="root")
 function returning the first not locked line of the action table
 archive ($archive, $dir="html")
 function archiving a directory ( upon account deletion )
 set ($type, $user, $parameters)
 function inserting the action in the sql table
 get_old ($all=null)
 This seems to be unused ?
 purge ($all=null)
 type $err type $db
 get_action ()
 function returning the first not locked line of the action table
 begin ($id)
 function locking an entry while it is being executed by the action script
 finish ($id, $return=0)
 function locking an entry while it is being executed by the action script
 reset_job ($id)
 type $db type $err
 get_job ()
 Returns a list of actions marked as executable and ready for execution.
 cancel ($id)
 function locking an entry while it is being executed by the action script

Detailed Description

This class manage actions to be performed on the file system on behalf of alternc Classes It primary use is to store the actions to be performed ( creating file or folder, deleting, setting permissions etc..) in the action sql table.

The script /usr/lib/alternc/do_actions.php handled by cron and incron is then used to perform those actions.

Copyleft AlternC Team

Definition at line 33 of file m_action.php.

Member Function Documentation

archive (   $archive,
  $dir = "html" 
)

function archiving a directory ( upon account deletion )

type $cuid type $db type $err

Parameters
type$archiveDirectory to archive within the archive_del_data folder if set in variable sql table If archive_del_data is not set we delete the folder
type$dirsub_directory of the archive directory
Returns
boolean

Definition at line 148 of file m_action.php.

References $cuid, $db, $err, del(), move(), and variable_get().

{
global $cuid, $db, $err;
$arch = variable_get('archive_del_data');
if (empty($arch)) {
$this->del($archive);
return true;
}
$BACKUP_DIR = $arch;
$db->query("select login from membres where uid=$cuid;");
$db->next_record();
if (!$db->Record["login"]) {
$err->raise("action", _("Login corresponding to $cuid not found"));
return false;
}
$uidlogin = $cuid . "-" . $db->Record["login"];
//The path will look like /<archive_del_data>/YYYY-MM/<uid>-<login>/<folder>
$today = getdate();
$dest = $BACKUP_DIR . '/' . $today["year"] . '-' . $today["mon"] . '/' . $uidlogin . '/' . $dir;
$this->move($archive, $dest);
return true;
}
begin (   $id)

function locking an entry while it is being executed by the action script

type $db type $err

Parameters
type$id
Returns
boolean

Definition at line 291 of file m_action.php.

References $db, and $err.

{
global $db, $err;
if (!$db->query("update actions set begin=now() where id=$id ;")) {
$err->raise("action", _("Error locking the action : $id"));
return false;
}
return true;
}
cancel (   $id)

function locking an entry while it is being executed by the action script

type $db

Parameters
type$id
Returns
boolean

Definition at line 360 of file m_action.php.

References $db, and finish().

{
global $db;
$this->finish($id, 666);
return true;
}
create_dir (   $dir,
  $user = "root" 
)

Plans the cration of a dir.

Parameters
string$dir
int$user
Returns
boolean

Definition at line 77 of file m_action.php.

References $user.

{
return $this->set('create_dir', $user, array('dir' => $dir));
}
create_file (   $file,
  $content = "",
  $user = "root" 
)

Plans a file creation.

Parameters
string$file
string$content
int$user
Returns
boolean

Definition at line 66 of file m_action.php.

References $content, and $user.

{
return $this->set('create_file', $user, array('file' => $file, 'content' => $content));
}
del (   $dir,
  $user = "root" 
)

function to delete file / folder

Parameters
type$dir
type$user
Returns
type

Definition at line 120 of file m_action.php.

References $user.

Referenced by archive().

{
return $this->set('delete', $user, array('dir' => $dir));
}
do_action ( )

Plans the cration of a file.

type $err type $L_INOTIFY_DO_ACTION

Returns
boolean

Definition at line 49 of file m_action.php.

References $err.

Referenced by set().

{
global $err, $L_INOTIFY_DO_ACTION;
$err->log("action", "do_action");
if( ! touch($L_INOTIFY_DO_ACTION) ){
return FALSE;
}
return TRUE;
}
finish (   $id,
  $return = 0 
)

function locking an entry while it is being executed by the action script

type $db type $err

Parameters
type$id
type$return
Returns
boolean

Definition at line 309 of file m_action.php.

References $db, and $err.

Referenced by cancel().

{
global $db, $err;
if (!$db->query("update actions set end=now(),status='$return' where id=$id ;")) {
$err->raise("action", _("Error unlocking the action : $id"));
return false;
}
return true;
}
fix_dir (   $dir,
  $user = "root" 
)

Plans a dir fix.

Parameters
type$dir
type$user
Returns
type

Definition at line 98 of file m_action.php.

References $user.

{
return $this->set('fix_dir', $user, array('dir' => $dir));
}
fix_file (   $file,
  $user = "root" 
)

Plans a file fix.

Parameters
type$file
type$user
Returns
type

Definition at line 109 of file m_action.php.

References $user.

{
return $this->set('fix_file', $user, array('file' => $file));
}
fix_user (   $uid,
  $user = "root" 
)

Plans a perms fix upon user creation.

Parameters
int$uid
string$user
Returns
boolean

Definition at line 87 of file m_action.php.

References $uid, and $user.

{
return $this->set('fix_user', $user, array('uid' => $uid));
}
get_action ( )

function returning the first not locked line of the action table

type $db type $err

Returns
boolean or array

Definition at line 270 of file m_action.php.

References $db, $err, and $tab.

{
global $db, $err;
$tab = array();
$db->query('select * from actions where end = 0 and begin = 0 order by id limit 1;');
if ($db->next_record()) {
$tab[] = $db->Record;
return $tab;
} else {
return false;
}
}
get_job ( )

Returns a list of actions marked as executable and ready for execution.

type $db type $err

Returns
boolean

Definition at line 341 of file m_action.php.

References $db, $err, and $tab.

{
global $db, $err;
$tab = array();
$db->query("Select * from actions where begin !=0 and end = 0 ;");
if ($db->next_record()) {
$tab[] = $db->Record;
return $tab;
} else {
return false;
}
}
get_old (   $all = null)

This seems to be unused ?

type $err type $db

Parameters
type$all
Returns
boolean

Definition at line 228 of file m_action.php.

References $db, and $err.

{
global $err, $db;
$purge = "select * from actions where TO_DAYS(curdate()) - TO_DAYS(creation) > 2;";
$result = $db->query($purge);
if (! $result) {
$err->raise("action", _("Error selecting old actions"));
return false;
}
return $db->num_rows($result) ;
}
m_action ( )

Constructor.

Definition at line 38 of file m_action.php.

{
}
move (   $src,
  $dst,
  $user = "root" 
)

function returning the first not locked line of the action table

Parameters
type$src
type$dst
type$user
Returns
type

Definition at line 132 of file m_action.php.

References $user.

Referenced by archive().

{
return $this->set('move', $user, array('src' => $src, 'dst' => $dst));
}
purge (   $all = null)

type $err type $db

Parameters
type$all
Returns
boolean

Definition at line 247 of file m_action.php.

References $db, and $err.

{
global $err, $db;
if (is_null($all)) {
$purge = "delete from actions where TO_DAYS(curdate()) - TO_DAYS(creation) > 2 and status = 0;";
} else {
$purge = "delete from actions where TO_DAYS(curdate()) - TO_DAYS(creation) > 2;";
}
$result = $db->query($purge);
if (! $result) {
$err->raise("action", _("Error purging old actions"));
return false;
}
return $db->num_rows($result) ;
}
reset_job (   $id)

type $db type $err

Parameters
type$id
Returns
boolean

Definition at line 325 of file m_action.php.

References $db, and $err.

{
global $db, $err;
if (!$db->query("update actions set end=0,begin=0,status='' where id=$id ;")) {
$err->raise("action", _("Error unlocking the action : $id"));
return false;
}
return true;
}
set (   $type,
  $user,
  $parameters 
)

function inserting the action in the sql table

type $db type $err

Parameters
type$type
type$user
type$parameters
Returns
boolean

Definition at line 182 of file m_action.php.

References $db, $err, $parameters, $query, and do_action().

{
global $db, $err;
$err->log("action", "set", $type);
$serialized = serialize($parameters);
switch ($type) {
case 'create_file':
$query = "insert into actions values ('','CREATE_FILE','$serialized',now(),'','','$user','');";
break;
case 'create_dir':
$query = "insert into actions values ('','CREATE_DIR','$serialized',now(),'','','$user','');";
break;
case 'move':
$query = "insert into actions values ('','MOVE','$serialized',now(),'','','$user','');";
break;
case 'fix_user':
$query = "insert into actions values ('','FIX_USER','$serialized',now(),'','','$user','');";
break;
case 'fix_file':
$query = "insert into actions values ('','FIX_FILE','$serialized',now(),'','','$user','');";
break;
case 'fix_dir':
$query = "insert into actions values ('','FIX_DIR','$serialized',now(),'','','$user','');";
break;
case 'delete':
$query = "insert into actions values ('','DELETE','$serialized',now(),'','','$user','');";
break;
default:
return false;
}
if (!$db->query($query)) {
$err->raise("action", _("Error setting actions"));
return false;
}
$this->do_action();
return true;
}

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