Beispiel #1
0
 public function getImplementation($scope)
 {
     if (empty($this->implementationHashMap[$scope])) {
         $normalizedName = Util::normilizeClassName($scope);
         $className = '\\Espo\\Custom\\AclPortal\\' . $normalizedName;
         if (!class_exists($className)) {
             $moduleName = $this->getMetadata()->getScopeModuleName($scope);
             if ($moduleName) {
                 $className = '\\Espo\\Modules\\' . $moduleName . '\\AclPortal\\' . $normalizedName;
             } else {
                 $className = '\\Espo\\AclPortal\\' . $normalizedName;
             }
             if (!class_exists($className)) {
                 $className = '\\Espo\\Core\\AclPortal\\Base';
             }
         }
         if (class_exists($className)) {
             $acl = new $className($scope);
             $dependencies = $acl->getDependencyList();
             foreach ($dependencies as $name) {
                 $acl->inject($name, $this->getContainer()->get($name));
             }
             $this->implementationHashMap[$scope] = $acl;
         } else {
             throw new Error();
         }
     }
     return $this->implementationHashMap[$scope];
 }
Beispiel #2
0
 protected function getNotificator($entityType)
 {
     if (empty($this->notifatorsHash[$entityType])) {
         $normalizedName = Util::normilizeClassName($entityType);
         $className = '\\Espo\\Custom\\Notificators\\' . $normalizedName;
         if (!class_exists($className)) {
             $moduleName = $this->getMetadata()->getScopeModuleName($entityType);
             if ($moduleName) {
                 $className = '\\Espo\\Modules\\' . $moduleName . '\\Notificators\\' . $normalizedName;
             } else {
                 $className = '\\Espo\\Notificators\\' . $normalizedName;
             }
             if (!class_exists($className)) {
                 $className = '\\Espo\\Core\\Notificators\\Base';
             }
         }
         $notificator = new $className();
         $dependencies = $notificator->getDependencyList();
         foreach ($dependencies as $name) {
             $notificator->inject($name, $this->getContainer()->get($name));
         }
         $this->notifatorsHash[$entityType] = $notificator;
     }
     return $this->notifatorsHash[$entityType];
 }
Beispiel #3
0
 protected function load($fieldName, $entityName)
 {
     $subList = array('first' . ucfirst($fieldName), ' ', 'last' . ucfirst($fieldName));
     $tableName = Util::toUnderScore($entityName);
     $orderByField = 'first' . ucfirst($fieldName);
     // TODO available in settings
     $fullList = array();
     $fullListReverse = array();
     $fieldList = array();
     $like = array();
     $equal = array();
     foreach ($subList as $subFieldName) {
         $fieldNameTrimmed = trim($subFieldName);
         if (!empty($fieldNameTrimmed)) {
             $columnName = $tableName . '.' . Util::toUnderScore($fieldNameTrimmed);
             $fullList[] = $fieldList[] = $columnName;
             $like[] = $columnName . " LIKE {value}";
             $equal[] = $columnName . " = {value}";
         } else {
             $fullList[] = "'" . $subFieldName . "'";
         }
     }
     $fullListReverse = array_reverse($fullList);
     return array($entityName => array('fields' => array($fieldName => array('type' => 'varchar', 'select' => $this->getSelect($fullList), 'where' => array('LIKE' => "(" . implode(" OR ", $like) . " OR CONCAT(" . implode(", ", $fullList) . ") LIKE {value} OR CONCAT(" . implode(", ", $fullListReverse) . ") LIKE {value})", '=' => "(" . implode(" OR ", $equal) . " OR CONCAT(" . implode(", ", $fullList) . ") = {value} OR CONCAT(" . implode(", ", $fullListReverse) . ") = {value})"), 'orderBy' => '' . $tableName . '.' . Util::toUnderScore($orderByField) . ' {direction}'))));
 }
