Merge branch '2016.11' into 2016.11-develop
authorPhilipp Schüle <p.schuele@metaways.de>
Mon, 27 Mar 2017 10:22:00 +0000 (12:22 +0200)
committerPhilipp Schüle <p.schuele@metaways.de>
Mon, 27 Mar 2017 10:22:00 +0000 (12:22 +0200)
Change-Id: I91a637a18b479e932f0b2f93ad3586abab538e39

1  2 
tests/tine20/Addressbook/JsonTest.php
tests/tine20/Felamimail/Frontend/JsonTest.php
tine20/Tinebase/Container.php
tine20/Tinebase/Controller/Abstract.php
tine20/Tinebase/Controller/Record/Abstract.php
tine20/Tinebase/Core.php
tine20/Tinebase/Frontend/Cli.php
tine20/Tinebase/Frontend/Cli/Abstract.php
tine20/Tinebase/User/Sql.php

Simple merge
Simple merge
@@@ -336,15 -333,16 +336,20 @@@ abstract class Tinebase_Controller_Abst
       */
      protected function _getModelsFromAppDir()
      {
+         $modelsDir = dirname(dirname(dirname(__FILE__))) . '/' . $this->_applicationName . '/Model/';
+         if (! file_exists($modelsDir)) {
+             return null;
+         }
+         
          try {
 -            $dir = new DirectoryIterator($modelsDir);
 +            $modelDir = dirname(dirname(dirname(__FILE__))) . '/' . $this->_applicationName . '/Model/';
 +            if (! file_exists($modelDir)) {
 +                return array();
 +            }
 +            $dir = new DirectoryIterator($modelDir);
          } catch (Exception $e) {
              Tinebase_Exception::log($e);
 -            return null;
 +            return array();
          }
  
          $models = array();
@@@ -2244,10 -2170,11 +2244,11 @@@ abstract class Tinebase_Controller_Reco
      }
  
      /**
+ <<<<<<< HEAD
       * returns path of record
       *
 -     * @param     $record
 -     * @param int $depth
 +     * @param Tinebase_Record_Interface     $record
 +     * @param boolean|int                   $depth
       * @return Tinebase_Record_RecordSet
       * @throws Tinebase_Exception_Record_NotAllowed
       * @throws Tinebase_Exception
Simple merge
@@@ -372,7 -342,10 +372,7 @@@ class Tinebase_Frontend_Cli extends Tin
          }
          
          $userController = Tinebase_User::getInstance();
 -        
 -        // deactivate user plugins (like postfix/dovecot email backends) for async job user
 -        $userController->unregisterAllPlugins();
--        
++
          try {
              $cronuser = $userController->getFullUserByLoginName($_opts->username);
          } catch (Tinebase_Exception_NotFound $tenf) {
@@@ -525,4 -521,55 +525,34 @@@ class Tinebase_Frontend_Cli_Abstrac
              $logger->ERR(__METHOD__ . '::' . __LINE__ . " import for {$this->_applicationName} failed ". $e->getMessage());
          }
      }
 -            if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Setting user with id ' . $cronuserId . ' as cronuser.');
+     /**
+      * 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::NOTICE)) Tinebase_Core::getLogger()->notice(__METHOD__ . '::' . __LINE__ . ' ' . $tenf->getMessage());
++            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) {
 -            $cronuser = $this->_createCronuser();
 -            Tinebase_Config::getInstance()->set(Tinebase_Config::CRONUSERID, $cronuser->getId());
++            if (Tinebase_Core::isLogLevel(Zend_Log::NOTICE)) Tinebase_Core::getLogger()->notice(__METHOD__ . '::' . __LINE__
++                . ' ' . $tenf->getMessage());
 -
 -    /**
 -     * 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;
 -    }
++            $cronuser = Tinebase_User::createSystemUser('cronuser');
++            if ($cronuser) {
++                Tinebase_Config::getInstance()->set(Tinebase_Config::CRONUSERID, $cronuser->getId());
++            }
+         }
+         return $cronuser;
+     }
  }
@@@ -188,7 -156,7 +188,7 @@@ class Tinebase_User_Sql extends Tinebas
          }
  
          $select->where($this->_db->quoteIdentifier($this->_db->table_prefix . $this->_tableName . '.' . 'is_deleted') . ' = 0');
--        
++
          $stmt = $select->query();
          $rows = $stmt->fetchAll(Zend_Db::FETCH_ASSOC);
          
          }
  
          $select->where($this->_db->table_prefix . $this->_tableName . '.' . $this->_db->quoteIdentifier('is_deleted') . ' = 0');
--        
++
          $stmt = $select->query();
          $rows = $stmt->fetchAll(Zend_Db::FETCH_COLUMN);
          
              . ' ' . $_status . ' user with id ' . $accountId);
  
          $result = $accountsTable->update($accountData, $where);
 -        
 +
 +        $oldUser = new Tinebase_Model_FullUser(array('accountId' => $accountId), true);
 +        $newUser = new Tinebase_Model_FullUser(array('accountId' => $accountId, 'accountStatus' => $_status), true);
 +        $this->_writeModLog($newUser, $oldUser);
-         
++
          return $result;
      }
  
          );
          
          $result = $accountsTable->update($accountData, $where);
 -        
 +
 +        $oldUser = new Tinebase_Model_FullUser(array('accountId' => $accountId), true);
 +        $newUser = new Tinebase_Model_FullUser(array('accountId' => $accountId, 'accountExpires' => $accountData['expires_at']), true);
 +        $this->_writeModLog($newUser, $oldUser);
-         
++
          return $result;
      }
      
          
          $updatedUser = $this->updateUserInSqlBackend($_user);
          $this->updatePluginUser($updatedUser, $_user);
 -        
 +
 +        $contactId = $updatedUser->contact_id;
 +        if (!empty($visibility) && !empty($contactId) && $visibility != $updatedUser->visibility) {
 +            $updatedUser->visibility = $visibility;
 +            $updatedUser = $this->updateUserInSqlBackend($updatedUser);
 +            $this->updatePluginUser($updatedUser, $_user);
 +        }
-         
++
          return $updatedUser;
      }
      
                  $_user->setId($userFromSyncBackend->getId());
              }
          }
 -        
 +
          $addedUser = $this->addUserInSqlBackend($_user);
          $this->addPluginUser($addedUser, $_user);
 -        
 +
 +        $contactId = $addedUser->contact_id;
 +        if (!empty($visibility) && !empty($contactId) && $visibility != $addedUser->visibility) {
 +            $addedUser->visibility = $visibility;
 +            $addedUser = $this->updateUserInSqlBackend($addedUser);
 +            $this->updatePluginUser($addedUser, $_user);
 +        }
-         
++
          return $addedUser;
      }
      
          if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Adding user to SQL backend: ' . $_user->accountLoginName);
          
          $accountsTable->insert($accountData);
 -            
 +
 +        $this->_writeModLog($_user, null);
-             
++
          return $this->getUserById($_user->getId(), 'Tinebase_Model_FullUser');
      }
      
              . ' Deleting user' . $user->accountLoginName);
  
          $transactionId = Tinebase_TransactionManager::getInstance()->startTransaction($this->_db);
--        
++
          try {
  
              $accountsTable          = new Tinebase_Db_Table(array('name' => SQL_TABLE_PREFIX . 'accounts'));
              Tinebase_TransactionManager::getInstance()->rollBack();
              throw($e);
          }
--        
++
          return $user;
      }
--    
++
      /**
       * delete users
       *