Overview

Namespaces

  • Cron
  • None

Classes

  • _HtmlGrid_TableOut
  • _TransactionModel_RawSaveOperation
  • AccessControlComponent
  • AccessControlHelper
  • ActionListHelper
  • ActiveDirectoryUtils
  • AddCurrentPidToSchedulingShellCallLogs
  • AnonymousFunctionOperation
  • ArrayUtil
  • AssociationIntegrityBehavior
  • AtomicOperation
  • AuthenticationComponent
  • AuthenticationController
  • AuthenticationUser
  • AutocompleteDatasourceComponent
  • BaseModelComponent
  • Basics
  • CakeLayersHelper
  • CheckAndRunShell
  • ClassSearcher
  • CommandLineUtil
  • CommonValidationBehavior
  • ConfigurableShellCallsSchedulingTask
  • ConfigurationKey
  • ConfigurationKeys
  • ConfigurationKeysController
  • Context
  • ContextComponent
  • ContextHelper
  • Contexts
  • ControllerInspector
  • ControllerMenuHelper
  • CreateJournalingTables
  • CreateTableConfigurationKeys
  • CreateTableSchedulingConfigurableShellCalls
  • CreateTableSchedulingShellCallLogs
  • CreateTableSettedConfigurationKeys
  • CreateTableUserResetPasswordRequests
  • CreateTableUsers
  • CronSchedulingInstaller
  • CronValidationBehavior
  • CssBox
  • CssController
  • CssProperties
  • CssShell
  • CsvUtil
  • CustomDataModel
  • DatasourceDumperManager
  • DateTimeInput
  • DependencyShell
  • DetailHelper
  • DumperShell
  • ExtendedFieldsAccessControl
  • ExtendedFieldSet
  • ExtendedFieldSetHelper
  • ExtendedFieldsParser
  • ExtendedFormHelper
  • ExtendedHasManyAppModel
  • ExtendedOperationsBehavior
  • FieldDefinition
  • FieldRowDefinition
  • FieldSetDefinition
  • FieldSetLayoutHelper
  • FileOperations
  • FileOperations_Rename
  • FileOperations_SymLink
  • FileOperations_Touch
  • FileOperations_Unlink
  • FileSystem
  • FixConfigurationKeysPrimaryKey
  • FixSettedConfigurationKeysPrimaryKey
  • HasManyUtilsBehavior
  • HtmlDocument
  • HtmlGrid
  • HtmlGrid_Cell
  • HttpClient
  • HttpResponse
  • ImapClient
  • ImapMailBox
  • ImapParserShell
  • IncludePath
  • InputMasked
  • InputSearchable
  • InputsOnSubmit
  • InstallShell
  • JenkinsBuildShell
  • Journal
  • JournalDetail
  • JournalizedBehavior
  • JsonResponseComponent
  • LayoutsHelper
  • Ldap
  • LdapUtils
  • ListFieldSet
  • ListFieldSetHelper
  • ListsHelper
  • MailParser
  • Make
  • MenuHelper
  • MigrationAllPluginsShell
  • ModelOperations
  • ModelOperations_Delete
  • ModelOperations_Save
  • ModelTraverser
  • MysqlDumper
  • OpenLdapUtils
  • PaginatorUtilComponent
  • PaginatorUtilComponentFilter
  • PaginatorUtilHelper
  • Plugin
  • PluginManager
  • Reflections
  • RenameEnabledToActiveFromUsersTable
  • RunShellCallShell
  • ScaffoldUtilComponent
  • ScaffoldUtilHelper
  • Scheduling
  • SchedulingConfigurableShellCall
  • SchedulingConfigurableShellCallsController
  • SchedulingShellCallLog
  • SchedulingShellCallLogsController
  • SettedConfigurationKey
  • StuffreposPluginsRename
  • TimeZoneBehavior
  • TransactionModel
  • TransactionOperation
  • Translator
  • TranslatorShell
  • User
  • UserAuthenticationComponent
  • UserChangePassword
  • UserResetPassword
  • UserResetPasswordRequest
  • UserResetPasswordRequestSubmission
  • UsersController
  • ViewUtilHelper

Interfaces

  • AccessControlFilter
  • CommitableOperation
  • DatasourceDumper
  • MakeListener
  • SchedulingInstaller
  • TasksObject
  • UndoableOperation

