Alternc  latest
Alternc logiel libre pour l'h├ębergement
 All Classes 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. More...
 
 do_action ()
 Plans the cration of a file. More...
 
 create_file ($file, $content="", $user="root")
 Plans a file creation. More...
 
 chmod ($filename, $perms, $user="root")
 Plans the a chmod on file or dir. More...
 
 create_dir ($dir, $user="root")
 Plans the creation of a dir. More...
 
 fix_user ($uid, $user="root")
 Plans a perms fix upon user creation. More...
 
 fix_dir ($dir, $user="root")
 Plans a dir fix. More...
 
 fix_file ($file, $user="root")
 Plans a file fix. More...
 
 del ($dir, $user="root")
 function to delete file / folder More...
 
 move ($src, $dst, $user="root")
 function returning the first not locked line of the action table More...
 
 archive ($archive, $dir="html")
 function archiving a directory ( upon account deletion ) More...
 
 set ($type, $user, $parameters)
 : This has to be escaped function inserting the action in the sql table More...
 
 get_old ()
 This seems to be unused ? More...
 
 purge ($all=null)
 
 get_action ()
 function returning the first not locked line of the action table More...
 
 begin ($id)
 function locking an entry while it is being executed by the action script More...
 
 finish ($id, $return=0)
 function locking an entry while it is being executed by the action script More...
 
 reset_job ($id)
 
 get_job ()
 Returns a list of actions marked as executable and ready for execution. More...
 
 cancel ($id)
 function locking an entry while it is being executed by the action script More...
 

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

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

function archiving a directory ( upon account deletion )

Parameters
globalint $cuid
globalm_mysql $db
globalm_err $err
string$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
string$dirsub_directory of the archive directory
Returns
boolean

Definition at line 161 of file m_action.php.

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

161  {
162  global $cuid, $db, $err;
163 
164  $arch = variable_get('archive_del_data');
165  if (empty($arch)) {
166  $this->del($archive);
167  return true;
168  }
169  $BACKUP_DIR = $arch;
170  $db->query("select login from membres where uid= ?;", array($cuid));
171  $db->next_record();
172  if (!$db->Record["login"]) {
173  $err->raise("action", _("Login corresponding to $cuid not found"));
174  return false;
175  }
176  $uidlogin = $cuid . "-" . $db->Record["login"];
177 
178  //The path will look like /<archive_del_data>/YYYY-MM/<uid>-<login>/<folder>
179  $today = getdate();
180  $dest = $BACKUP_DIR . '/' . $today["year"] . '-' . $today["mon"] . '/' . $uidlogin . '/' . $dir;
181  $this->move($archive, $dest);
182  return true;
183  }
global $db
Definition: bootstrap.php:22
del($dir, $user="root")
function to delete file / folder
Definition: m_action.php:133
$err
Definition: bootstrap.php:72
move($src, $dst, $user="root")
function returning the first not locked line of the action table
Definition: m_action.php:145
$cuid
Definition: bootstrap.php:43
variable_get($name, $default=null, $createit_comment=null)
Return a persistent variable.
Definition: variables.php:90
m_action::begin (   $id)

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

Parameters
globalm_mysql $db
globalm_err $err
int$id
Returns
boolean

Definition at line 290 of file m_action.php.

References $db, $err, and $id.

290  {
291  global $db, $err;
292  if (!$db->query("update actions set begin=now() where id= ? ;", array($id))) {
293  $err->raise("action", _("Error locking the action : $id"));
294  return false;
295  }
296  return true;
297  }
global $db
Definition: bootstrap.php:22
$err
Definition: bootstrap.php:72
if(!isset($is_include)) if(!$key &&!$crt) $id
m_action::cancel (   $id)

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

Parameters
globalm_mysql $db
int$id
Returns
boolean

Definition at line 359 of file m_action.php.

References $id, and finish().

359  {
360  $this->finish($id, 666);
361  return true;
362  }
finish($id, $return=0)
function locking an entry while it is being executed by the action script
Definition: m_action.php:308
if(!isset($is_include)) if(!$key &&!$crt) $id
m_action::chmod (   $filename,
  $perms,
  $user = "root" 
)

Plans the a chmod on file or dir.

Parameters
string$filename
int$perms
string$user
Returns
boolean

Definition at line 79 of file m_action.php.

References $user, and set().

79  {
80  return $this->set('chmod', $user, array('filename' => $filename, "perms" => $perms));
81  }
$user
Definition: bootstrap.php:84
set($type, $user, $parameters)
: This has to be escaped function inserting the action in the sql table
Definition: m_action.php:196
m_action::create_dir (   $dir,
  $user = "root" 
)