Beispiel #4
0
 protected function load($linkName, $entityName)
 {
     $parentRelation = parent::load($linkName, $entityName);
     $relation = array($entityName => array('fields' => array($linkName . 'Types' => array('type' => 'jsonObject', 'notStorable' => true))));
     $relation = \Espo\Core\Utils\Util::merge($parentRelation, $relation);
     return $relation;
 }
Beispiel #5
0
 public function get($scope, $name)
 {
     $scope = $this->sanitizeInput($scope);
     $name = $this->sanitizeInput($name);
     if (isset($this->changedData[$scope][$name])) {
         return Json::encode($this->changedData[$scope][$name]);
     }
     $fileFullPath = Util::concatPath($this->getLayoutPath($scope, true), 'portal/' . $name . '.json');
     if (!file_exists($fileFullPath)) {
         $fileFullPath = Util::concatPath($this->getLayoutPath($scope), 'portal/' . $name . '.json');
     }
     if (!file_exists($fileFullPath)) {
         $fileFullPath = Util::concatPath($this->getLayoutPath($scope, true), $name . '.json');
     }
     if (!file_exists($fileFullPath)) {
         $fileFullPath = Util::concatPath($this->getLayoutPath($scope), $name . '.json');
     }
     if (!file_exists($fileFullPath)) {
         $defaultPath = $this->params['defaultsPath'];
         $fileFullPath = Util::concatPath(Util::concatPath($defaultPath, 'layouts'), $name . '.json');
         if (!file_exists($fileFullPath)) {
             return false;
         }
     }
     return $this->getFileManager()->getContents($fileFullPath);
 }
Beispiel #6
0
 protected function load($fieldName, $entityName)
 {
     $foreignField = $this->getForeignField($fieldName, $entityName);
     $tableName = Util::toUnderScore($entityName);
     $fullList = array();
     //contains empty string (" ") like delimiter
     $fullListReverse = array();
     //reverse of $fullList
     $fieldList = array();
     //doesn't contain empty string (" ") like delimiter
     $like = array();
     $equal = array();
     foreach ($foreignField as $foreignFieldName) {
         $fieldNameTrimmed = trim($foreignFieldName);
         if (!empty($fieldNameTrimmed)) {
             $columnName = $tableName . '.' . Util::toUnderScore($fieldNameTrimmed);
             $fullList[] = $fieldList[] = $columnName;
             $like[] = $columnName . " LIKE '{text}'";
             $equal[] = $columnName . " = '{text}'";
         } else {
             $fullList[] = "'" . $foreignFieldName . "'";
         }
     }
     $fullListReverse = array_reverse($fullList);
     return array($entityName => array('fields' => array($fieldName => array('type' => 'varchar', 'select' => $this->getSelect($fullList), 'where' => array('LIKE' => "(" . implode(" OR ", $like) . " OR CONCAT(" . implode(", ", $fullList) . ") LIKE '{text}' OR CONCAT(" . implode(", ", $fullListReverse) . ") LIKE '{text}')", '=' => "(" . implode(" OR ", $equal) . " OR CONCAT(" . implode(", ", $fullList) . ") = '{text}' OR CONCAT(" . implode(", ", $fullListReverse) . ") = '{text}')"), 'orderBy' => implode(", ", array_map(function ($item) {
         return $item . ' {direction}';
     }, $fieldList))))));
 }
Beispiel #7
0
 protected function load($linkName, $entityName)
 {
     $parentRelation = parent::load($linkName, $entityName);
     $foreignEntityName = $this->getForeignEntityName();
     $relation = array($entityName => array('relations' => array($linkName => array('midKeys' => array(lcfirst($entityName) . 'Id', lcfirst($foreignEntityName) . 'Id')))));
     $relation = \Espo\Core\Utils\Util::merge($parentRelation, $relation);
     return $relation;
 }
Beispiel #8
0
 public function normalizeEntityName($name)
 {
     if (empty($this->entityClassNameHash[$name])) {
         $className = '\\Espo\\Custom\\Entities\\' . Util::normilizeClassName($name);
         if (!class_exists($className)) {
             $className = $this->espoMetadata->getEntityPath($name);
         }
         $this->entityClassNameHash[$name] = $className;
     }
     return $this->entityClassNameHash[$name];
 }
 protected function getClassName($name)
 {
     $name = Util::normilizeClassName($name);
     if (!isset($this->data)) {
         $this->init();
     }
     $name = ucfirst($name);
     if (isset($this->data[$name])) {
         return $this->data[$name];
     }
     return false;
 }
