[ Index ]

PHP Cross Reference of vtigercrm-6.1.0

title

Body

[close]

/ -> vtigercron.php (source)

   1  <?php
   2  /*+*******************************************************************************
   3   * The contents of this file are subject to the vtiger CRM Public License Version 1.0
   4   * ("License"); You may not use this file except in compliance with the License
   5   * The Original Code is:  vtiger CRM Open Source
   6   * The Initial Developer of the Original Code is vtiger.
   7   * Portions created by vtiger are Copyright (C) vtiger.
   8   * All Rights Reserved.
   9   ********************************************************************************/
  10  
  11  /**
  12   * Start the cron services configured.
  13   */
  14  include_once  'vtlib/Vtiger/Cron.php';
  15  require_once  'config.inc.php';
  16  require_once ('modules/Emails/mail.php');
  17  
  18  if (file_exists('config_override.php')) {
  19      include_once 'config_override.php';
  20  }
  21  
  22  // Extended inclusions
  23  require_once  'includes/Loader.php';
  24  vimport ('includes.runtime.EntryPoint');
  25  
  26  $site_URLArray = explode('/',$site_URL);
  27  $organization_name = $site_URLArray[2];
  28  $organization_name = str_replace('.od1.vtiger.com', '', $organization_name);
  29  
  30  $version = explode('.', phpversion());
  31  
  32  $php = ($version[0] * 10000 + $version[1] * 100 + $version[2]);
  33  if($php <  50300){
  34      $hostName = php_uname('n');
  35  } else {
  36      $hostName = gethostname();
  37  }
  38  
  39  $mailbody ="Instance dir : $root_directory <br/> Company Name : $organization_name <br/> Site Url : $site_URL <br/> Host Name : $hostName<br/>";
  40  
  41  $mailSubject = "[Alert] $organization_name ";
  42  if(PHP_SAPI === "cli" || (isset($_SESSION["authenticated_user_id"]) &&    isset($_SESSION["app_unique_key"]) && $_SESSION["app_unique_key"] == $application_unique_key)){
  43  
  44  $cronTasks = false;
  45  if (isset($_REQUEST['service'])) {
  46      // Run specific service
  47      $cronTasks = array(Vtiger_Cron::getInstance($_REQUEST['service']));
  48  }
  49  else {
  50      // Run all service
  51      $cronTasks = Vtiger_Cron::listAllActiveInstances();
  52  }
  53  
  54  $cronRunId = microtime(true);
  55  $cronStarts = date('Y-m-d H:i:s');
  56  
  57  //set global current user permissions
  58  global $current_user;
  59  $current_user = Users::getActiveAdminUser();
  60  
  61  echo sprintf('[CRON],"%s",%s,Instance,"%s","",[STARTS]',$cronRunId,$site_URL,$cronStarts)."\n";
  62  foreach ($cronTasks as $cronTask) {
  63      try {
  64          $cronTask->setBulkMode(true);
  65  
  66          // Not ready to run yet?
  67          if (!$cronTask->isRunnable()) {
  68              echo sprintf("[INFO] %s - not ready to run as the time to run again is not completed\n", $cronTask->getName());
  69              continue;
  70          }
  71  
  72          // Timeout could happen if intermediate cron-tasks fails
  73          // and affect the next task. Which need to be handled in this cycle.                
  74          if ($cronTask->hadTimedout()) {
  75              echo sprintf("[INFO] %s - cron task had timedout as it is not completed last time it run- restarting\n", $cronTask->getName());    
  76          }
  77          
  78          // Mark the status - running        
  79          $cronTask->markRunning();
  80          echo sprintf('[CRON],"%s",%s,%s,"%s","",[STARTS]',$cronRunId,$site_URL,$cronTask->getName(),date('Y-m-d H:i:s',$cronTask->getLastStart()))."\n";
  81          
  82          checkFileAccess($cronTask->getHandlerFile());        
  83          require_once $cronTask->getHandlerFile();
  84          
  85          // Mark the status - finished
  86          $cronTask->markFinished();
  87          echo "\n".sprintf('[CRON],"%s",%s,%s,"%s","%s",[ENDS]',$cronRunId,$site_URL,$cronTask->getName(),date('Y-m-d H:i:s',$cronTask->getLastStart()),date('Y-m-d H:i:s',$cronTask->getLastEnd()))."\n";
  88          
  89      } catch (Exception $e) {
  90          echo sprintf("[ERROR]: %s - cron task execution throwed exception.\n", $cronTask->getName());
  91          echo $e->getMessage();
  92          echo "\n";
  93      }        
  94  }
  95  
  96  $cronEnds = date('Y-m-d H:i:s');
  97  echo sprintf('[CRON],"%s",%s,Instance,"%s","%s",[ENDS]',$cronRunId,$site_URL,$cronStarts,$cronEnds)."\n";
  98  
  99  }
 100  
 101  else{
 102      echo("Access denied!");
 103  }
 104  
 105  
 106  
 107  ?>


Generated: Fri Nov 28 20:08:37 2014 Cross-referenced by PHPXref 0.7.1