Alternc  latest
Alternc logiel libre pour l'hébergement
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

 do_action ()
 Tell the incron that an action should be performed. 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 permission fix. More...
 
 fix_file ($file, $user="root")
 Plans a file permission 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)
 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.

Definition at line 28 of file m_action.php.

Member Function Documentation

◆ archive()

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

function archiving a directory ( upon account deletion )

Parameters
globalint $cuid
globalm_mysql $db
globalm_messages $msg
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 158 of file m_action.php.

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

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

◆ begin()

m_action::begin (   $id)

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

Parameters
globalm_mysql $db
globalm_messages $msg
int$id
Returns
boolean

Definition at line 290 of file m_action.php.

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

References $db, $id, and $msg.

◆ cancel()

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 363 of file m_action.php.

363  {
364  $this->finish($id, 666);
365  return true;
366  }
finish($id, $return=0)
function locking an entry while it is being executed by the action script
Definition: m_action.php:309

References $id, and finish().

◆ chmod()

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 69 of file m_action.php.

69  {
70  return $this->set('chmod', $user, array('filename' => $filename, "perms" => $perms));
71  }
$user
Definition: bootstrap.php:84

References $user.

◆ create_dir()

m_action::create_dir (   $dir,
  $user = "root" 
)

Plans the creation of a dir.

Parameters
string$dir
int$user
Returns
boolean

Definition at line 81 of file m_action.php.

81  {
82  return $this->set('create_dir', $user, array('dir' => $dir));
83  }

References $user.

◆ create_file()

m_action::create_file (   $file,
  $content = "",
  $user = "root" 
)

Plans a file creation.

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

Definition at line 56 of file m_action.php.

56  {
57  return $this->set('create_file', $user, array('file' => $file, 'content' => $content));
58  }
$content
Definition: bro_editor.php:91

References $content, and $user.

◆ del()

m_action::del (   $dir,
  $user = "root" 
)

function to delete file / folder

Parameters
string$dir
m_user$user
Returns
boolean

Definition at line 128 of file m_action.php.

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

References $user.

Referenced by archive().

◆ do_action()

m_action::do_action ( )

Tell the incron that an action should be performed.

Parameters
globalm_messages $msg
globalstring $L_INOTIFY_DO_ACTION
Returns
boolean

Definition at line 38 of file m_action.php.

38  {
39  global $msg, $L_INOTIFY_DO_ACTION;
40  $msg->log("action", "do_action");
41  if (!@touch($L_INOTIFY_DO_ACTION)) {
42  return FALSE;
43  }
44  return TRUE;
45  }

References $msg.

Referenced by set().

◆ finish()

m_action::finish (   $id,
  $return = 0 
)

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

Parameters
globalm_mysql $db
globalm_messages $msg
int$id
integer$return
Returns
boolean

Definition at line 309 of file m_action.php.

309  {
310  global $db, $msg;
311  if (!$db->query("update actions set end=now(),status=? where id= ?;", array($return, $id))) {
312  $msg->raise("ERROR", "action", _("Error unlocking the action : $id"));
313  return false;
314  }
315  return true;
316  }

References $db, $id, and $msg.

Referenced by cancel().

◆ fix_dir()

m_action::fix_dir (   $dir,
  $user = "root" 
)

Plans a dir permission fix.

Parameters
string$dir
m_user$user
Returns
boolean

Definition at line 104 of file m_action.php.

104  {
105  return $this->set('fix_dir', $user, array('dir' => $dir));
106  }

References $user.

◆ fix_file()

m_action::fix_file (   $file,
  $user = "root" 
)

Plans a file permission fix.

Parameters
string$file
m_user$user
Returns
boolean

Definition at line 116 of file m_action.php.

116  {
117  return $this->set('fix_file', $user, array('file' => $file));
118  }

References $user.

◆ fix_user()

m_action::fix_user (   $uid,
  $user = "root" 
)

Plans a perms fix upon user creation.

Parameters
int$uid
string$user
Returns
boolean

Definition at line 92 of file m_action.php.

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

References $uid, and $user.

◆ get_action()

m_action::get_action ( )