Beispiel #10
0
 public function process($controllerName, $actionName, $params, $data, $request)
 {
     $customeClassName = '\\Espo\\Custom\\Controllers\\' . Util::normilizeClassName($controllerName);
     if (class_exists($customeClassName)) {
         $controllerClassName = $customeClassName;
     } else {
         $moduleName = $this->metadata->getScopeModuleName($controllerName);
         if ($moduleName) {
             $controllerClassName = '\\Espo\\Modules\\' . $moduleName . '\\Controllers\\' . Util::normilizeClassName($controllerName);
         } else {
             $controllerClassName = '\\Espo\\Controllers\\' . Util::normilizeClassName($controllerName);
         }
     }
     if ($data && stristr($request->getContentType(), 'application/json')) {
         $data = json_decode($data);
     }
     if ($data instanceof \stdClass) {
         $data = get_object_vars($data);
     }
     if (!class_exists($controllerClassName)) {
         throw new NotFound("Controller '{$controllerName}' is not found");
     }
     $controller = new $controllerClassName($this->container, $request->getMethod());
     if ($actionName == 'index') {
         $actionName = $controllerClassName::$defaultAction;
     }
     $actionNameUcfirst = ucfirst($actionName);
     $beforeMethodName = 'before' . $actionNameUcfirst;
     $actionMethodName = 'action' . $actionNameUcfirst;
     $afterMethodName = 'after' . $actionNameUcfirst;
     $fullActionMethodName = strtolower($request->getMethod()) . ucfirst($actionMethodName);
     if (method_exists($controller, $fullActionMethodName)) {
         $primaryActionMethodName = $fullActionMethodName;
     } else {
         $primaryActionMethodName = $actionMethodName;
     }
     if (!method_exists($controller, $primaryActionMethodName)) {
         throw new NotFound("Action '{$actionName}' (" . $request->getMethod() . ") does not exist in controller '{$controllerName}'");
     }
     if (method_exists($controller, $beforeMethodName)) {
         $controller->{$beforeMethodName}($params, $data, $request);
     }
     $result = $controller->{$primaryActionMethodName}($params, $data, $request);
     if (method_exists($controller, $afterMethodName)) {
         $controller->{$afterMethodName}($params, $data, $request);
     }
     if (is_array($result) || is_bool($result) || $result instanceof \StdClass) {
         return \Espo\Core\Utils\Json::encode($result);
     }
     return $result;
 }
Beispiel #11
0
 public function __construct()
 {
     parent::__construct();
     if (empty($this->entityType)) {
         $name = get_class($this);
         if (preg_match('@\\\\([\\w]+)$@', $name, $matches)) {
             $name = $matches[1];
         }
         if ($name != 'Record') {
             $this->entityType = Util::normilizeScopeName($name);
         }
     }
     $this->entityName = $this->entityType;
 }
 public function run()
 {
     $uid = $_GET['uid'];
     $action = $_GET['action'];
     if (empty($uid) || empty($action)) {
         throw new BadRequest();
     }
     if (!in_array($action, array('accept', 'decline', 'tentative'))) {
         throw new BadRequest();
     }
     $uniqueId = $this->getEntityManager()->getRepository('UniqueId')->where(array('name' => $uid))->findOne();
     if (!$uniqueId) {
         throw new NotFound();
         return;
     }
     $data = $uniqueId->get('data');
     $eventType = $data->eventType;
     $eventId = $data->eventId;
     $inviteeType = $data->inviteeType;
     $inviteeId = $data->inviteeId;
     $link = $data->link;
     if (!empty($eventType) && !empty($eventId) && !empty($inviteeType) && !empty($inviteeId) && !empty($link)) {
         $event = $this->getEntityManager()->getEntity($eventType, $eventId);
         $invitee = $this->getEntityManager()->getEntity($inviteeType, $inviteeId);
         if ($event && $invitee) {
             $relDefs = $event->getRelations();
             $tableName = Util::toUnderscore($relDefs[$link]['relationName']);
             $status = 'None';
             if ($action == 'accept') {
                 $status = 'Accepted';
             } else {
                 if ($action == 'decline') {
                     $status = 'Declined';
                 } else {
                     if ($action == 'tentative') {
                         $status = 'Tentative';
                     }
                 }
             }
             $pdo = $this->getEntityManager()->getPDO();
             $sql = "\n                    UPDATE `{$tableName}` SET status = '{$status}'\n                    WHERE " . strtolower($eventType) . "_id = '{$eventId}' AND " . strtolower($inviteeType) . "_id = '{$inviteeId}'\n                ";
             $sth = $pdo->prepare($sql);
             $sth->execute();
             $this->getEntityManager()->getRepository('UniqueId')->remove($uniqueId);
             echo $status;
             return;
         }
     }
     throw new Error();
 }