Plans the creation of a dir.

Parameters
string$dir
int$user
Returns
boolean

Definition at line 90 of file m_action.php.

References $user, and set().

90  {
91  return $this->set('create_dir', $user, array('dir' => $dir));
92  }
$user
Definition: bootstrap.php:84
set($type, $user, $parameters)
: This has to be escaped function inserting the action in the sql table
Definition: m_action.php:196
m_action::create_file (   $file,
  $content = "",
  $user = "root" 
)

Plans a file creation.

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

Definition at line 67 of file m_action.php.

References $content, $user, and set().

67  {
68  return $this->set('create_file', $user, array('file' => $file, 'content' => $content));
69  }
$user
Definition: bootstrap.php:84
$content
Definition: bro_editor.php:94
set($type, $user, $parameters)
: This has to be escaped function inserting the action in the sql table
Definition: m_action.php:196
m_action::del (   $dir,
  $user = "root" 
)

function to delete file / folder

Parameters
string$dir
m_user$user
Returns
boolean

Definition at line 133 of file m_action.php.

References $user, and set().

Referenced by archive().

133  {
134  return $this->set('delete', $user, array('dir' => $dir));
135  }
$user
Definition: bootstrap.php:84
set($type, $user, $parameters)
: This has to be escaped function inserting the action in the sql table
Definition: m_action.php:196
m_action::do_action ( )

Plans the cration of a file.

Parameters
global$err
globalstring $L_INOTIFY_DO_ACTION
Returns
boolean

Definition at line 50 of file m_action.php.

References $err.

Referenced by set().

50  {
51  global $err, $L_INOTIFY_DO_ACTION;
52  $err->log("action", "do_action");
53  if (!@touch($L_INOTIFY_DO_ACTION)) {
54  return FALSE;
55  }
56  return TRUE;
57  }
$err
Definition: bootstrap.php:72
m_action::finish (   $id,
  $return = 0 
)

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

Parameters
globalm_mysql $db
globalm_err $err
int$id
integer$return
Returns
boolean

Definition at line 308 of file m_action.php.

References $db, $err, and $id.

Referenced by cancel().

308  {
309  global $db, $err;
310  if (!$db->query("update actions set end=now(),status=? where id= ?;", array($return, $id))) {
311  $err->raise("action", _("Error unlocking the action : $id"));
312  return false;
313  }
314  return true;
315  }
global $db
Definition: bootstrap.php:22
$err
Definition: bootstrap.php:72
if(!isset($is_include)) if(!$key &&!$crt) $id
m_action::fix_dir (   $dir,
  $user = "root" 
)

Plans a dir fix.

Parameters
string$dir
m_user$user
Returns
boolean

Definition at line 111 of file m_action.php.

References $user, and set().

111  {
112  return $this->set('fix_dir', $user, array('dir' => $dir));
113  }
$user
Definition: bootstrap.php:84
set($type, $user, $parameters)
: This has to be escaped function inserting the action in the sql table
Definition: m_action.php:196
m_action::fix_file (   $file,
  $user = "root" 
)

Plans a file fix.

Parameters
string$file
m_user$user
Returns
boolean

Definition at line 122 of file m_action.php.

References $user, and set().

122  {
123  return $this->set('fix_file', $user, array('file' => $file));
124  }
$user
Definition: bootstrap.php:84
set($type, $user, $parameters)
: This has to be escaped function inserting the action in the sql table
Definition: m_action.php:196
m_action::fix_user (   $uid,
  $user = "root" 
)

Plans a perms fix upon user creation.

Parameters
int$uid
string$user
Returns
boolean

Definition at line 100 of file m_action.php.

References $uid, $user, and set().

100  {
101  return $this->set('fix_user', $user, array('uid' => $uid));
102  }
$user
Definition: bootstrap.php:84
$uid
set($type, $user, $parameters)
: This has to be escaped function inserting the action in the sql table
Definition: m_action.php:196
m_action::get_action ( )

function returning the first not locked line of the action table

Parameters
globalm_mysql $db
globalm_err $err
Returns
boolean or array

Definition at line 269 of file m_action.php.

References $db, $err, and $tab.

269  {
270  global $db, $err;
271 
272  $tab = array();
273  $db->query('select * from actions where end = 0 and begin = 0 order by id limit 1;');
274  if ($db->next_record()) {
275  $tab[] = $db->Record;
276  return $tab;
277  } else {
278  return false;
279  }
280  }
global $db
Definition: bootstrap.php:22
$err
Definition: bootstrap.php:72
if(!empty($domup)) $tab
m_action::get_job ( )

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

