Example #1
0
 /**
  *
  * @return Conjoon_Builder
  */
 private function _getBuilder()
 {
     if (!$this->_builder) {
         /**
          * @see Conjoon_Keys
          */
         require_once 'Conjoon/Keys.php';
         /**
          * @see Conjoon_Builder_Factory
          */
         require_once 'Conjoon/Builder/Factory.php';
         $this->_builder = Conjoon_Builder_Factory::getBuilder(Conjoon_Keys::CACHE_FEED_ITEM, Zend_Registry::get(Conjoon_Keys::REGISTRY_CONFIG_OBJECT)->toArray(), $this->_getItemModel());
     }
     return $this->_builder;
 }
Example #2
0
 /**
  * @return Conjoon_Modules_Groupware_Email_Message_Builder
  */
 private function _getBuilder()
 {
     if (!$this->_builder) {
         /**
          * @see Conjoon_Builder_Factory
          */
         require_once 'Conjoon/Builder/Factory.php';
         $this->_builder = Conjoon_Builder_Factory::getBuilder(Conjoon_Keys::CACHE_EMAIL_MESSAGE, Zend_Registry::get(Conjoon_Keys::REGISTRY_CONFIG_OBJECT)->toArray(), $this->_getMessageModel());
     }
     return $this->_builder;
 }