Beispiel #13
0
 protected function load($fieldName, $entityName)
 {
     $converedFieldName = $fieldName . 'Converted';
     $currencyColumnName = Util::toUnderScore($fieldName);
     $alias = Util::toUnderScore($fieldName) . "_currency_alias";
     $d = array($entityName => array('fields' => array($fieldName => array("type" => "float", "orderBy" => $converedFieldName . " {direction}"))));
     $params = $this->getFieldParams($fieldName);
     if (!empty($params['notStorable'])) {
         $d[$entityName]['fields'][$fieldName]['notStorable'] = true;
     } else {
         $d[$entityName]['fields'][$fieldName . 'Converted'] = array('type' => 'float', 'select' => Util::toUnderScore($entityName) . "." . $currencyColumnName . " * {$alias}.rate", 'where' => array("=" => Util::toUnderScore($entityName) . "." . $currencyColumnName . " * {$alias}.rate = {value}", ">" => Util::toUnderScore($entityName) . "." . $currencyColumnName . " * {$alias}.rate > {value}", "<" => Util::toUnderScore($entityName) . "." . $currencyColumnName . " * {$alias}.rate < {value}", ">=" => Util::toUnderScore($entityName) . "." . $currencyColumnName . " * {$alias}.rate >= {value}", "<=" => Util::toUnderScore($entityName) . "." . $currencyColumnName . " * {$alias}.rate <= {value}", "<>" => Util::toUnderScore($entityName) . "." . $currencyColumnName . " * {$alias}.rate <> {value}"), 'notStorable' => true, 'orderBy' => $converedFieldName . " {direction}");
     }
     return $d;
 }
Beispiel #14
0
 protected function restoreFiles()
 {
     $GLOBALS['log']->info('Installer: Restore previous files.');
     $backupPath = $this->getPath('backupPath');
     $backupFilePath = Util::concatPath($backupPath, self::FILES);
     $backupFileList = $this->getRestoreFileList();
     $copyFileList = $this->getCopyFileList();
     $deleteFileList = array_diff($copyFileList, $backupFileList);
     $res = $this->copy($backupFilePath, '', true);
     $res &= $this->getFileManager()->remove($deleteFileList, null, true);
     if ($res) {
         $this->getFileManager()->removeInDir($backupPath, true);
     }
     return $res;
 }
 public function create($entityName)
 {
     $className = '\\Espo\\Custom\\SelectManagers\\' . Util::normilizeClassName($entityName);
     if (!class_exists($className)) {
         $moduleName = $this->metadata->getScopeModuleName($entityName);
         if ($moduleName) {
             $className = '\\Espo\\Modules\\' . $moduleName . '\\SelectManagers\\' . Util::normilizeClassName($entityName);
         } else {
             $className = '\\Espo\\SelectManagers\\' . Util::normilizeClassName($entityName);
         }
         if (!class_exists($className)) {
             $className = '\\Espo\\Core\\SelectManagers\\Base';
         }
     }
     $selectManager = new $className($this->entityManager, $this->user, $this->acl, $this->metadata);
     $selectManager->setEntityName($entityName);
     return $selectManager;
 }