Parameters
globalm_mysql $db
globalm_err $err
Returns
boolean

Definition at line 340 of file m_action.php.

References $db, and $tab.

340  {
341  global $db;
342  $tab = array();
343  $db->query("Select * from actions where begin !=0 and end = 0 ;");
344  if ($db->next_record()) {
345  $tab[] = $db->Record;
346  return $tab;
347  } else {
348  return false;
349  }
350  }
global $db
Definition: bootstrap.php:22
if(!empty($domup)) $tab
m_action::get_old ( )

This seems to be unused ?

Parameters
globalm_err $err
globalm_mysql $db
Returns
boolean

Definition at line 228 of file m_action.php.

References $db, and $err.

228  {
229  global $err, $db;
230 
231  $purge = "select * from actions where TO_DAYS(curdate()) - TO_DAYS(creation) > 2;";
232  $result = $db->query($purge);
233  if (!$result) {
234  $err->raise("action", _("Error selecting old actions"));
235  return false;
236  }
237  return $db->num_rows($result);
238  }
global $db
Definition: bootstrap.php:22
$err
Definition: bootstrap.php:72
m_action::m_action ( )

Constructor.

Definition at line 39 of file m_action.php.

39  {
40 
41  }
m_action::move (   $src,
  $dst,
  $user = "root" 
)

function returning the first not locked line of the action table

Parameters
string$src
string$dst
m_user$user
Returns
boolean

Definition at line 145 of file m_action.php.

References $user, and set().

Referenced by archive().

145  {
146  return $this->set('move', $user, array('src' => $src, 'dst' => $dst));
147  }
$user
Definition: bootstrap.php:84
set($type, $user, $parameters)
: This has to be escaped function inserting the action in the sql table
Definition: m_action.php:196
m_action::purge (   $all = null)
Parameters
globalm_err $err
globalm_mysql $db
type$all
Returns
boolean

Definition at line 247 of file m_action.php.

References $db, and $err.

247  {
248  global $err, $db;
249  if (is_null($all)) {
250  $purge = "delete from actions where TO_DAYS(curdate()) - TO_DAYS(creation) > 2 and status = 0;";
251  } else {
252  $purge = "delete from actions where TO_DAYS(curdate()) - TO_DAYS(creation) > 2;";
253  }
254  $result = $db->query($purge);
255  if (!$result) {
256  $err->raise("action", _("Error purging old actions"));
257  return false;
258  }
259  return $db->num_rows($result);
260  }
global $db
Definition: bootstrap.php:22
$err
Definition: bootstrap.php:72
m_action::reset_job (   $id)
Parameters
globalm_mysql $db
globalm_err $err
int$id
Returns
boolean

Definition at line 324 of file m_action.php.

References $db, $err, and $id.

324  {
325  global $db, $err;
326  if (!$db->query("update actions set end=0,begin=0,status='' where id= ?;", array($id))) {
327  $err->raise("action", _("Error unlocking the action : $id"));
328  return false;
329  }
330  return true;
331  }
global $db
Definition: bootstrap.php:22
$err
Definition: bootstrap.php:72
if(!isset($is_include)) if(!$key &&!$crt) $id
m_action::set (   $type,
  $user,
  $parameters 
)

: This has to be escaped function inserting the action in the sql table

Parameters
globalm_mysql $db
globalm_err $err
string$type
string | integer$userwich user do we impersonate?
mixed$parameters
Returns
boolean

Definition at line 196 of file m_action.php.

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

Referenced by chmod(), create_dir(), create_file(), del(), fix_dir(), fix_file(), fix_user(), and move().

196  {
197  global $db, $err;
198  $err->log("action", "set", $type);
199  $serialized = serialize($parameters);
200  $type = strtoupper($type);
201  if (in_array($type, array('CHMOD',
202  'CREATE_FILE',
203  'CREATE_DIR',
204  'MOVE',
205  'FIX_USER',
206  'FIX_FILE',
207  'FIX_DIR',
208  'DELETE'))) {
209  $query = "INSERT INTO `actions` (type, parameters, creation, user) VALUES('$type', '$serialized', now(), '$user');";
210  } else {
211  return False;
212  }
213 
214  if (!$db->query($query)) {
215  $err->raise("action", _("Error setting actions"));
216  return false;
217  }
218  return $this->do_action();
219  }
do_action()
Plans the cration of a file.
Definition: m_action.php:50
global $db
Definition: bootstrap.php:22
$err
Definition: bootstrap.php:72
$query
Definition: 3.0.0~3.php:43

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