Example #3
0
 /**
  * @return Conjoon_Modules_Groupware_Email_Folder_FolderRootTypeBuilder
  */
 private function _getFolderRootTypeBuilder()
 {
     if (!$this->_folderRootTypeBuilder) {
         /**
          * @see Conjoon_Builder_Factory
          */
         require_once 'Conjoon/Builder/Factory.php';
         /**
          * @see Conjoon_Keys
          */
         require_once 'Conjoon/Keys.php';
         $this->_folderRootTypeBuilder = Conjoon_Builder_Factory::getBuilder(Conjoon_Keys::CACHE_EMAIL_FOLDERS_ROOT_TYPE, Zend_Registry::get(Conjoon_Keys::REGISTRY_CONFIG_OBJECT)->toArray(), $this->_getFolderModel());
     }
     return $this->_folderRootTypeBuilder;
 }
 /**
  * This action will update email accounts according to the POST params
  * that come along with the request.
  * Depending of the current context the action was called, the format of the
  * POST params will differ: For json, it will be an array holding json-encoded parameters.
  * Despite all different formats the POST params may come in, each request sends
  * values for 'updated' and 'deleted' accounts: 'deleted' as an array, holding all
  * ids that should become deleted, and 'updated' an array holding information about
  * the records that get edited, represented by specific associative array, representing
  * the fields of the record.
  * The view will await values assigned to 'updated_failed' and 'deleted_failed', whereas
  * 'deleted_failed' is an array containing all ids that couldn't be deleted, and
  * 'updated_failed' an array containing the records (in associative array notation)
  * that could not be updated.
  *
  * Note: If any error in the user-input was detected, no update-action will happen, but
  * deltes may already have been submitted to the underlying datastore.
  * The first error found in the passed data will be returned as an error of the type
  * Conjoon_Error_Form, containing the fields that where errorneous.
  *
  */
 public function updateEmailAccountsAction()
 {
     require_once 'Conjoon/Modules/Groupware/Email/Account/Filter/Account.php';
     require_once 'Conjoon/Util/Array.php';
     require_once 'Conjoon/Modules/Groupware/Email/Account/Model/Account.php';
     $toDelete = array();
     $toUpdate = array();
     $deletedFailed = array();
     $updatedFailed = array();
     $model = new Conjoon_Modules_Groupware_Email_Account_Model_Account();
     $data = array();
     $error = null;
     if ($this->_helper->conjoonContext()->getCurrentContext() == self::CONTEXT_JSON) {
         require_once 'Zend/Json.php';
         $toDelete = Zend_Json::decode($_POST['deleted'], Zend_Json::TYPE_ARRAY);
         $toUpdate = Zend_Json::decode($_POST['updated'], Zend_Json::TYPE_ARRAY);
     }
     $numToUpdate = count($toUpdate);
     $numToDelete = count($toDelete);
     if ($numToUpdate != 0 || $numToDelete != 0) {
         /**
          * @see Conjoon_Builder_Factory
          */
         require_once 'Conjoon/Builder/Factory.php';
         Conjoon_Builder_Factory::getBuilder(Conjoon_Keys::CACHE_EMAIL_ACCOUNTS, Zend_Registry::get(Conjoon_Keys::REGISTRY_CONFIG_OBJECT)->toArray())->cleanCacheForTags(array('userId' => Zend_Registry::get(Conjoon_Keys::REGISTRY_AUTH_OBJECT)->getIdentity()->getId()));
     }
     $userId = $this->_helper->registryAccess()->getUserId();
     for ($i = 0; $i < $numToDelete; $i++) {
         $affected = $model->deleteAccount($toDelete[$i], $userId);
         if ($affected == 0) {
             $deletedFailed[] = $toDelete[$i];
         }
     }
     $folderMappingData = array();
     for ($i = 0; $i < $numToUpdate; $i++) {
         $_ = $toUpdate[$i];
         $folderMappingData[$toUpdate[$i]['id']] = $toUpdate[$i]['folderMappings'];
         $filter = new Conjoon_Modules_Groupware_Email_Account_Filter_Account($_, Conjoon_Filter_Input::CONTEXT_UPDATE);
         try {
             $data[$i] = $filter->getProcessedData();
             Conjoon_Util_Array::underscoreKeys($data[$i]);
         } catch (Zend_Filter_Exception $e) {
             require_once 'Conjoon/Error.php';
             $error = Conjoon_Error::fromFilter($filter, $e);
             $this->view->success = false;
             $this->view->updatedFailed = array($_['id']);
             $this->view->deletedFailed = $deletedFailed;
             $this->view->error = $error->getDto();
             return;
         }
     }
     $createdLocalRootMailFolders = array();
     $removedLocalRootMailFolders = array();
     /**
      * @see Conjoon_BeanContext_Decorator
      */
     require_once 'Conjoon/BeanContext/Decorator.php';
     $decoratedFolderModel = new Conjoon_BeanContext_Decorator('Conjoon_Modules_Groupware_Email_Folder_Model_Folder', null, false);
     $decoratedAccountModel = new Conjoon_BeanContext_Decorator('Conjoon_Modules_Groupware_Email_Account_Model_Account');
     /**
      * @see Conjoon_Modules_Groupware_Email_Folder_Model_Folder
      */
     require_once 'Conjoon/Modules/Groupware/Email/Folder/Model/Folder.php';
     $folderModel = new Conjoon_Modules_Groupware_Email_Folder_Model_Folder();
     /**
      * @see Conjoon_Modules_Groupware_Email_Folder_Model_FoldersAccounts
      */
     require_once 'Conjoon/Modules/Groupware/Email/Folder/Model/FoldersAccounts.php';
     $foldersAccounts = new Conjoon_Modules_Groupware_Email_Folder_Model_FoldersAccounts();
     for ($i = 0, $len = count($data); $i < $len; $i++) {
         $id = $data[$i]['id'];
         unset($data[$i]['id']);
         // check here for duplicates
         $duplicates = $model->getAccountWithNameForUser($data[$i]['name'], $userId);
         $affected = 0;
         if (!empty($duplicates)) {
             for ($a = 0, $lena = count($duplicates); $a < $lena; $a++) {
                 if ($duplicates[$a]['id'] != $id) {
                     $affected = -1;
                     break;
                 }
             }
         }
         if ($affected != -1) {
             $affected = $model->updateAccount($id, $data[$i]);
             $entityManager = Zend_Registry::get(Conjoon_Keys::DOCTRINE_ENTITY_MANAGER);
             // update folderMappings
             if (isset($folderMappingData[$id])) {
                 $fmRep = $entityManager->getRepository('\\Conjoon\\Data\\Entity\\Mail\\DefaultFolderMappingEntity');
                 for ($u = 0, $lenu = count($folderMappingData[$id]); $u < $lenu; $u++) {
                     if (isset($folderMappingData[$id][$u]['id']) && empty($folderMappingData[$id][$u]['path'])) {
                         $updEnt = $fmRep->findById($folderMappingData[$id][$u]['id']);
                         $updEnt->setGlobalName("");
                         $fmRep->register($updEnt);
                     } else {
                         if (isset($folderMappingData[$id][$u]['id']) && !empty($folderMappingData[$id][$u]['path'])) {
                             /**
                              * @see \Conjoon\Data\Entity\Mail\DefaultFolderMappingEntity
                              */
                             require_once 'Conjoon/Data/Entity/Mail/DefaultFolderMappingEntity.php';
                             /**
                              * @see Conjoon_Modules_Groupware_Email_ImapHelper
                              */
                             require_once 'Conjoon/Modules/Groupware/Email/ImapHelper.php';
                             $accDto = $decoratedAccountModel->getAccountAsDto($id, $userId);
                             $delim = Conjoon_Modules_Groupware_Email_ImapHelper::getFolderDelimiterForImapAccount($accDto);
                             $p = $folderMappingData[$id][$u]['path'];
                             array_shift($p);
                             array_shift($p);
                             $globalName = implode($delim, $p);
                             $updEnt = $fmRep->findById($folderMappingData[$id][$u]['id']);
                             $updEnt->setGlobalName($globalName);
                             $fmRep->register($updEnt);
                             continue;
                         }
                     }
                 }
                 $fmRep->flush();
             }
             // take care of folder heirarchies
             if ($affected != -1) {
                 /**
                  * @todo Facade
                  */
                 $hasSeparateFolderHierarchy = array_key_exists('has_separate_folder_hierarchy', $data[$i]) ? (bool) (int) $data[$i]['has_separate_folder_hierarchy'] : null;
                 // get org protocol of account so it cannot be changed from
                 // the outside
                 $orgAccount = $model->getAccount($id, $userId);
                 $orgProtocol = $orgAccount['protocol'];
                 if ($hasSeparateFolderHierarchy !== null && strtolower($orgProtocol) !== 'imap') {
                     // the original folder ids, before remapping occures
                     $oldAccountFolderIds = $foldersAccounts->getFolderIdsForAccountId($id);
                     // read out folder base data of folder for associated account
                     $rootFolderBaseData = $decoratedFolderModel->getAnyRootMailFolderBaseDataAsDto($id, $userId);
                     if (!$rootFolderBaseData) {
                         throw new RuntimeException("No root folder base data available.");
                     }
                     if (!$hasSeparateFolderHierarchy) {
                         // do nothing if type is already accounts_root and
                         // separateFolderHierarchy = false is submitted;
                         // but if the type is root and the folderHierarchy
                         // (i.e. "root) should be removed,
                         // we need to switch from root to accounts_root
                         if ($rootFolderBaseData->type == 'root') {
                             // check first if accounts_root exist!
                             $accountsRootFolderId = $folderModel->getAccountsRootMailFolderBaseData($userId);
                             // accounts root not yet existing
                             if (!$accountsRootFolderId) {
                                 $folderModel->createFolderBaseHierarchyAndMapAccountIdForUserId($id, $userId);
                             } else {
                                 $newFolderIds = $folderModel->getFoldersForAccountsRoot($userId);
                                 // accounts root already existing.
                                 // remove the root and remap to accounts_root
                                 foreach ($oldAccountFolderIds as $oldFolderId) {
                                     $folderModel->deleteFolder($oldFolderId, $userId, false);
                                 }
                                 $removedLocalRootMailFolders[$id] = $rootFolderBaseData;
                                 $foldersAccounts->mapFolderIdsToAccountId($newFolderIds, $id);
                             }
                             $createdLocalRootMailFolders[$id] = $decoratedFolderModel->getAnyRootMailFolderBaseDataAsDto($id, $userId);
                         }
                     } else {
                         // do nothing if the type is already root which means
                         // there already exists a separate folder hierarchy
                         // if the type is accounts_root, we need to switch
                         // to a root hierarchy
                         if ($rootFolderBaseData->type == 'accounts_root') {
                             // remove old mappings
                             $foldersAccounts->deleteForAccountId($id);
                             $folderModel->createFolderHierarchyAndMapAccountIdForUserId($id, $userId, $data[$i]['name']);
                             $createdLocalRootMailFolders[$id] = $decoratedFolderModel->getAnyRootMailFolderBaseDataAsDto($id, $userId);
                         }
                     }
                 }
             }
         }
         if ($affected == -1) {
             $updatedFailed[] = $id;
         }
     }
     $this->view->success = empty($updatedFailed) ? true : false;
     $this->view->updatedFailed = $updatedFailed;
     $this->view->deletedFailed = $deletedFailed;
     $this->view->error = null;
     $this->view->createdLocalRootMailFolders = $createdLocalRootMailFolders;
     $this->view->removedLocalRootMailFolders = $removedLocalRootMailFolders;
 }
 /**
  * Updates an account based on the given data.
  * Data to be updated will be available in a numeric indexed array "data",
  * whereas each value is an assoc array with the following fields:
  *  - id
  *  - name
  *  - password
  *  - updateInterval
  *
  * The field "id" is mandatory. Successfully updated indexes of accounts must
  * be send back in a property "updated", whereas data which cannot be updated must
  * be send back in a property called "failed" (each value in this array is the id
  * of the account which could not be updated).
  * The "success" property has to be set to "false" as soon as one account could
  * not be updated.
  *
  */
 public function updateAccountAction()
 {
     $data = $this->_request->getParam('data');
     /**
      * @see Conjoon_Modules_Service_Twitter_Account_Filter_Account
      */
     require_once 'Conjoon/Modules/Service/Twitter/Account/Filter/Account.php';
     /**
      * @see Conjoon_Modules_Service_Twitter_Account_Model_Account
      */
     require_once 'Conjoon/Modules/Service/Twitter/Account/Model/Account.php';
     $model = new Conjoon_Modules_Service_Twitter_Account_Model_Account();
     $filter = new Conjoon_Modules_Service_Twitter_Account_Filter_Account(array(), Conjoon_Modules_Service_Twitter_Account_Filter_Account::CONTEXT_UPDATE);
     $updated = array();
     $failed = array();
     for ($i = 0, $len = count($data); $i < $len; $i++) {
         $filter->setData($data[$i]);
         $upData = $filter->getProcessedData();
         $id = $upData['id'];
         unset($upData['id']);
         // no data left? skip, mark account as succesfully updated
         if (empty($upData)) {
             $updated[] = $id;
             continue;
         }
         $res = $model->updateAccountForId($upData, $id);
         if (!$res) {
             $failed[] = $id;
         } else {
             $updated[] = $id;
         }
     }
     if (count($updated)) {
         /**
          * @see Conjoon_Builder_Factory
          */
         require_once 'Conjoon/Builder/Factory.php';
         Conjoon_Builder_Factory::getBuilder(Conjoon_Keys::CACHE_TWITTER_ACCOUNTS, Zend_Registry::get(Conjoon_Keys::REGISTRY_CONFIG_OBJECT)->toArray())->remove(array('userId' => $this->_helper->registryAccess()->getUserId()));
     }
     $this->view->success = count($failed) == 0;
     $this->view->failed = $failed;
     $this->view->updated = $updated;
 }