Beispiel #16
0
 /**
  * Unite files content
  *
  * @param array $paths
  * @param bool $isReturnModuleNames - If need to return data with module names
  *
  * @return array
  */
 public function unify(array $paths, $isReturnModuleNames = false)
 {
     $data = $this->loadData($paths['corePath']);
     if (!empty($paths['modulePath'])) {
         $moduleDir = strstr($paths['modulePath'], '{*}', true);
         $moduleList = isset($this->metadata) ? $this->getMetadata()->getModuleList() : $this->getFileManager()->getFileList($moduleDir, false, '', false);
         foreach ($moduleList as $moduleName) {
             $moduleFilePath = str_replace('{*}', $moduleName, $paths['modulePath']);
             if ($isReturnModuleNames) {
                 if (!isset($data[$moduleName])) {
                     $data[$moduleName] = array();
                 }
                 $data[$moduleName] = Util::merge($data[$moduleName], $this->loadData($moduleFilePath));
                 continue;
             }
             $data = Util::merge($data, $this->loadData($moduleFilePath));
         }
     }
     if (!empty($paths['customPath'])) {
         $data = Util::merge($data, $this->loadData($paths['customPath']));
     }
     return $data;
 }
Beispiel #17
0
 protected function load($fieldName, $entityName)
 {
     return array($entityName => array('fields' => array($fieldName => array('select' => 'phone_number.name', 'where' => array('LIKE' => \Espo\Core\Utils\Util::toUnderScore($entityName) . ".id IN (\n\t\t\t\t\t\t\t\tSELECT entity_id \n\t\t\t\t\t\t\t\tFROM entity_phone_number\n\t\t\t\t\t\t\t\tJOIN phone_number ON phone_number.id = entity_phone_number.phone_number_id\n\t\t\t\t\t\t\t\tWHERE \n\t\t\t\t\t\t\t\t\tentity_phone_number.deleted = 0 AND entity_phone_number.entity_type = '{$entityName}' AND\n\t\t\t\t\t\t\t\t\tphone_number.deleted = 0 AND phone_number.name LIKE '{text}'          \t\t\n\t\t\t\t\t\t\t)", '=' => \Espo\Core\Utils\Util::toUnderScore($entityName) . ".id IN (\n\t\t\t\t\t\t\t\tSELECT entity_id \n\t\t\t\t\t\t\t\tFROM entity_phone_number\n\t\t\t\t\t\t\t\tJOIN phone_number ON phone_number.id = entity_phone_number.phone_number_id\n\t\t\t\t\t\t\t\tWHERE \n\t\t\t\t\t\t\t\t\tentity_phone_number.deleted = 0 AND entity_phone_number.entity_type = '{$entityName}' AND\n\t\t\t\t\t\t\t\t\tphone_number.deleted = 0 AND phone_number.name = '{text}'          \t\t\n\t\t\t\t\t\t\t)"), 'orderBy' => 'phone_number.name {direction}'), $fieldName . 'Data' => array('type' => 'text', 'notStorable' => true)), 'relations' => array($fieldName . 's' => array('type' => 'manyMany', 'entity' => 'PhoneNumber', 'relationName' => 'entityPhoneNumber', 'midKeys' => array('entity_id', 'phone_number_id'), 'conditions' => array('entityType' => $entityName), 'additionalColumns' => array('entityType' => array('type' => 'varchar', 'len' => 100), 'primary' => array('type' => 'bool', 'default' => false))))));
 }