Exceptions

  • LdapObjectNotWritableException
  • ModelTraverserException
  • Overview
  • Namespace
  • Class
  • Tree
  1: <?php
  2: 
  3: App::uses('ClassSearcher', 'Base.Lib');
  4: App::uses('SchedulingTask', 'Scheduling.Lib');
  5: 
  6: /**
  7:  * 
  8:  * interface SchedulingManager {
  9:  *   public function update($shellCalls);
 10:  * }
 11:  * 
 12:  * interface SchedulingTask {  
 13:  * @return array('scheduling' => string, 'shell' => string, args => string[])[]
 14:  *   public function generate();
 15:  * }
 16:  */
 17: class Scheduling {
 18: 
 19:     /**
 20:      * 
 21:      * @return array('scheduling' => string, 'shell' => string, args => string[])[]
 22:      */
 23:     public static function shellCalls() {
 24:         $shellCalls = array();
 25:         foreach (self::_findSchedulingTasksInstances() as $schedulingTask) {
 26:             $shellCalls = array_merge(
 27:                     $shellCalls
 28:                     , self::_generateShellCalls($schedulingTask)
 29:             );
 30:         }
 31:         return $shellCalls;
 32:     }
 33: 
 34:     public static function setNextRun($shellCall) {
 35:         $schedulingShellCallLog = self::findLog($shellCall);
 36:         $cron = Cron\CronExpression::factory($shellCall['scheduling']);
 37:         $schedulingShellCallLog['SchedulingShellCallLog']['next_run'] = $cron->getNextRunDate()->format('Y-m-d H:i:s');
 38:         unset($schedulingShellCallLog['SchedulingShellCallLog']['modified']);
 39:         ClassRegistry::init('Scheduling.SchedulingShellCallLog')->saveOrThrowException($schedulingShellCallLog);
 40:     }
 41: 
 42:     public static function findLog($shellCall) {
 43:         $SchedulingShellCallLog = ClassRegistry::init('Scheduling.SchedulingShellCallLog');
 44:         $schedulingShellCallLog = $SchedulingShellCallLog->find('first', array(
 45:             'conditions' => array(
 46:                 'SchedulingShellCallLog.scheduling' => $shellCall['scheduling'],
 47:                 'SchedulingShellCallLog.args' => self::serializeArgs($shellCall['args']),
 48:                 'SchedulingShellCallLog.shell' => $shellCall['shell'],
 49:             )
 50:         ));
 51:         if (empty($schedulingShellCallLog)) {
 52:             $SchedulingShellCallLog->create();
 53:             $shellCall['args'] = self::serializeArgs($shellCall['args']);
 54:             $SchedulingShellCallLog->saveOrThrowException(array(
 55:                 'SchedulingShellCallLog' => $shellCall
 56:             ));
 57:             return $SchedulingShellCallLog->read();
 58:         } else {
 59:             return $schedulingShellCallLog;
 60:         }
 61:     }
 62: 
 63:     public static function serializeArgs($args) {
 64:         if (is_array($args)) {
 65:             return trim(implode(' ', array_map('escapeshellarg', $args)));
 66:         } else {
 67:             return trim('' . $args);
 68:         }
 69:     }
 70:     
 71:     /**
 72:      * 
 73:      * @return SchedulingInstaller
 74:      * @throws Exception
 75:      */
 76:     public static function getInstaller($schedulingInstallerClass = null) {
 77:         if (!$schedulingInstallerClass) {
 78:             $schedulingInstallerClass = Configure::read('Scheduling.installer_class');
 79:             if (!$schedulingInstallerClass || trim($schedulingInstallerClass) == '') {
 80:                 throw new Exception("Configuration \"Scheduling.installer_class\" not set.");
 81:             }
 82:         }
 83:         return ClassSearcher::findInstanceAndInstantiate('Lib' . DS . 'SchedulingInstaller', $schedulingInstallerClass);
 84:     }
 85: 
 86:     private static function _generateShellCalls($schedulingTask) {
 87:         $shellCalls = array();
 88:         foreach($schedulingTask->generate() as $shellCall) {
 89:             if (empty($shellCall['args'])) {
 90:                 $shellCall['args'] = array();
 91:             }
 92:             $shellCalls[] = $shellCall;
 93:         }
 94:         return $shellCalls;
 95:     }
 96: 
 97:     /**
 98:      * @return SchedulingTask[]
 99:      */
100:     private static function _findSchedulingTasksInstances() {
101:         return ClassSearcher::findInstances('Lib' . DS . 'SchedulingTask');
102:     }
103: 
104: }
API documentation generated by ApiGen 2.8.0