Merge branch '2016.11' into 2016.11-develop
authorjenkins <tine20-jenkins@metaways.de>
Mon, 7 Aug 2017 11:04:12 +0000 (13:04 +0200)
committerjenkins <tine20-jenkins@metaways.de>
Mon, 7 Aug 2017 11:04:12 +0000 (13:04 +0200)
1  2 
tine20/Tinebase/ActionQueue.php

   *
   * @package     Tinebase
   * @subpackage  ActionQueue
 + *
 + * @method int getQueueSize()
 + * @method int waitForJob()
 + * @method string receive(integer $jobId)
 + * @method void delete(integer $jobId)
 + *
   */
   class Tinebase_ActionQueue implements Tinebase_Controller_Interface
   {
      {
          $options = null;
          $backend = self::BACKEND_DIRECT;
 -        
 -        if (isset(Tinebase_Core::getConfig()->actionqueue) && Tinebase_Core::getConfig()->actionqueue->active) {
 -            $options = Tinebase_Core::getConfig()->actionqueue->toArray();
 +        $config = Tinebase_Core::getConfig()->{Tinebase_Config::ACTIONQUEUE};
 +
 +        /** @noinspection PhpUndefinedFieldInspection */
 +        if ($config && isset($config->{Tinebase_Config::ACTIONQUEUE_BACKEND}) && $config->{Tinebase_Config::ACTIONQUEUE_ACTIVE}) {
 +            /** @noinspection PhpUndefinedFieldInspection */
 +            $options = $config->toArray();
              
 -            $backend = (isset($options['backend']) || array_key_exists('backend', $options)) ? ucfirst(strtolower($options['backend'])) : $backend;
 -            unset($options['backend']);
 +            $backend = (isset($options[Tinebase_Config::ACTIONQUEUE_BACKEND]) || array_key_exists(Tinebase_Config::ACTIONQUEUE_BACKEND, $options)) ? ucfirst(strtolower($options[Tinebase_Config::ACTIONQUEUE_BACKEND])) : $backend;
 +            unset($options[Tinebase_Config::ACTIONQUEUE_BACKEND]);
 +            unset($options[Tinebase_Config::ACTIONQUEUE_ACTIVE]);
          }
          
          $className = 'Tinebase_ActionQueue_Backend_' . $backend;
              throw new Tinebase_Exception_UnexpectedValue('backend does not implement Tinebase_ActionQueue_Backend_Interface');
          }
      }
 -    
 -    /**
 -     * execute action defined in queue message
 -     * 
 -     * @param  array  $message  action
 -     * @return mixed
 -     */
 +
 +     /**
 +      * execute action defined in queue message
 +      *
 +      * @param  array $message action
 +      * @return mixed
 +      * @throws Tinebase_Exception_AccessDenied
 +      * @throws Tinebase_Exception_NotFound
 +      */
      public function executeAction($message)
      {
          if (! is_array($message) || ! (isset($message['action']) || array_key_exists('action', $message)) || strpos($message['action'], '.') === FALSE) {
          }
  
          if (Tinebase_Core::isLogLevel(Zend_Log::INFO)) Tinebase_Core::getLogger()->info(
 -            __METHOD__ . '::' . __LINE__ . " executing action: '{$message['action']}'");
 +            __LINE__ . '::' . __METHOD__ . " executing action: '{$message['action']}'");
          
          list($appName, $actionName) = explode('.', $message['action']);
          $controller = Tinebase_Core::getApplicationInstance($appName);
              $this->delete($jobId);
          }
      }
 -    
 -    /**
 +
 +     /** @noinspection PhpDocSignatureInspection */
 +     /**
       * queues an action
 -     * 
 +     *
       * @param string $_action
       * @param mixed  $_arg1
       * @param mixed  $_arg2
      {
          $params = func_get_args();
          $action = array_shift($params);
+         $user = Tinebase_Core::getUser();
+         if (! is_object($user)) {
+             if (Tinebase_Core::isLogLevel(Zend_Log::ERR)) Tinebase_Core::getLogger()->err(
+                 __METHOD__ . '::' . __LINE__ . " Not Queueing action: '{$action}' because no valid user object found");
+             return null;
+         }
          $message = array(
              'action'     => $action,
-             'account_id' => Tinebase_Core::getUser()->getId(),
+             'account_id' => $user->getId(),
              'params'     => $params
          );