Beispiel #18
0
 /**
  * Get and merge hook data by checking the files exist in $hookDirs
  *
  * @param array $hookDirs - it can be an array('Espo/Hooks', 'Espo/Custom/Hooks', 'Espo/Modules/Crm/Hooks')
  *
  * @return array
  */
 protected function getHookData($hookDirs)
 {
     if (is_string($hookDirs)) {
         $hookDirs = (array) $hookDirs;
     }
     $hooks = array();
     foreach ($hookDirs as $hookDir) {
         if (file_exists($hookDir)) {
             $fileList = $this->getFileManager()->getFileList($hookDir, 1, '\\.php$', 'file');
             foreach ($fileList as $scopeName => $hookFiles) {
                 $hookScopeDirPath = Util::concatPath($hookDir, $scopeName);
                 $scopeHooks = array();
                 foreach ($hookFiles as $hookFile) {
                     $hookFilePath = Util::concatPath($hookScopeDirPath, $hookFile);
                     $className = Util::getClassName($hookFilePath);
                     foreach ($this->hookList as $hookName) {
                         if (method_exists($className, $hookName)) {
                             $scopeHooks[$hookName][$className::$order][] = $className;
                         }
                     }
                 }
                 //sort hooks by order
                 foreach ($scopeHooks as $hookName => $hookList) {
                     ksort($hookList);
                     $sortedHookList = array();
                     foreach ($hookList as $hookDetails) {
                         $sortedHookList = array_merge($sortedHookList, $hookDetails);
                     }
                     $hooks[$scopeName][$hookName] = isset($hooks[$scopeName][$hookName]) ? array_merge($hooks[$scopeName][$hookName], $sortedHookList) : $sortedHookList;
                 }
             }
         }
     }
     return $hooks;
 }
Beispiel #19
0
 public function testUnsetInArrayByValueWithoutReindex()
 {
     $newArray = json_decode('[
       "__APPEND__",
         {
            "name":"populating",
            "label":"Populating",
            "view":"Advanced:TargetList.Record.Panels.Populating"
         }
     ]', true);
     $result = json_decode('{
       "1": {
         "name": "populating",
         "label": "Populating",
         "view": "Advanced:TargetList.Record.Panels.Populating"
       }
     }', true);
     $this->assertEquals($result, Util::unsetInArrayByValue('__APPEND__', $newArray, false));
 }
Beispiel #20
0
 protected function getInitValues(array $fieldParams)
 {
     $values = array();
     foreach ($this->fieldAccordances as $espoType => $ormType) {
         if (isset($fieldParams[$espoType])) {
             if (is_array($ormType)) {
                 $conditionRes = false;
                 if (!is_array($fieldParams[$espoType])) {
                     $conditionRes = preg_match('/' . $ormType['condition'] . '/i', $fieldParams[$espoType]);
                 }
                 if (!$conditionRes || $conditionRes && $conditionRes === $ormType['conditionEquals']) {
                     $value = is_array($fieldParams[$espoType]) ? json_encode($fieldParams[$espoType]) : $fieldParams[$espoType];
                     $values = Util::merge($values, Util::replaceInArray('{0}', $value, $ormType['value']));
                 }
             } else {
                 $values[$ormType] = $fieldParams[$espoType];
             }
         }
     }
     return $values;
 }
Beispiel #21
0
 protected function initFieldTypes()
 {
     foreach ($this->fieldTypePaths as $path) {
         $typeList = $this->getFileManager()->getFileList($path, false, '\\.php$');
         if ($typeList !== false) {
             foreach ($typeList as $name) {
                 $typeName = preg_replace('/\\.php$/i', '', $name);
                 $dbalTypeName = strtolower($typeName);
                 $filePath = Util::concatPath($path, $typeName);
                 $class = Util::getClassName($filePath);
                 if (!Type::hasType($dbalTypeName)) {
                     Type::addType($dbalTypeName, $class);
                 } else {
                     Type::overrideType($dbalTypeName, $class);
                 }
                 $dbTypeName = method_exists($class, 'getDbTypeName') ? $class::getDbTypeName() : $dbalTypeName;
                 $this->getConnection()->getDatabasePlatform()->registerDoctrineTypeMapping($dbTypeName, $dbalTypeName);
             }
         }
     }
 }