function returning the first not locked line of the action table

Parameters
globalm_mysql $db
Returns
boolean or array

Definition at line 268 of file m_action.php.

268  {
269  global $db;
270 
271  $tab = array();
272  $db->query('select * from actions where end = 0 and begin = 0 order by id limit 1;');
273  if ($db->next_record()) {
274  $tab[] = $db->Record;
275  return $tab;
276  } else {
277  return false;
278  }
279  }

References $db, and $tab.

◆ get_job()

m_action::get_job ( )

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

Parameters
globalm_mysql $db
globalm_messages $msg
Returns
boolean

Definition at line 343 of file m_action.php.

343  {
344  global $db;
345  $tab = array();
346  $db->query("Select * from actions where begin !=0 and end = 0 ;");
347  if ($db->next_record()) {
348  $tab[] = $db->Record;
349  return $tab;
350  } else {
351  return false;
352  }
353  }

References $db, and $tab.

◆ get_old()

m_action::get_old ( )

This seems to be unused ?

Parameters
globalm_messages $msg
globalm_mysql $db
Returns
boolean

Definition at line 226 of file m_action.php.

226  {
227  global $msg, $db;
228 
229  $purge = "select * from actions where TO_DAYS(curdate()) - TO_DAYS(creation) > 2;";
230  $result = $db->query($purge);
231  if (!$result) {
232  $msg->raise("ERROR", "action", _("Error selecting old actions"));
233  return false;
234  }
235  return $db->num_rows($result);
236  }

References $db, and $msg.

◆ move()

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 141 of file m_action.php.

141  {
142  return $this->set('move', $user, array('src' => $src, 'dst' => $dst));
143  }

References $user.

Referenced by archive().

◆ purge()

m_action::purge (   $all = null)
Parameters
globalm_messages $msg
globalm_mysql $db
type$all
Returns
boolean|int The number of rows purged; False is there was an error

Definition at line 246 of file m_action.php.

246  {
247  global $msg, $db;
248  if (is_null($all)) {
249  $purge = "delete from actions where TO_DAYS(curdate()) - TO_DAYS(creation) > 2 and status = 0;";
250  } else {
251  $purge = "delete from actions where TO_DAYS(curdate()) - TO_DAYS(creation) > 2;";
252  }
253  $result = $db->query($purge);
254  if (!$result) {
255  $msg->raise("ERROR", "action", _("Error purging old actions"));
256  return false;
257  }
258  return $db->num_rows($result);
259  }

References $db, and $msg.

◆ reset_job()

m_action::reset_job (   $id)
Parameters
globalm_mysql $db
globalm_messages $msg
int$id
Returns
boolean

Definition at line 326 of file m_action.php.

326  {
327  global $db, $msg;
328  if (!$db->query("update actions set end=0,begin=0,status='' where id= ?;", array($id))) {
329  $msg->raise("ERROR", "action", _("Error unlocking the action : $id"));
330  return false;
331  }
332  return true;
333  }

References $db, $id, and $msg.

◆ set()

m_action::set (   $type,
  $user,
  $parameters 
)

function inserting the action in the sql table

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

Definition at line 193 of file m_action.php.

193  {
194  global $db, $msg;
195  $msg->log("action", "set", $type);
196  $serialized = serialize($parameters);
197  $type = strtoupper($type);
198  if (in_array($type, array('CHMOD',
199  'CREATE_FILE',
200  'CREATE_DIR',
201  'MOVE',
202  'FIX_USER',
203  'FIX_FILE',
204  'FIX_DIR',
205  'DELETE'))) {
206  $query = "INSERT INTO `actions` (type, parameters, creation, user) VALUES('$type', '$serialized', now(), '$user');";
207  } else {
208  return False;
209  }
210 
211  if (!$db->query($query)) {
212  $msg->raise("ERROR", "action", _("Error setting actions"));
213  return false;
214  }
215  return $this->do_action();
216  }
$query
Definition: 3.0.0~3.php:37
do_action()
Tell the incron that an action should be performed.
Definition: m_action.php:38

References $db, $msg, $query, and do_action().


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