/[drupal]/contributions/modules/db_maintenance/db_maintenance.module
ViewVC logotype

Diff of /contributions/modules/db_maintenance/db_maintenance.module

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph | View Patch Patch

revision 1.9.2.6.2.1, Fri Aug 1 02:03:58 2008 UTC revision 1.9.2.6.2.2, Fri Aug 8 18:15:21 2008 UTC
# Line 1  Line 1 
1  <?php  <?php
2  // $Id: db_maintenance.module,v 1.9.2.4 2008/06/26 06:26:25 jgraham Exp $  // $Id: db_maintenance.module,v 1.9.2.6.2.1 2008/08/01 02:03:58 deekayen Exp $
3    
4  /**  /**
5   * @file   * @file
6   * Optimizes database tables during cron runs.   * Optimizes database tables during cron runs.
7   *   *
8   * @version $Id: db_maintenance.module,v 1.9.2.4 2008/06/26 06:26:25 jgraham Exp $   * @version $Id: db_maintenance.module,v 1.9.2.6.2.1 2008/08/01 02:03:58 deekayen Exp $
9   * @author David Kent Norman   * @author David Kent Norman
10   * @link http://deekayen.net/   * @link http://deekayen.net/
11   *   *
# Line 288  function db_maintenance_admin_settings() Line 288  function db_maintenance_admin_settings()
288      '#description' => t('List of email addresses to notify when tasks run. Seperate multiple addressses with a comma. Leave empty for no notification')      '#description' => t('List of email addresses to notify when tasks run. Seperate multiple addressses with a comma. Leave empty for no notification')
289    );    );
290    
   
291    return system_settings_form($form);    return system_settings_form($form);
292  }  }
293    
294    function db_maintenance_admin_settings_validate($formid, &$form) {
295      if (!is_dir($form['db_maintenance_backup_directory'])) {
296        form_set_error('db_maintenance_backup_directory', t('Backup directory does not exist or is not a directory.'));
297      }
298      elseif (!is_writable($form['db_maintenance_backup_directory'])) {
299        form_set_error('db_maintenance_backup_directory', t('Backup directory is not writable.'));
300      }
301    
302      if (!is_file($form['db_maintenance_path_to_tar'])) {
303        form_set_error('db_maintenance_path_to_tar', t('Path to tar is incorrect.'));
304      }
305      elseif(!is_executable($form['db_maintenance_path_to_tar'])) {
306        form_set_error('db_maintenance_path_to_tar', t('tar is not executable.'));
307      }
308    
309      if (!is_file($form['db_maintenance_path_to_mysqldump'])) {
310        form_set_error('db_maintenance_path_to_mysqldump', t('Path to mysqldump is incorrect.'));
311      }
312      elseif(!is_executable($form['db_maintenance_path_to_mysqldump'])) {
313        form_set_error('db_maintenance_path_to_mysqldump', t('mysqldump is not executable.'));
314      }
315    
316      $emails = explode(',', $form['db_maintenance_email_notify']);
317      if (!empty($emails)) {
318        $bad = array();
319        foreach($emails as $email) {
320          $email = trim($email);
321          if (!valid_email_address($email)) {
322            $bad[] = $email;
323          }
324        }
325        if (!empty($bad)) {
326          form_set_error('db_maintenance_email_notify', t('The following email address(es) were invalid; @badmail', array('@badmail' => implode(', ', $bad))));
327        }
328      }
329    }
330    
331  function db_maintenance_check_status($status, $op) {  function db_maintenance_check_status($status, $op) {
332    // mysql return codes indicating okay/success all others assumed to be "bad"    // mysql return codes indicating okay/success all others assumed to be "bad"
333    $DB_MAINTENANCE_OKAY = array('Table is already up to date', 'OK');    $DB_MAINTENANCE_OKAY = array('Table is already up to date', 'OK');
# Line 337  function db_maintenance_email($email) { Line 373  function db_maintenance_email($email) {
373      foreach ($email as $task => $status) {      foreach ($email as $task => $status) {
374        switch ($task) {        switch ($task) {
375          case 'db_backup':          case 'db_backup':
376            if ($status) {            // db_backup returns filename
377              if (is_file($status)) {
378              $message[] = t('Database backed up. mysqldump is available at \'!STATUS\' when connected to \'!URL\'', array('!STATUS' => $status, '!URL' => $base_url));              $message[] = t('Database backed up. mysqldump is available at \'!STATUS\' when connected to \'!URL\'', array('!STATUS' => $status, '!URL' => $base_url));
379            }            }
380            else {            else {
# Line 345  function db_maintenance_email($email) { Line 382  function db_maintenance_email($email) {
382            }            }
383            break;            break;
384          case 'files_backup':          case 'files_backup':
385            if ($status) {            if (is_file($status)) {
386              $message[] = t('Site files backed up. Files tarball are available at \'!STATUS\' when connected to \'!URL\'', array('!STATUS' => $status, '!URL' => $base_url));              $message[] = t('Site files backed up. Files tarball are available at \'!STATUS\' when connected to \'!URL\'', array('!STATUS' => $status, '!URL' => $base_url));
387            }            }
388            else {            else {
# Line 385  function db_maintenance_do_db_backup() { Line 422  function db_maintenance_do_db_backup() {
422    if (is_dir($backupdir)) {    if (is_dir($backupdir)) {
423      exec($mysqldumpexec, $output, $return);      exec($mysqldumpexec, $output, $return);
424      // $return is return value of exec'd command (0 is okay status)      // $return is return value of exec'd command (0 is okay status)
425      if (!$return) {      if (!$return && !is_file($filename)) {
426        watchdog('db_maintenance', $output, WATCHDOG_ERROR);        watchdog('db_maintenance', $output, WATCHDOG_ERROR);
427        return FALSE;        return FALSE;
428      }      }
     else if (!is_file($filename)) {  
       watchdog('db_maintenance', t('failed to backup database') .': '. $output, WATCHDOG_ERROR);  
       return FALSE;  
     }  
429      else {      else {
430        return $filename;        return $filename;
431      }      }

Legend:
Removed from v.1.9.2.6.2.1  
changed lines
  Added in v.1.9.2.6.2.2

  ViewVC Help
Powered by ViewVC 1.1.2