Beispiel #22
0
 public function save(Entity $entity, array $options = array())
 {
     $nowString = date('Y-m-d H:i:s', time());
     $restoreData = array();
     if ($entity->isNew()) {
         if (!$entity->has('id')) {
             $entity->set('id', Util::generateId());
         }
         if ($entity->hasField('createdAt')) {
             $entity->set('createdAt', $nowString);
         }
         if ($entity->hasField('modifiedAt')) {
             $entity->set('modifiedAt', $nowString);
         }
         if ($entity->hasField('createdById')) {
             $entity->set('createdById', $this->entityManager->getUser()->id);
         }
         if ($entity->has('modifiedById')) {
             $restoreData['modifiedById'] = $entity->get('modifiedById');
         }
         if ($entity->has('modifiedAt')) {
             $restoreData['modifiedAt'] = $entity->get('modifiedAt');
         }
         $entity->clear('modifiedById');
     } else {
         if (empty($options['silent'])) {
             if ($entity->hasField('modifiedAt')) {
                 $entity->set('modifiedAt', $nowString);
             }
             if ($entity->hasField('modifiedById')) {
                 $entity->set('modifiedById', $this->entityManager->getUser()->id);
             }
         }
         if ($entity->has('createdById')) {
             $restoreData['createdById'] = $entity->get('createdById');
         }
         if ($entity->has('createdAt')) {
             $restoreData['createdAt'] = $entity->get('createdAt');
         }
         $entity->clear('createdById');
         $entity->clear('createdAt');
     }
     $this->restoreData = $restoreData;
     $result = parent::save($entity, $options);
     return $result;
 }
Beispiel #23
0
 protected function getRestoreFileList()
 {
     if (!isset($this->data['restoreFileList'])) {
         $packagePath = $this->getPackagePath();
         $filesPath = Util::concatPath($packagePath, self::FILES);
         if (!file_exists($filesPath)) {
             $this->unzipArchive($packagePath);
         }
         $this->data['restoreFileList'] = $this->getFileManager()->getFileList($filesPath, true, '', true, true);
     }
     return $this->data['restoreFileList'];
 }
Beispiel #24
0
 /**
  * Get a filename without the file extension
  *
  * @param string $filename
  * @param string $ext - extension, ex. '.json'
  *
  * @return array
  */
 public function getFileName($fileName, $ext = '')
 {
     if (empty($ext)) {
         $fileName = substr($fileName, 0, strrpos($fileName, '.', -1));
     } else {
         if (substr($ext, 0, 1) != '.') {
             $ext = '.' . $ext;
         }
         if (substr($fileName, -strlen($ext)) == $ext) {
             $fileName = substr($fileName, 0, -strlen($ext));
         }
     }
     $exFileName = explode('/', Utils\Util::toFormat($fileName, '/'));
     return end($exFileName);
 }
Beispiel #25
0
 protected function init($reload = false)
 {
     if ($reload || !file_exists($this->getLangCacheFile()) || !$this->getConfig()->get('useCache')) {
         $this->fullData = $this->getUnifier()->unify($this->name, $this->paths, true);
         $result = true;
         foreach ($this->fullData as $i18nName => $i18nData) {
             $i18nCacheFile = str_replace('{*}', $i18nName, $this->cacheFile);
             if ($i18nName != $this->defaultLanguage) {
                 $i18nData = Util::merge($this->fullData[$this->defaultLanguage], $i18nData);
             }
             $result &= $this->getFileManager()->putContentsPHP($i18nCacheFile, $i18nData);
         }
         if ($result == false) {
             throw new Error('Language::init() - Cannot save data to a cache');
         }
     }
     $this->data = $this->getFileManager()->getContents($this->getLangCacheFile());
 }
Beispiel #26
0
 public function getRepositoryPath($entityName, $delim = '\\')
 {
     $path = $this->getScopePath($entityName, $delim);
     return implode($delim, array($path, 'Repositories', Util::normilizeClassName(ucfirst($entityName))));
 }
