moves cronuser creation fns to abstract cli frontend
authorPhilipp Schüle <p.schuele@metaways.de>
Sat, 25 Mar 2017 18:10:17 +0000 (19:10 +0100)
committerPhilipp Schüle <p.schuele@metaways.de>
Mon, 27 Mar 2017 07:49:36 +0000 (09:49 +0200)
Change-Id: Ic71dd2a6d04dd951d806f4fd30710d5445ed5334
Reviewed-on: http://gerrit.tine20.com/customers/4426
Tested-by: Jenkins CI (http://ci.tine20.com/)
Reviewed-by: Philipp Schüle <p.schuele@metaways.de>
tine20/Tinebase/Frontend/Cli.php
tine20/Tinebase/Frontend/Cli/Abstract.php

index 80fb1b3..0a11537 100644 (file)
@@ -363,59 +363,8 @@ class Tinebase_Frontend_Cli extends Tinebase_Frontend_Cli_Abstract
         
         return true;
     }
-    
-    /**
-     * try to get user for cronjob from config
-     * 
-     * @return Tinebase_Model_FullUser
-     */
-    protected function _getCronuserFromConfigOrCreateOnTheFly()
-    {
-        try {
-            $cronuserId = Tinebase_Config::getInstance()->get(Tinebase_Config::CRONUSERID);
-            if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Setting user with id ' . $cronuserId . ' as cronuser.');
-            $cronuser = Tinebase_User::getInstance()->getUserByPropertyFromSqlBackend('accountId', $cronuserId, 'Tinebase_Model_FullUser');
-            try {
-                Tinebase_User::getInstance()->assertAdminGroupMembership($cronuser);
-            } catch (Exception $e) {
-                Tinebase_Exception::log($e);
-            }
-        } catch (Tinebase_Exception_NotFound $tenf) {
-            if (Tinebase_Core::isLogLevel(Zend_Log::NOTICE)) Tinebase_Core::getLogger()->notice(__METHOD__ . '::' . __LINE__ . ' ' . $tenf->getMessage());
-            
-            $cronuser = $this->_createCronuser();
-            Tinebase_Config::getInstance()->set(Tinebase_Config::CRONUSERID, $cronuser->getId());
-        }
-        
-        return $cronuser;
-    }
 
     /**
-     * create new cronuser
-     * 
-     * @return Tinebase_Model_FullUser
-     */
-    protected function _createCronuser()
-    {
-        if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ .' Creating new cronuser.');
-        
-        $adminGroup = Tinebase_Group::getInstance()->getDefaultAdminGroup();
-        $cronuser = new Tinebase_Model_FullUser(array(
-            'accountLoginName'      => 'cronuser',
-            'accountStatus'         => Tinebase_Model_User::ACCOUNT_STATUS_DISABLED,
-            'visibility'            => Tinebase_Model_FullUser::VISIBILITY_HIDDEN,
-            'accountPrimaryGroup'   => $adminGroup->getId(),
-            'accountLastName'       => 'cronuser',
-            'accountDisplayName'    => 'cronuser',
-            'accountExpires'        => NULL,
-        ));
-        $cronuser = Tinebase_User::getInstance()->addUser($cronuser);
-        Tinebase_Group::getInstance()->addGroupMember($cronuser->accountPrimaryGroup, $cronuser->getId());
-        
-        return $cronuser;
-    }
-    
-    /**
      * process given queue job
      *  --message json encoded task
      *
index c084357..1b18e33 100644 (file)
@@ -521,4 +521,55 @@ class Tinebase_Frontend_Cli_Abstract
             $logger->ERR(__METHOD__ . '::' . __LINE__ . " import for {$this->_applicationName} failed ". $e->getMessage());
         }
     }
+
+    /**
+     * try to get user for cronjob from config
+     *
+     * @return Tinebase_Model_FullUser
+     */
+    protected function _getCronuserFromConfigOrCreateOnTheFly()
+    {
+        try {
+            $cronuserId = Tinebase_Config::getInstance()->get(Tinebase_Config::CRONUSERID);
+            if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Setting user with id ' . $cronuserId . ' as cronuser.');
+            $cronuser = Tinebase_User::getInstance()->getUserByPropertyFromSqlBackend('accountId', $cronuserId, 'Tinebase_Model_FullUser');
+            try {
+                Tinebase_User::getInstance()->assertAdminGroupMembership($cronuser);
+            } catch (Exception $e) {
+                Tinebase_Exception::log($e);
+            }
+        } catch (Tinebase_Exception_NotFound $tenf) {
+            if (Tinebase_Core::isLogLevel(Zend_Log::NOTICE)) Tinebase_Core::getLogger()->notice(__METHOD__ . '::' . __LINE__ . ' ' . $tenf->getMessage());
+
+            $cronuser = $this->_createCronuser();
+            Tinebase_Config::getInstance()->set(Tinebase_Config::CRONUSERID, $cronuser->getId());
+        }
+
+        return $cronuser;
+    }
+
+    /**
+     * create new cronuser
+     *
+     * @return Tinebase_Model_FullUser
+     */
+    protected function _createCronuser()
+    {
+        if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ .' Creating new cronuser.');
+
+        $adminGroup = Tinebase_Group::getInstance()->getDefaultAdminGroup();
+        $cronuser = new Tinebase_Model_FullUser(array(
+            'accountLoginName'      => 'cronuser',
+            'accountStatus'         => Tinebase_Model_User::ACCOUNT_STATUS_DISABLED,
+            'visibility'            => Tinebase_Model_FullUser::VISIBILITY_HIDDEN,
+            'accountPrimaryGroup'   => $adminGroup->getId(),
+            'accountLastName'       => 'cronuser',
+            'accountDisplayName'    => 'cronuser',
+            'accountExpires'        => NULL,
+        ));
+        $cronuser = Tinebase_User::getInstance()->addUser($cronuser);
+        Tinebase_Group::getInstance()->addGroupMember($cronuser->accountPrimaryGroup, $cronuser->getId());
+
+        return $cronuser;
+    }
 }