Beispiel #27
0
 protected function createRecord($entityName, $data)
 {
     if (isset($data['id'])) {
         $entity = $this->getEntityManager()->getEntity($entityName, $data['id']);
         if (!isset($entity)) {
             $pdo = $this->getEntityManager()->getPDO();
             $sql = "SELECT id FROM `" . Util::toUnderScore($entityName) . "` WHERE `id` = '" . $data['id'] . "'";
             $sth = $pdo->prepare($sql);
             $sth->execute();
             $deletedEntity = $sth->fetch(\PDO::FETCH_ASSOC);
             if ($deletedEntity) {
                 $sql = "UPDATE `" . Util::toUnderScore($entityName) . "` SET deleted = '0' WHERE `id` = '" . $data['id'] . "'";
                 $pdo->prepare($sql)->execute();
                 $entity = $this->getEntityManager()->getEntity($entityName, $data['id']);
             }
         }
     }
     if (!isset($entity)) {
         $entity = $this->getEntityManager()->getEntity($entityName);
     }
     $entity->set($data);
     $id = $this->getEntityManager()->saveEntity($entity);
     return is_string($id);
 }
Beispiel #28
0
 protected function load($fieldName, $entityName)
 {
     return array($entityName => array('fields' => array($fieldName => array('select' => 'emailAddresses.name', 'where' => array('LIKE' => \Espo\Core\Utils\Util::toUnderScore($entityName) . ".id IN (\n                                SELECT entity_id\n                                FROM entity_email_address\n                                JOIN email_address ON email_address.id = entity_email_address.email_address_id\n                                WHERE\n                                    entity_email_address.deleted = 0 AND entity_email_address.entity_type = '{$entityName}' AND\n                                    email_address.deleted = 0 AND email_address.name LIKE {value}\n                            )", '=' => \Espo\Core\Utils\Util::toUnderScore($entityName) . ".id IN (\n                                SELECT entity_id\n                                FROM entity_email_address\n                                JOIN email_address ON email_address.id = entity_email_address.email_address_id\n                                WHERE\n                                    entity_email_address.deleted = 0 AND entity_email_address.entity_type = '{$entityName}' AND\n                                    email_address.deleted = 0 AND email_address.name = {value}\n                            )", '<>' => \Espo\Core\Utils\Util::toUnderScore($entityName) . ".id IN (\n                                SELECT entity_id\n                                FROM entity_email_address\n                                JOIN email_address ON email_address.id = entity_email_address.email_address_id\n                                WHERE\n                                    entity_email_address.deleted = 0 AND entity_email_address.entity_type = '{$entityName}' AND\n                                    email_address.deleted = 0 AND email_address.name <> {value}\n                            )"), 'orderBy' => 'emailAddresses.name {direction}'), $fieldName . 'Data' => array('type' => 'text', 'notStorable' => true)), 'relations' => array($fieldName . 'es' => array('type' => 'manyMany', 'entity' => 'EmailAddress', 'relationName' => 'entityEmailAddress', 'midKeys' => array('entity_id', 'email_address_id'), 'conditions' => array('entityType' => $entityName), 'additionalColumns' => array('entityType' => array('type' => 'varchar', 'len' => 100), 'primary' => array('type' => 'bool', 'default' => false))))));
 }
Beispiel #29
0
 /**
  * Helpful method for get content from files for unite Files
  *
  * @param string | array $paths
  * @param string | array() $defaults - It can be a string like ["metadata","layouts"] OR an array with default values
  *
  * @return array
  */
 protected function unifyGetContents($paths, $defaults)
 {
     $fileContent = $this->getFileManager()->getContents($paths);
     $decoded = Utils\Json::getArrayData($fileContent, null);
     if (!isset($decoded)) {
         $GLOBALS['log']->emergency('Syntax error in ' . Utils\Util::concatPath($paths));
         return array();
     }
     return $decoded;
 }
Beispiel #30
0
 /**
  * Generate index name
  *
  * @return string
  */
 protected function generateIndexName($name, $entityName)
 {
     $names = array('IDX');
     $names[] = strtoupper(Util::toUnderScore($entityName));
     $names[] = strtoupper(Util::toUnderScore($name));
     return implode('_', $names);
 }