Merge branch 'master' into stable
This commit is contained in:
+4
-7
@@ -2,17 +2,14 @@
|
||||
/data/cache/*
|
||||
/data/upload/*
|
||||
/data/preferences/*
|
||||
/data/.backup/*
|
||||
/data/config.php
|
||||
/custom
|
||||
/application/Espo/Resources/metadata/scopes/CustomTest.json
|
||||
/application/Espo/Modules/Crm/Resources/metadata/scopes/CustomTest.json
|
||||
/application/Espo/Resources/layouts/CustomTest/*
|
||||
/application/Espo/Modules/Crm/Resources/layouts/CustomTest/*
|
||||
/application/Espo/Resources/metadata/customTest/*
|
||||
/application/Espo/Modules/Crm/Resources/metadata/customTest/*
|
||||
/build
|
||||
/node_modules
|
||||
/client
|
||||
/test.php
|
||||
/main.html
|
||||
/tests/testData/Utils/Config/config.php
|
||||
/tests/testData/cache/*
|
||||
composer.phar
|
||||
vendor/
|
||||
|
||||
@@ -4,23 +4,22 @@
|
||||
|
||||
DirectoryIndex index.php index.html
|
||||
|
||||
# PROTECTED DIRECTORIES
|
||||
<IfModule mod_rewrite.c>
|
||||
RewriteEngine On
|
||||
RewriteCond %{REQUEST_FILENAME} -d
|
||||
RewriteRule (?i)(data|api) - [F]
|
||||
</IfModule>
|
||||
RedirectMatch 403 (?i)/data/config\.php$
|
||||
RedirectMatch 403 (?i)/data/logs
|
||||
RedirectMatch 403 (?i)/data/cache
|
||||
RedirectMatch 403 (?i)/data/upload
|
||||
RedirectMatch 403 (?i)/application
|
||||
RedirectMatch 403 (?i)/custom
|
||||
RedirectMatch 403 (?i)/vendor
|
||||
#END PROTECTED DIRECTORIES
|
||||
|
||||
<IfModule mod_rewrite.c>
|
||||
RewriteEngine On
|
||||
# PROTECTED DIRECTORIES
|
||||
RewriteCond %{REQUEST_FILENAME} -d
|
||||
RewriteRule ^/?(data|api)/ - [F]
|
||||
|
||||
RewriteRule ^/?data/config\.php$ - [F]
|
||||
RewriteRule ^/?data/logs/ - [F]
|
||||
RewriteRule ^/?data/cache/ - [F]
|
||||
RewriteRule ^/?data/upload/ - [F]
|
||||
RewriteRule ^/?application/ - [F]
|
||||
RewriteRule ^/?custom/ - [F]
|
||||
RewriteRule ^/?vendor/ - [F]
|
||||
#END PROTECTED DIRECTORIES
|
||||
|
||||
RewriteRule .* - [E=HTTP_ESPO_CGI_AUTH:%{HTTP:Authorization}]
|
||||
|
||||
RewriteRule reset/?$ reset.html [QSA,L]
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
<a href='http://www.espocrm.com'>EspoCRM is an Open Source CRM</a> (Customer Relationship Management) software that allows you to see, enter and evaluate all your company relationships regardless of the type. People, companies or opportunities - all in an easy and intuitive interface.
|
||||
|
||||
### How to get started
|
||||
|
||||
1. Clone repository to your local computer.
|
||||
2. Change to the project's root directory.
|
||||
3. Install [composer](https://getcomposer.org/doc/00-intro.md).
|
||||
4. Run `composer install` if composer is installed globally or `php composer.phar install` if locally.
|
||||
|
||||
Never update composer dependencies if you are going to contribute code back.
|
||||
|
||||
Now you can build.
|
||||
|
||||
If your repository is accessible via a web server then you can run EspoCRM by url `http://PROJECT_URL/frontend` w/o making a build. You will need to have proper data/config.php and existing database.
|
||||
|
||||
### How to build
|
||||
|
||||
You need to have nodejs installed.
|
||||
|
||||
1. Change to the project's root directory.
|
||||
2. Install project dependencies with `npm install`.
|
||||
3. Run Grunt with `grunt`.
|
||||
|
||||
The build will be created in the `build` directory.
|
||||
|
||||
### License
|
||||
|
||||
EspoCRM is published under the GNU GPLv3 [license](https://raw.githubusercontent.com/espocrm/espocrm/master/LICENSE.txt).
|
||||
|
||||
@@ -72,7 +72,7 @@ class Admin extends \Espo\Core\Controllers\Base
|
||||
{
|
||||
$upgradeManager = new \Espo\Core\UpgradeManager($this->getContainer());
|
||||
|
||||
$upgradeManager->run($data['id']);
|
||||
$upgradeManager->install($data['id']);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,131 @@
|
||||
<?php
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM - Open Source CRM application.
|
||||
* Copyright (C) 2014 Yuri Kuznetsov, Taras Machyshyn, Oleksiy Avramenko
|
||||
* Website: http://www.espocrm.com
|
||||
*
|
||||
* EspoCRM is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* EspoCRM is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with EspoCRM. If not, see http://www.gnu.org/licenses/.
|
||||
************************************************************************/
|
||||
|
||||
namespace Espo\Controllers;
|
||||
|
||||
use \Espo\Core\Exceptions\Error;
|
||||
use \Espo\Core\Exceptions\Forbidden;
|
||||
|
||||
class Extension extends \Espo\Core\Controllers\Record
|
||||
{
|
||||
protected function checkControllerAccess()
|
||||
{
|
||||
if (!$this->getUser()->isAdmin()) {
|
||||
throw new Forbidden();
|
||||
}
|
||||
}
|
||||
|
||||
public function actionUpload($params, $data, $request)
|
||||
{
|
||||
if (!$request->isPost()) {
|
||||
throw new Forbidden();
|
||||
}
|
||||
|
||||
$manager = new \Espo\Core\ExtensionManager($this->getContainer());
|
||||
|
||||
$id = $manager->upload($data);
|
||||
$manifest = $manager->getManifest();
|
||||
|
||||
return array(
|
||||
'id' => $id,
|
||||
'version' => $manifest['version'],
|
||||
'name' => $manifest['name'],
|
||||
'description' => $manifest['description'],
|
||||
);
|
||||
}
|
||||
|
||||
public function actionInstall($params, $data, $request)
|
||||
{
|
||||
if (!$request->isPost()) {
|
||||
throw new Forbidden();
|
||||
}
|
||||
|
||||
$manager = new \Espo\Core\ExtensionManager($this->getContainer());
|
||||
|
||||
$manager->install($data['id']);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function actionUninstall($params, $data, $request)
|
||||
{
|
||||
if (!$request->isPost()) {
|
||||
throw new Forbidden();
|
||||
}
|
||||
|
||||
$manager = new \Espo\Core\ExtensionManager($this->getContainer());
|
||||
|
||||
$manager->uninstall($data['id']);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function actionCreate()
|
||||
{
|
||||
throw new Forbidden();
|
||||
}
|
||||
|
||||
public function actionUpdate()
|
||||
{
|
||||
throw new Forbidden();
|
||||
}
|
||||
|
||||
public function actionPatch()
|
||||
{
|
||||
throw new Forbidden();
|
||||
}
|
||||
|
||||
public function actionListLinked()
|
||||
{
|
||||
throw new Forbidden();
|
||||
}
|
||||
|
||||
public function actionDelete($params, $data, $request)
|
||||
{
|
||||
$manager = new \Espo\Core\ExtensionManager($this->getContainer());
|
||||
|
||||
$manager->delete($params['id']);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function actionMassUpdate()
|
||||
{
|
||||
throw new Forbidden();
|
||||
}
|
||||
|
||||
public function actionMassDelete()
|
||||
{
|
||||
throw new Forbidden();
|
||||
}
|
||||
|
||||
public function actionCreateLink()
|
||||
{
|
||||
throw new Forbidden();
|
||||
}
|
||||
|
||||
public function actionRemoveLink()
|
||||
{
|
||||
throw new Forbidden();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,35 +45,33 @@ class ExternalAccount extends \Espo\Core\Controllers\Record
|
||||
);
|
||||
}
|
||||
|
||||
public function actionGetOAuthCredentials($params, $data, $request)
|
||||
public function actionGetOAuth2Info($params, $data, $request)
|
||||
{
|
||||
$id = $request->get('id');
|
||||
list($integration, $userId) = explode('__', $id);
|
||||
|
||||
if (!$this->getUser()->isAdmin()) {
|
||||
if ($this->getUser()->id != $userId) {
|
||||
throw new Forbidden();
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->getUser()->id != $userId) {
|
||||
throw new Forbidden();
|
||||
}
|
||||
|
||||
$entity = $this->getEntityManager()->getEntity('Integration', $integration);
|
||||
if ($entity) {
|
||||
return array(
|
||||
'clientId' => $entity->get('clientId'),
|
||||
'redirectUri' => $this->getConfig()->get('siteUrl') . '/oauthcallback'
|
||||
'redirectUri' => $this->getConfig()->get('siteUrl') . '/oauthcallback',
|
||||
'isConnected' => $this->getRecordService()->ping($integration, $userId)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public function actionRead($params, $data, $request)
|
||||
{
|
||||
list($integration, $userId) = explode('__', $params['id']);
|
||||
|
||||
if (!$this->getUser()->isAdmin()) {
|
||||
if ($this->getUser()->id != $userId) {
|
||||
throw new Forbidden();
|
||||
}
|
||||
}
|
||||
list($integration, $userId) = explode('__', $params['id']);
|
||||
|
||||
if ($this->getUser()->id != $userId) {
|
||||
throw new Forbidden();
|
||||
}
|
||||
|
||||
$entity = $this->getEntityManager()->getEntity('ExternalAccount', $params['id']);
|
||||
return $entity->toArray();
|
||||
@@ -88,17 +86,39 @@ class ExternalAccount extends \Espo\Core\Controllers\Record
|
||||
{
|
||||
list($integration, $userId) = explode('__', $params['id']);
|
||||
|
||||
if (!$this->getUser()->isAdmin()) {
|
||||
if ($this->getUser()->id != $userId) {
|
||||
throw new Forbidden();
|
||||
}
|
||||
|
||||
if ($this->getUser()->id != $userId) {
|
||||
throw new Forbidden();
|
||||
}
|
||||
|
||||
if (isset($data['enabled']) && !$data['enabled']) {
|
||||
$data['data'] = null;
|
||||
}
|
||||
|
||||
$entity = $this->getEntityManager()->getEntity('ExternalAccount', $params['id']);
|
||||
$entity->set($data);
|
||||
$this->getEntityManager()->saveEntity($entity);
|
||||
|
||||
return $entity->toArray();
|
||||
}
|
||||
|
||||
public function actionAuthorizationCode($params, $data, $request)
|
||||
{
|
||||
if (!$request->isPost()) {
|
||||
throw new Error('Bad HTTP method type.');
|
||||
}
|
||||
|
||||
$id = $data['id'];
|
||||
$code = $data['code'];
|
||||
|
||||
list($integration, $userId) = explode('__', $id);
|
||||
|
||||
if ($this->getUser()->id != $userId) {
|
||||
throw new Forbidden();
|
||||
}
|
||||
|
||||
$service = $this->getRecordService();
|
||||
return $service->authorizationCode($integration, $userId, $code);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -70,7 +70,11 @@ class FieldManager extends \Espo\Core\Controllers\Base
|
||||
$fieldManager = $this->getContainer()->get('fieldManager');
|
||||
$fieldManager->update($params['name'], $data, $params['scope']);
|
||||
|
||||
$this->getContainer()->get('dataManager')->rebuild($params['scope']);
|
||||
if ($fieldManager->isChanged()) {
|
||||
$this->getContainer()->get('dataManager')->rebuild($params['scope']);
|
||||
} else {
|
||||
$this->getContainer()->get('dataManager')->clearCache();
|
||||
}
|
||||
|
||||
return $fieldManager->read($params['name'], $params['scope']);
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ class Stream extends \Espo\Core\Controllers\Base
|
||||
public function actionList($params, $data, $request)
|
||||
{
|
||||
$scope = $params['scope'];
|
||||
$id = $params['id'];
|
||||
$id = isset($params['id']) ? $params['id'] : null;
|
||||
|
||||
$offset = intval($request->get('offset'));
|
||||
$maxSize = intval($request->get('maxSize'));
|
||||
|
||||
@@ -24,6 +24,8 @@ namespace Espo\Core;
|
||||
|
||||
use \Espo\Core\Exceptions\Error;
|
||||
|
||||
use \Espo\ORM\Entity;
|
||||
|
||||
class Acl
|
||||
{
|
||||
private $data = array();
|
||||
@@ -70,7 +72,7 @@ class Acl
|
||||
|
||||
}
|
||||
|
||||
public function checkScope($scope, $action = null, $isOwner = null, $inTeam = null)
|
||||
public function checkScope($scope, $action = null, $isOwner = null, $inTeam = null, $entity = null)
|
||||
{
|
||||
if (array_key_exists($scope, $this->data)) {
|
||||
if ($this->data[$scope] === false) {
|
||||
@@ -100,6 +102,9 @@ class Acl
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if ($inTeam === null && $entity) {
|
||||
$inTeam = $this->checkInTeam($entity);
|
||||
}
|
||||
|
||||
if ($inTeam) {
|
||||
if ($value === 'team') {
|
||||
@@ -129,8 +134,10 @@ class Acl
|
||||
return $this->checkScope($subject, $action, $isOwner, $inTeam);
|
||||
} else {
|
||||
$entity = $subject;
|
||||
$entityName = $entity->getEntityName();
|
||||
return $this->checkScope($entityName, $action, $this->checkIsOwner($entity), $this->checkInTeam($entity));
|
||||
if ($entity instanceof Entity) {
|
||||
$entityName = $entity->getEntityName();
|
||||
return $this->checkScope($entityName, $action, $this->checkIsOwner($entity), $inTeam, $entity);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -168,7 +175,20 @@ class Acl
|
||||
public function checkInTeam($entity)
|
||||
{
|
||||
$userTeamIds = $this->user->get('teamsIds');
|
||||
$teamIds = $entity->get('teamsIds');
|
||||
|
||||
if (!$entity->hasRelation('teams') || !$entity->hasField('teamsIds')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!$entity->has('teamsIds')) {
|
||||
$entity->loadLinkMultipleField('teams');
|
||||
}
|
||||
|
||||
$teamIds = $entity->get('teamsIds');
|
||||
|
||||
if (empty($teamIds)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach ($userTeamIds as $id) {
|
||||
if (in_array($id, $teamIds)) {
|
||||
|
||||
@@ -28,25 +28,25 @@ class Person extends \Espo\Core\ORM\Entity
|
||||
|
||||
public function setLastName($value)
|
||||
{
|
||||
$this->setValue('lastName', $value);
|
||||
$this->_setValue('lastName', $value);
|
||||
|
||||
$firstName = $this->get('firstName');
|
||||
if (empty($firstName)) {
|
||||
$this->setValue('name', $value);
|
||||
$this->_setValue('name', $value);
|
||||
} else {
|
||||
$this->setValue('name', $firstName . ' ' . $value);
|
||||
$this->_setValue('name', $firstName . ' ' . $value);
|
||||
}
|
||||
}
|
||||
|
||||
public function setFirstName($value)
|
||||
{
|
||||
$this->setValue('firstName', $value);
|
||||
$this->_setValue('firstName', $value);
|
||||
|
||||
$lastName = $this->get('lastName');
|
||||
if (empty($lastName)) {
|
||||
$this->setValue('name', $value);
|
||||
$this->_setValue('name', $value);
|
||||
} else {
|
||||
$this->setValue('name', $value . ' ' . $lastName);
|
||||
$this->_setValue('name', $value . ' ' . $lastName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM - Open Source CRM application.
|
||||
* Copyright (C) 2014 Yuri Kuznetsov, Taras Machyshyn, Oleksiy Avramenko
|
||||
* Website: http://www.espocrm.com
|
||||
*
|
||||
* EspoCRM is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* EspoCRM is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with EspoCRM. If not, see http://www.gnu.org/licenses/.
|
||||
************************************************************************/
|
||||
|
||||
namespace Espo\Core;
|
||||
|
||||
class ExtensionManager extends Upgrades\Base
|
||||
{
|
||||
protected $name = 'Extension';
|
||||
|
||||
protected $params = array(
|
||||
'packagePath' => 'data/upload/extensions',
|
||||
|
||||
'backupPath' => 'data/.backup/extensions',
|
||||
|
||||
'scriptNames' => array(
|
||||
'before' => 'BeforeInstall',
|
||||
'after' => 'AfterInstall',
|
||||
'beforeUninstall' => 'BeforeUninstall',
|
||||
'afterUninstall' => 'AfterUninstall',
|
||||
)
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,125 @@
|
||||
<?php
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM - Open Source CRM application.
|
||||
* Copyright (C) 2014 Yuri Kuznetsov, Taras Machyshyn, Oleksiy Avramenko
|
||||
* Website: http://www.espocrm.com
|
||||
*
|
||||
* EspoCRM is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* EspoCRM is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with EspoCRM. If not, see http://www.gnu.org/licenses/.
|
||||
************************************************************************/
|
||||
|
||||
namespace Espo\Core\ExternalAccount;
|
||||
|
||||
use \Espo\Core\Exceptions\Error;
|
||||
use \Espo\Core\Exceptions\Forbidden;
|
||||
use \Espo\Core\Exceptions\NotFound;
|
||||
|
||||
class ClientManager
|
||||
{
|
||||
protected $entityManager;
|
||||
|
||||
protected $metadata;
|
||||
|
||||
protected $clientMap = array();
|
||||
|
||||
public function __construct($entityManager, $metadata, $config)
|
||||
{
|
||||
$this->entityManager = $entityManager;
|
||||
$this->metadata = $metadata;
|
||||
$this->config = $config;
|
||||
}
|
||||
|
||||
protected function getMetadata()
|
||||
{
|
||||
return $this->metadata;
|
||||
}
|
||||
|
||||
protected function getEntityManager()
|
||||
{
|
||||
return $this->entityManager;
|
||||
}
|
||||
|
||||
protected function getConfig()
|
||||
{
|
||||
return $this->config;
|
||||
}
|
||||
|
||||
public function storeAccessToken($hash, $data)
|
||||
{
|
||||
if (!empty($this->clientMap[$hash]) && !empty($this->clientMap[$hash]['externalAccountEntity'])) {
|
||||
$externalAccountEntity = $this->clientMap[$hash]['externalAccountEntity'];
|
||||
$externalAccountEntity->set('accessToken', $data['accessToken']);
|
||||
$externalAccountEntity->set('tokenType', $data['tokenType']);
|
||||
$this->getEntityManager()->saveEntity($externalAccountEntity);
|
||||
}
|
||||
}
|
||||
|
||||
public function create($integration, $userId)
|
||||
{
|
||||
$authMethod = $this->getMetadata()->get("integrations.{$integration}.authMethod");
|
||||
$methodName = 'create' . ucfirst($authMethod);
|
||||
return $this->$methodName($integration, $userId);
|
||||
}
|
||||
|
||||
protected function createOAuth2($integration, $userId)
|
||||
{
|
||||
$integrationEntity = $this->getEntityManager()->getEntity('Integration', $integration);
|
||||
$externalAccountEntity = $this->getEntityManager()->getEntity('ExternalAccount', $integration . '__' . $userId);
|
||||
|
||||
$className = $this->getMetadata()->get("integrations.{$integration}.clientClassName");
|
||||
|
||||
$redirectUri = $this->getConfig()->get('siteUrl') . '/oauthcallback'; // TODO move to client class
|
||||
|
||||
if (!$externalAccountEntity) {
|
||||
throw new Error("External Account {$integration} not found for {$userId}");
|
||||
}
|
||||
|
||||
if (!$integrationEntity->get('enabled')) {
|
||||
return null;
|
||||
}
|
||||
if (!$externalAccountEntity->get('enabled')) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$oauth2Client = new \Espo\Core\ExternalAccount\OAuth2\Client();
|
||||
|
||||
$client = new $className($oauth2Client, array(
|
||||
'endpoint' => $this->getMetadata()->get("integrations.{$integration}.params.endpoint"),
|
||||
'tokenEndpoint' => $this->getMetadata()->get("integrations.{$integration}.params.tokenEndpoint"),
|
||||
'clientId' => $integrationEntity->get('clientId'),
|
||||
'clientSecret' => $integrationEntity->get('clientSecret'),
|
||||
'redirectUri' => $redirectUri,
|
||||
'accessToken' => $externalAccountEntity->get('accessToken'),
|
||||
'refreshToken' => $externalAccountEntity->get('refreshToken'),
|
||||
'tokenType' => $externalAccountEntity->get('tokenType'),
|
||||
), $this);
|
||||
|
||||
$this->addToClientMap($client, $integrationEntity, $externalAccountEntity, $userId);
|
||||
|
||||
return $client;
|
||||
}
|
||||
|
||||
protected function addToClientMap($client, $integrationEntity, $externalAccountEntity, $userId)
|
||||
{
|
||||
$this->clientMap[spl_object_hash($client)] = array(
|
||||
'client' => $client,
|
||||
'userId' => $userId,
|
||||
'integration' => $integrationEntity->id,
|
||||
'integrationEntity' => $integrationEntity,
|
||||
'externalAccountEntity' => $externalAccountEntity,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM - Open Source CRM application.
|
||||
* Copyright (C) 2014 Yuri Kuznetsov, Taras Machyshyn, Oleksiy Avramenko
|
||||
* Website: http://www.espocrm.com
|
||||
*
|
||||
* EspoCRM is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* EspoCRM is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with EspoCRM. If not, see http://www.gnu.org/licenses/.
|
||||
************************************************************************/
|
||||
|
||||
namespace Espo\Core\ExternalAccount\Clients;
|
||||
|
||||
use \Espo\Core\Exceptions\Error;
|
||||
|
||||
class Google extends OAuth2Abstract
|
||||
{
|
||||
protected function getPingUrl()
|
||||
{
|
||||
return 'https://www.googleapis.com/calendar/v3/users/me/calendarList';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM - Open Source CRM application.
|
||||
* Copyright (C) 2014 Yuri Kuznetsov, Taras Machyshyn, Oleksiy Avramenko
|
||||
* Website: http://www.espocrm.com
|
||||
*
|
||||
* EspoCRM is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* EspoCRM is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with EspoCRM. If not, see http://www.gnu.org/licenses/.
|
||||
************************************************************************/
|
||||
|
||||
namespace Espo\Core\ExternalAccount\Clients;
|
||||
|
||||
interface IClient
|
||||
{
|
||||
public function getParam($name);
|
||||
|
||||
public function setParam($name, $value);
|
||||
|
||||
public function setParams(array $params);
|
||||
|
||||
public function ping();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,209 @@
|
||||
<?php
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM - Open Source CRM application.
|
||||
* Copyright (C) 2014 Yuri Kuznetsov, Taras Machyshyn, Oleksiy Avramenko
|
||||
* Website: http://www.espocrm.com
|
||||
*
|
||||
* EspoCRM is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* EspoCRM is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with EspoCRM. If not, see http://www.gnu.org/licenses/.
|
||||
************************************************************************/
|
||||
|
||||
namespace Espo\Core\ExternalAccount\Clients;
|
||||
|
||||
use \Espo\Core\Exceptions\Error;
|
||||
|
||||
use \Espo\Core\ExternalAccount\OAuth2\Client;
|
||||
|
||||
abstract class OAuth2Abstract implements IClient
|
||||
{
|
||||
protected $client = null;
|
||||
|
||||
protected $manager = null;
|
||||
|
||||
protected $paramList = array(
|
||||
'endpoint',
|
||||
'tokenEndpoint',
|
||||
'clientId',
|
||||
'clientSecret',
|
||||
'tokenType',
|
||||
'accessToken',
|
||||
'refreshToken',
|
||||
'redirectUri',
|
||||
);
|
||||
|
||||
protected $clientId = null;
|
||||
|
||||
protected $clientSecret = null;
|
||||
|
||||
protected $accessToken = null;
|
||||
|
||||
protected $refreshToken = null;
|
||||
|
||||
protected $redirectUri = null;
|
||||
|
||||
public function __construct($client, array $params = array(), $manager = null)
|
||||
{
|
||||
$this->client = $client;
|
||||
|
||||
$this->setParams($params);
|
||||
|
||||
$this->manager = $manager;
|
||||
}
|
||||
|
||||
public function getParam($name)
|
||||
{
|
||||
if (in_array($name, $this->paramList)) {
|
||||
return $this->$name;
|
||||
}
|
||||
}
|
||||
|
||||
public function setParam($name, $value)
|
||||
{
|
||||
if (in_array($name, $this->paramList)) {
|
||||
$methodName = 'set' . ucfirst($name);
|
||||
if (method_exists($this->client, $methodName)) {
|
||||
$this->client->$methodName($value);
|
||||
}
|
||||
$this->$name = $value;
|
||||
}
|
||||
}
|
||||
|
||||
public function setParams(array $params)
|
||||
{
|
||||
foreach ($this->paramList as $name) {
|
||||
if (!empty($params[$name])) {
|
||||
$this->setParam($name, $params[$name]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected function afterTokenRefreshed($data)
|
||||
{
|
||||
if ($this->manager) {
|
||||
$this->manager->storeAccessToken(spl_object_hash($this), $data);
|
||||
}
|
||||
}
|
||||
|
||||
public function getAccessTokenFromAuthorizationCode($code)
|
||||
{
|
||||
$r = $this->client->getAccessToken($this->getParam('tokenEndpoint'), Client::GRANT_TYPE_AUTHORIZATION_CODE, array(
|
||||
'code' => $code,
|
||||
'redirect_uri' => $this->getParam('redirectUri')
|
||||
));
|
||||
|
||||
|
||||
if ($r['code'] == 200) {
|
||||
$data = array();
|
||||
if (!empty($r['result'])) {
|
||||
$data['accessToken'] = $r['result']['access_token'];
|
||||
$data['tokenType'] = $r['result']['token_type'];
|
||||
$data['refreshToken'] = $r['result']['refresh_token'];
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
abstract protected function getPingUrl();
|
||||
|
||||
public function ping()
|
||||
{
|
||||
if (empty($this->accessToken) || empty($this->clientId) || empty($this->clientSecret)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$url = $this->getPingUrl();
|
||||
|
||||
try {
|
||||
$this->request($url);
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public function request($url, $params = array(), $httpMethod = Client::HTTP_METHOD_GET, $allowRenew = true)
|
||||
{
|
||||
$r = $this->client->request($url, $params, $httpMethod);
|
||||
|
||||
$code = null;
|
||||
if (!empty($r['code'])) {
|
||||
$code = $r['code'];
|
||||
}
|
||||
|
||||
if ($code == 200) {
|
||||
return $r['result'];
|
||||
} else {
|
||||
$handledData = $this->handleErrorResponse($r);
|
||||
|
||||
if ($allowRenew && is_array($handledData)) {
|
||||
if ($handledData['action'] == 'refreshToken') {
|
||||
if ($this->refreshToken()) {
|
||||
return $this->request($url, $params, $httpMethod, false);
|
||||
}
|
||||
} else if ($handledData['action'] == 'renew') {
|
||||
return $this->request($url, $params, $httpMethod, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
throw new Error("Error after requesting {$httpMethod} {$url}.", $code);
|
||||
}
|
||||
|
||||
protected function refreshToken()
|
||||
{
|
||||
if (!empty($this->refreshToken)) {
|
||||
$r = $this->client->getAccessToken($this->getParam('tokenEndpoint'), Client::GRANT_TYPE_REFRESH_TOKEN, array(
|
||||
'refresh_token' => $this->refreshToken,
|
||||
));
|
||||
if ($r['code'] == 200) {
|
||||
if (is_array($r['result'])) {
|
||||
if (!empty($r['result']['access_token'])) {
|
||||
$data = array();
|
||||
$data['accessToken'] = $r['result']['access_token'];
|
||||
$data['tokenType'] = $r['result']['token_type'];
|
||||
|
||||
$this->setParams($data);
|
||||
$this->afterTokenRefreshed($data);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected function handleErrorResponse($r)
|
||||
{
|
||||
if ($r['code'] == 401 && !empty($r['result'])) {
|
||||
$result = $r['result'];
|
||||
if (strpos($r['header'], 'error=invalid_token') !== false) {
|
||||
return array(
|
||||
'action' => 'refreshToken'
|
||||
);
|
||||
} else {
|
||||
return array(
|
||||
'action' => 'renew'
|
||||
);
|
||||
}
|
||||
} else if ($r['code'] == 400 && !empty($r['result'])) {
|
||||
if ($r['result']['error'] == 'invalid_token') {
|
||||
return array(
|
||||
'action' => 'refreshToken'
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,248 @@
|
||||
<?php
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM - Open Source CRM application.
|
||||
* Copyright (C) 2014 Yuri Kuznetsov, Taras Machyshyn, Oleksiy Avramenko
|
||||
* Website: http://www.espocrm.com
|
||||
*
|
||||
* EspoCRM is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* EspoCRM is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with EspoCRM. If not, see http://www.gnu.org/licenses/.
|
||||
************************************************************************/
|
||||
|
||||
namespace Espo\Core\ExternalAccount\OAuth2;
|
||||
|
||||
class Client
|
||||
{
|
||||
const AUTH_TYPE_URI = 0;
|
||||
const AUTH_TYPE_AUTHORIZATION_BASIC = 1;
|
||||
const AUTH_TYPE_FORM = 2;
|
||||
|
||||
const TOKEN_TYPE_URI = 'Uri';
|
||||
const TOKEN_TYPE_BEARER = 'Bearer';
|
||||
const TOKEN_TYPE_OAUTH = 'OAuth';
|
||||
|
||||
const CONTENT_TYPE_APPLICATION = 0;
|
||||
const CONTENT_TYPE_MULTIPART = 1;
|
||||
|
||||
const HTTP_METHOD_GET = 'GET';
|
||||
const HTTP_METHOD_POST = 'POST';
|
||||
const HTTP_METHOD_PUT = 'PUT';
|
||||
|
||||
const HTTP_METHOD_DELETE = 'DELETE';
|
||||
const HTTP_METHOD_HEAD = 'HEAD';
|
||||
const HTTP_METHOD_PATCH = 'PATCH';
|
||||
|
||||
const GRANT_TYPE_AUTHORIZATION_CODE = 'authorization_code';
|
||||
const GRANT_TYPE_REFRESH_TOKEN = 'refresh_token';
|
||||
const GRANT_TYPE_PASSWORD = 'password';
|
||||
const GRANT_TYPE_CLIENT_CREDENTIALS = 'client_credentials';
|
||||
|
||||
protected $clientId = null;
|
||||
|
||||
protected $clientSecret = null;
|
||||
|
||||
protected $accessToken = null;
|
||||
|
||||
protected $authType = self::AUTH_TYPE_URI;
|
||||
|
||||
protected $tokenType = self::TOKEN_TYPE_URI;
|
||||
|
||||
protected $accessTokenSecret = null;
|
||||
|
||||
protected $accessTokenParamName = 'access_token';
|
||||
|
||||
protected $certificateFile = null;
|
||||
|
||||
protected $curlOptions = array();
|
||||
|
||||
public function __construct(array $params = array())
|
||||
{
|
||||
if (!extension_loaded('curl')) {
|
||||
throw new \Exception('CURL extension not found.');
|
||||
}
|
||||
}
|
||||
|
||||
public function setClientId($clientId)
|
||||
{
|
||||
$this->clientId = $clientId;
|
||||
}
|
||||
|
||||
public function setClientSecret($clientSecret)
|
||||
{
|
||||
$this->clientSecret = $clientSecret;
|
||||
}
|
||||
|
||||
public function setAccessToken($accessToken)
|
||||
{
|
||||
$this->accessToken = $accessToken;
|
||||
}
|
||||
|
||||
public function setAuthType($authType)
|
||||
{
|
||||
$this->authType = $authType;
|
||||
}
|
||||
|
||||
public function setCertificateFile($certificateFile)
|
||||
{
|
||||
$this->certificateFile = $certificateFile;
|
||||
}
|
||||
|
||||
public function setCurlOption($option, $value)
|
||||
{
|
||||
$this->curlOptions[$option] = $value;
|
||||
}
|
||||
|
||||
public function setCurlOptions($options)
|
||||
{
|
||||
$this->curlOptions = array_merge($this->curlOptions, $options);
|
||||
}
|
||||
|
||||
public function setTokenType($tokenType)
|
||||
{
|
||||
$this->tokenType = $tokenType;
|
||||
}
|
||||
|
||||
public function setAccessTokenSecret($accessTokenSecret)
|
||||
{
|
||||
$this->accessTokenSecret = $accessTokenSecret;
|
||||
}
|
||||
|
||||
public function request($url, $params = array(), $httpMethod = self::HTTP_METHOD_GET, array $httpHeaders = array(), $contentType = self::CONTENT_TYPE_MULTIPART)
|
||||
{
|
||||
if ($this->accessToken) {
|
||||
switch ($this->tokenType) {
|
||||
case self::TOKEN_TYPE_URI:
|
||||
$params[$this->accessTokenParamName] = $this->accessToken;
|
||||
break;
|
||||
case self::TOKEN_TYPE_BEARER:
|
||||
$httpHeaders['Authorization'] = 'Bearer ' . $this->accessToken;
|
||||
break;
|
||||
case self::TOKEN_TYPE_OAUTH:
|
||||
$httpHeaders['Authorization'] = 'OAuth ' . $this->accessToken;
|
||||
break;
|
||||
default:
|
||||
throw new \Exception('Unknown access token type.');
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return $this->execute($url, $params, $httpMethod, $httpHeaders, $contentType);
|
||||
}
|
||||
|
||||
private function execute($url, $params = array(), $httpMethod, array $httpHeaders = array(), $contentType = self::CONTENT_TYPE_MULTIPART)
|
||||
{
|
||||
$curlOptions = array(
|
||||
CURLOPT_RETURNTRANSFER => true,
|
||||
CURLOPT_SSL_VERIFYPEER => true,
|
||||
CURLOPT_CUSTOMREQUEST => $httpMethod
|
||||
);
|
||||
|
||||
switch ($httpMethod) {
|
||||
case self::HTTP_METHOD_POST:
|
||||
$curlOptions[CURLOPT_POST] = true;
|
||||
case self::HTTP_METHOD_PUT:
|
||||
case self::HTTP_METHOD_PATCH:
|
||||
if (self::CONTENT_TYPE_APPLICATION === $contentType) {
|
||||
$postFields = http_build_query($params, null, '&');
|
||||
}
|
||||
$curlOptions[CURLOPT_POSTFIELDS] = $postFields;
|
||||
break;
|
||||
case self::HTTP_METHOD_HEAD:
|
||||
$curlOptions[CURLOPT_NOBODY] = true;
|
||||
case self::HTTP_METHOD_DELETE:
|
||||
case self::HTTP_METHOD_GET:
|
||||
if (strpos($url, '?') === false) {
|
||||
$url .= '?';
|
||||
}
|
||||
$url .= http_build_query($params, null, '&');
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
$curlOptions[CURLOPT_URL] = $url;
|
||||
|
||||
$curlOptHttpHeader = array();
|
||||
foreach ($httpHeaders as $key => $value) {
|
||||
$curlOptHttpHeader[] = "{$key}: {$value}";
|
||||
}
|
||||
$curlOptions[CURLOPT_HTTPHEADER] = $curlOptHttpHeader;
|
||||
|
||||
$ch = curl_init();
|
||||
curl_setopt_array($ch, $curlOptions);
|
||||
|
||||
curl_setopt($ch, CURLOPT_HEADER, 1);
|
||||
|
||||
if (!empty($this->certificateFile)) {
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
|
||||
curl_setopt($ch, CURLOPT_CAINFO, $this->certificateFile);
|
||||
} else {
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
|
||||
}
|
||||
|
||||
if (!empty($this->curlOptions)) {
|
||||
curl_setopt_array($ch, $this->curlOptions);
|
||||
}
|
||||
|
||||
$response = curl_exec($ch);
|
||||
|
||||
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||
$contentType = curl_getinfo($ch, CURLINFO_CONTENT_TYPE);
|
||||
$headerSize = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
|
||||
|
||||
$responceHeader = substr($response, 0, $headerSize);
|
||||
$responceBody = substr($response, $headerSize);
|
||||
|
||||
$resultArray = null;
|
||||
|
||||
if ($curlError = curl_error($ch)) {
|
||||
throw new \Exception($curlError);
|
||||
} else {
|
||||
$resultArray = json_decode($responceBody, true);
|
||||
}
|
||||
curl_close($ch);
|
||||
|
||||
return array(
|
||||
'result' => (null !== $resultArray) ? $resultArray: $responceBody,
|
||||
'code' => intval($httpCode),
|
||||
'contentType' => $contentType,
|
||||
'header' => $responceHeader,
|
||||
);
|
||||
}
|
||||
|
||||
public function getAccessToken($url, $grantType, array $params)
|
||||
{
|
||||
$params['grant_type'] = $grantType;
|
||||
|
||||
$httpHeaders = array();
|
||||
switch ($this->clientAuth) {
|
||||
case self::AUTH_TYPE_URI:
|
||||
case self::AUTH_TYPE_FORM:
|
||||
$params['client_id'] = $this->clientId;
|
||||
$params['client_secret'] = $this->clientSecret;
|
||||
break;
|
||||
case self::AUTH_TYPE_AUTHORIZATION_BASIC:
|
||||
$params['client_id'] = $this->clientId;
|
||||
$httpHeaders['Authorization'] = 'Basic ' . base64_encode($this->clientId . ':' . $this->clientSecret);
|
||||
break;
|
||||
default:
|
||||
throw new \Exception();
|
||||
}
|
||||
|
||||
return $this->execute($url, $params, self::HTTP_METHOD_POST, $httpHeaders, self::CONTENT_TYPE_APPLICATION);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,6 +26,7 @@ use \Espo\ORM\EntityManager;
|
||||
use \Espo\ORM\EntityFactory;
|
||||
use \Espo\ORM\Entity;
|
||||
use \Espo\ORM\IEntity;
|
||||
use Espo\Core\Utils\Util;
|
||||
|
||||
use \Espo\Core\Interfaces\Injectable;
|
||||
|
||||
@@ -63,11 +64,38 @@ class RDB extends \Espo\ORM\Repositories\RDB implements Injectable
|
||||
{
|
||||
$this->handleEmailAddressParams($params);
|
||||
$this->handlePhoneNumberParams($params);
|
||||
$this->handleCurrencyParams($params);
|
||||
}
|
||||
|
||||
protected function handleCurrencyParams(&$params)
|
||||
{
|
||||
$entityName = $this->entityName;
|
||||
|
||||
$metadata = $this->getMetadata();
|
||||
|
||||
if (!$metadata) {
|
||||
return;
|
||||
}
|
||||
|
||||
$defs = $metadata->get('entityDefs.' . $entityName);
|
||||
|
||||
foreach ($defs['fields'] as $field => $d) {
|
||||
if (isset($d['type']) && $d['type'] == 'currency') {
|
||||
if (empty($params['customJoin'])) {
|
||||
$params['customJoin'] = '';
|
||||
}
|
||||
$alias = Util::toUnderScore($field) . "_currency_alias";
|
||||
$params['customJoin'] .= "
|
||||
LEFT JOIN currency AS `{$alias}` ON {$alias}.id = ".Util::toUnderScore($entityName).".".Util::toUnderScore($field)."_currency
|
||||
";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected function handleEmailAddressParams(&$params)
|
||||
{
|
||||
$entityName = $this->entityName;
|
||||
$entityName = $this->entityName;
|
||||
|
||||
$defs = $this->getEntityManager()->getMetadata()->get($entityName);
|
||||
if (!empty($defs['relations']) && array_key_exists('emailAddresses', $defs['relations'])) {
|
||||
|
||||
@@ -39,7 +39,7 @@ class Base
|
||||
protected $entityName;
|
||||
|
||||
protected $metadata;
|
||||
|
||||
|
||||
const MIN_LENGTH_FOR_CONTENT_SEARCH = 4;
|
||||
|
||||
public function __construct($entityManager, \Espo\Entities\User $user, Acl $acl, $metadata)
|
||||
@@ -84,7 +84,7 @@ class Base
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected function getTextFilterFields()
|
||||
{
|
||||
return $this->metadata->get("entityDefs.{$this->entityName}.collection.textFilterFields", array('name'));
|
||||
@@ -111,9 +111,9 @@ class Base
|
||||
$fieldDefs = $this->entityManager->getEntity($this->entityName)->getFields();
|
||||
$fieldList = $this->getTextFilterFields();
|
||||
$d = array();
|
||||
foreach ($fieldList as $field) {
|
||||
foreach ($fieldList as $field) {
|
||||
if (
|
||||
strlen($item['value']) >= self::MIN_LENGTH_FOR_CONTENT_SEARCH
|
||||
strlen($item['value']) >= self::MIN_LENGTH_FOR_CONTENT_SEARCH
|
||||
&&
|
||||
!empty($fieldDefs[$field]['type']) && $fieldDefs[$field]['type'] == 'text'
|
||||
) {
|
||||
@@ -122,7 +122,7 @@ class Base
|
||||
$d[$field . '*'] = $item['value'] . '%';
|
||||
}
|
||||
}
|
||||
$where['OR'] = $d;
|
||||
$where['OR'] = $d;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -174,7 +174,26 @@ class Base
|
||||
if (empty($result['whereClause'])) {
|
||||
$result['whereClause'] = array();
|
||||
}
|
||||
$result['whereClause']['name*'] = $params['q'] . '%';
|
||||
|
||||
$fieldDefs = $this->entityManager->getEntity($this->entityName)->getFields();
|
||||
|
||||
$value = $params['q'];
|
||||
|
||||
$fieldList = $this->getTextFilterFields();
|
||||
$d = array();
|
||||
foreach ($fieldList as $field) {
|
||||
if (
|
||||
strlen($item['value']) >= self::MIN_LENGTH_FOR_CONTENT_SEARCH
|
||||
&&
|
||||
!empty($fieldDefs[$field]['type']) && $fieldDefs[$field]['type'] == 'text'
|
||||
) {
|
||||
$d[$field . '*'] = '%' . $value . '%';
|
||||
} else {
|
||||
$d[$field . '*'] = $value . '%';
|
||||
}
|
||||
}
|
||||
|
||||
$result['whereClause']['OR'] = $d;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -297,6 +316,57 @@ class Base
|
||||
case 'future':
|
||||
$part[$item['field'] . '>'] = date('Y-m-d');
|
||||
break;
|
||||
case 'currentMonth':
|
||||
$dt = new \DateTime();
|
||||
$part['AND'] = array(
|
||||
$item['field'] . '>=' => $dt->modify('first day of this month')->format('Y-m-d'),
|
||||
$item['field'] . '<' => $dt->add(new \DateInterval('P1M'))->format('Y-m-d'),
|
||||
);
|
||||
break;
|
||||
case 'lastMonth':
|
||||
$dt = new \DateTime();
|
||||
$part['AND'] = array(
|
||||
$item['field'] . '>=' => $dt->modify('first day of last month')->format('Y-m-d'),
|
||||
$item['field'] . '<' => $dt->add(new \DateInterval('P1M'))->format('Y-m-d'),
|
||||
);
|
||||
break;
|
||||
case 'currentQuarter':
|
||||
$dt = new \DateTime();
|
||||
$quarter = ceil($dt->format('m') / 3);
|
||||
$dt->modify('first day of January this year');
|
||||
$part['AND'] = array(
|
||||
$item['field'] . '>=' => $dt->add(new \DateInterval('P'.(($quarter - 1) * 3).'M'))->format('Y-m-d'),
|
||||
$item['field'] . '<' => $dt->add(new \DateInterval('P3M'))->format('Y-m-d'),
|
||||
);
|
||||
break;
|
||||
case 'lastQuarter':
|
||||
$dt = new \DateTime();
|
||||
$quarter = ceil($dt->format('m') / 3);
|
||||
$dt->modify('first day of January this year');
|
||||
$quarter--;
|
||||
if ($quarter == 0) {
|
||||
$quarter = 4;
|
||||
$dt->sub('P1Y');
|
||||
}
|
||||
$part['AND'] = array(
|
||||
$item['field'] . '>=' => $dt->add(new \DateInterval('P'.(($quarter - 1) * 3).'M'))->format('Y-m-d'),
|
||||
$item['field'] . '<' => $dt->add(new \DateInterval('P3M'))->format('Y-m-d'),
|
||||
);
|
||||
break;
|
||||
case 'currentYear':
|
||||
$dt = new \DateTime();
|
||||
$part['AND'] = array(
|
||||
$item['field'] . '>=' => $dt->modify('first day of January this year')->format('Y-m-d'),
|
||||
$item['field'] . '<' => $dt->add(new \DateInterval('P1Y'))->format('Y-m-d'),
|
||||
);
|
||||
break;
|
||||
case 'lastYear':
|
||||
$dt = new \DateTime();
|
||||
$part['AND'] = array(
|
||||
$item['field'] . '>=' => $dt->modify('first day of January last year')->format('Y-m-d'),
|
||||
$item['field'] . '<' => $dt->add(new \DateInterval('P1Y'))->format('Y-m-d'),
|
||||
);
|
||||
break;
|
||||
case 'between':
|
||||
if (is_array($item['value'])) {
|
||||
$part['AND'] = array(
|
||||
|
||||
@@ -26,11 +26,14 @@ use Espo\Core\Exceptions\Error;
|
||||
|
||||
class UpgradeManager extends Upgrades\Base
|
||||
{
|
||||
protected $packagePath = 'data/upload/upgrades';
|
||||
protected $name = 'Upgrade';
|
||||
|
||||
protected $scriptNames = array(
|
||||
'before' => 'BeforeUpgrade',
|
||||
'after' => 'AfterUpgrade',
|
||||
protected $params = array(
|
||||
'packagePath' => 'data/upload/upgrades',
|
||||
|
||||
'scriptNames' => array(
|
||||
'before' => 'BeforeUpgrade',
|
||||
'after' => 'AfterUpgrade',
|
||||
)
|
||||
);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,102 @@
|
||||
<?php
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM - Open Source CRM application.
|
||||
* Copyright (C) 2014 Yuri Kuznetsov, Taras Machyshyn, Oleksiy Avramenko
|
||||
* Website: http://www.espocrm.com
|
||||
*
|
||||
* EspoCRM is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* EspoCRM is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with EspoCRM. If not, see http://www.gnu.org/licenses/.
|
||||
************************************************************************/
|
||||
|
||||
namespace Espo\Core\Upgrades;
|
||||
|
||||
use Espo\Core\Exceptions\Error;
|
||||
|
||||
class ActionManager
|
||||
{
|
||||
private $managerName;
|
||||
|
||||
private $container;
|
||||
|
||||
private $objects;
|
||||
|
||||
protected $currentAction;
|
||||
|
||||
protected $params;
|
||||
|
||||
public function __construct($managerName, $container, $params)
|
||||
{
|
||||
$this->managerName = $managerName;
|
||||
$this->container = $container;
|
||||
|
||||
$params['name'] = $managerName;
|
||||
$this->params = $params;
|
||||
}
|
||||
|
||||
protected function getManagerName()
|
||||
{
|
||||
return $this->managerName;
|
||||
}
|
||||
|
||||
protected function getContainer()
|
||||
{
|
||||
return $this->container;
|
||||
}
|
||||
|
||||
public function setAction($action)
|
||||
{
|
||||
$this->currentAction = $action;
|
||||
}
|
||||
|
||||
public function getAction()
|
||||
{
|
||||
return $this->currentAction;
|
||||
}
|
||||
|
||||
public function getParams()
|
||||
{
|
||||
return $this->params;
|
||||
}
|
||||
|
||||
public function run($data)
|
||||
{
|
||||
$object = $this->getObject();
|
||||
|
||||
return $object->run($data);
|
||||
}
|
||||
|
||||
public function getManifest()
|
||||
{
|
||||
return $this->getObject()->getManifest();
|
||||
}
|
||||
|
||||
protected function getObject()
|
||||
{
|
||||
$managerName = $this->getManagerName();
|
||||
$actionName = $this->getAction();
|
||||
|
||||
if (!isset($this->objects[$managerName][$actionName])) {
|
||||
$class = '\Espo\Core\Upgrades\Actions\\' . ucfirst($managerName) . '\\' . ucfirst($actionName);
|
||||
|
||||
if (!class_exists($class)) {
|
||||
throw new Error('Could not find an action ['.ucfirst($actionName).'], class ['.$class.'].');
|
||||
}
|
||||
|
||||
$this->objects[$managerName][$actionName] = new $class($this->container, $this);
|
||||
}
|
||||
|
||||
return $this->objects[$managerName][$actionName];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,488 @@
|
||||
<?php
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM - Open Source CRM application.
|
||||
* Copyright (C) 2014 Yuri Kuznetsov, Taras Machyshyn, Oleksiy Avramenko
|
||||
* Website: http://www.espocrm.com
|
||||
*
|
||||
* EspoCRM is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* EspoCRM is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with EspoCRM. If not, see http://www.gnu.org/licenses/.
|
||||
************************************************************************/
|
||||
|
||||
namespace Espo\Core\Upgrades\Actions;
|
||||
|
||||
use Espo\Core\Utils\Util,
|
||||
Espo\Core\Utils\Json,
|
||||
Espo\Core\Exceptions\Error;
|
||||
|
||||
abstract class Base
|
||||
{
|
||||
private $container;
|
||||
|
||||
private $actionManager;
|
||||
|
||||
private $zipUtil;
|
||||
|
||||
private $fileManager;
|
||||
|
||||
private $config;
|
||||
|
||||
private $entityManager;
|
||||
|
||||
protected $data;
|
||||
|
||||
protected $params = null;
|
||||
|
||||
protected $processId = null;
|
||||
|
||||
protected $manifestName = 'manifest.json';
|
||||
|
||||
protected $packagePostfix = 'z';
|
||||
|
||||
/**
|
||||
* Directory name of files in a package
|
||||
*/
|
||||
const FILES = 'files';
|
||||
|
||||
/**
|
||||
* Directory name of scripts in a package
|
||||
*/
|
||||
const SCRIPTS = 'scripts';
|
||||
|
||||
/**
|
||||
* Package types
|
||||
*/
|
||||
protected $packageTypes = array(
|
||||
'upgrade' => 'upgrade',
|
||||
'extension' => 'extension',
|
||||
);
|
||||
|
||||
/**
|
||||
* Default package type
|
||||
*/
|
||||
protected $defaultPackageType = 'extension';
|
||||
|
||||
|
||||
public function __construct(\Espo\Core\Container $container, \Espo\Core\Upgrades\ActionManager $actionManager)
|
||||
{
|
||||
$this->container = $container;
|
||||
$this->actionManager = $actionManager;
|
||||
$this->params = $actionManager->getParams();
|
||||
|
||||
$this->zipUtil = new \Espo\Core\Utils\File\ZipArchive($container->get('fileManager'));
|
||||
}
|
||||
|
||||
public function __destruct()
|
||||
{
|
||||
$this->processId = null;
|
||||
$this->data = null;
|
||||
}
|
||||
|
||||
protected function getContainer()
|
||||
{
|
||||
return $this->container;
|
||||
}
|
||||
|
||||
protected function getActionManager()
|
||||
{
|
||||
return $this->actionManager;
|
||||
}
|
||||
|
||||
protected function getParams($name = null)
|
||||
{
|
||||
if (isset($this->params[$name])) {
|
||||
return $this->params[$name];
|
||||
}
|
||||
|
||||
return $this->params;
|
||||
}
|
||||
|
||||
protected function getZipUtil()
|
||||
{
|
||||
return $this->zipUtil;
|
||||
}
|
||||
|
||||
protected function getFileManager()
|
||||
{
|
||||
if (!isset($this->fileManager)) {
|
||||
$this->fileManager = $this->getContainer()->get('fileManager');
|
||||
}
|
||||
return $this->fileManager;
|
||||
}
|
||||
|
||||
protected function getConfig()
|
||||
{
|
||||
if (!isset($this->config)) {
|
||||
$this->config = $this->getContainer()->get('config');
|
||||
}
|
||||
return $this->config;
|
||||
}
|
||||
|
||||
protected function getEntityManager()
|
||||
{
|
||||
if (!isset($this->entityManager)) {
|
||||
$this->entityManager = $this->getContainer()->get('entityManager');
|
||||
}
|
||||
return $this->entityManager;
|
||||
}
|
||||
|
||||
protected function throwErrorAndRemovePackage($errorMessage = '')
|
||||
{
|
||||
$this->deletePackageFiles();
|
||||
$this->deletePackageArchive();
|
||||
throw new Error($errorMessage);
|
||||
}
|
||||
|
||||
abstract public function run($data);
|
||||
|
||||
protected function createProcessId()
|
||||
{
|
||||
if (isset($this->processId)) {
|
||||
throw new Error('Another installation process is currently running.');
|
||||
}
|
||||
|
||||
$this->processId = uniqid();
|
||||
|
||||
return $this->processId;
|
||||
}
|
||||
|
||||
protected function getProcessId()
|
||||
{
|
||||
if (!isset($this->processId)) {
|
||||
throw new Error('Installation ID was not specified.');
|
||||
}
|
||||
|
||||
return $this->processId;
|
||||
}
|
||||
|
||||
protected function setProcessId($processId)
|
||||
{
|
||||
$this->processId = $processId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if version of upgrade/extension is acceptable to current version of EspoCRM
|
||||
*
|
||||
* @param string $version
|
||||
* @return boolean
|
||||
*/
|
||||
protected function isAcceptable()
|
||||
{
|
||||
$res = $this->checkPackageType();
|
||||
$res &= $this->checkVersions();
|
||||
|
||||
return (bool) $res;
|
||||
}
|
||||
|
||||
protected function checkVersions()
|
||||
{
|
||||
$manifest = $this->getManifest();
|
||||
|
||||
/** check acceptable versions */
|
||||
$version = $manifest['acceptableVersions'];
|
||||
if (empty($version)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$currentVersion = $this->getConfig()->get('version');
|
||||
|
||||
if (is_string($version)) {
|
||||
$version = (array) $version;
|
||||
}
|
||||
|
||||
foreach ($version as $strVersion) {
|
||||
|
||||
$strVersion = trim($strVersion);
|
||||
|
||||
if ($strVersion == $currentVersion) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$strVersion = str_replace('\\', '', $strVersion);
|
||||
$strVersion = preg_quote($strVersion);
|
||||
$strVersion = str_replace('\\*', '+', $strVersion);
|
||||
|
||||
if (preg_match('/^'.$strVersion.'/', $currentVersion)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
$this->throwErrorAndRemovePackage('Your EspoCRM version doesn\'t match for this installation package.');
|
||||
}
|
||||
|
||||
protected function checkPackageType()
|
||||
{
|
||||
$manifest = $this->getManifest();
|
||||
|
||||
/** check package type */
|
||||
$type = strtolower( $this->getParams('name') );
|
||||
$manifestType = isset($manifest['type']) ? strtolower($manifest['type']) : $this->defaultPackageType;
|
||||
|
||||
if (!in_array($manifestType, $this->packageTypes)) {
|
||||
$this->throwErrorAndRemovePackage('Unknown package type.');
|
||||
}
|
||||
|
||||
if ($type != $manifestType) {
|
||||
$this->throwErrorAndRemovePackage('Wrong package type. You cannot install '.$manifestType.' package via '.ucfirst($type).' Manager.');
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Run scripts by type
|
||||
* @param string $type Ex. "before", "after"
|
||||
* @return void
|
||||
*/
|
||||
protected function runScript($type)
|
||||
{
|
||||
$packagePath = $this->getPackagePath();
|
||||
$scriptNames = $this->getParams('scriptNames');
|
||||
|
||||
$scriptName = $scriptNames[$type];
|
||||
if (!isset($scriptName)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$beforeInstallScript = Util::concatPath( array($packagePath, self::SCRIPTS, $scriptName) ) . '.php';
|
||||
|
||||
if (file_exists($beforeInstallScript)) {
|
||||
require_once($beforeInstallScript);
|
||||
$script = new $scriptName();
|
||||
|
||||
try {
|
||||
$script->run($this->getContainer());
|
||||
} catch (\Exception $e) {
|
||||
$this->throwErrorAndRemovePackage($e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get package path
|
||||
*
|
||||
* @param string $processId
|
||||
* @return string
|
||||
*/
|
||||
protected function getPath($name = 'packagePath', $isPackage = false)
|
||||
{
|
||||
$postfix = $isPackage ? $this->packagePostfix : '';
|
||||
|
||||
$processId = $this->getProcessId();
|
||||
$path = Util::concatPath($this->getParams($name), $processId);
|
||||
|
||||
return $path . $postfix;
|
||||
}
|
||||
|
||||
protected function getPackagePath($isPackage = false)
|
||||
{
|
||||
return $this->getPath('packagePath', $isPackage);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of files defined in manifest.json
|
||||
*
|
||||
* @return [type] [description]
|
||||
*/
|
||||
protected function getDeleteFileList()
|
||||
{
|
||||
$manifest = $this->getManifest();
|
||||
|
||||
if (!empty($manifest['delete'])) {
|
||||
return $manifest['delete'];
|
||||
}
|
||||
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete files defined in a manifest
|
||||
*
|
||||
* @return boolen
|
||||
*/
|
||||
protected function deleteFiles()
|
||||
{
|
||||
$deleteFileList = $this->getDeleteFileList();
|
||||
|
||||
if (!empty($deleteFileList)) {
|
||||
return $this->getFileManager()->remove($deleteFileList);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
protected function getCopyFileList()
|
||||
{
|
||||
if (!isset($this->data['fileList'])) {
|
||||
$packagePath = $this->getPackagePath();
|
||||
$filesPath = Util::concatPath($packagePath, self::FILES);
|
||||
|
||||
$this->data['fileList'] = $this->getFileManager()->getFileList($filesPath, true, '', 'all', true);
|
||||
}
|
||||
|
||||
return $this->data['fileList'];
|
||||
}
|
||||
|
||||
protected function copy($sourcePath, $destPath, $recursively = false, array $fileList = null, $copyOnlyFiles = false)
|
||||
{
|
||||
try {
|
||||
$res = $this->getFileManager()->copy($sourcePath, $destPath, $recursively, $fileList, $copyOnlyFiles);
|
||||
} catch (\Exception $e) {
|
||||
$this->throwErrorAndRemovePackage($e->getMessage());
|
||||
}
|
||||
|
||||
return $res;
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy files from upgrade/extension package
|
||||
*
|
||||
* @param string $processId
|
||||
* @return boolean
|
||||
*/
|
||||
protected function copyFiles()
|
||||
{
|
||||
$packagePath = $this->getPackagePath();
|
||||
$filesPath = Util::concatPath($packagePath, self::FILES);
|
||||
|
||||
return $this->copy($filesPath, '', true);
|
||||
}
|
||||
|
||||
public function getManifest()
|
||||
{
|
||||
if (!isset($this->data['manifest'])) {
|
||||
$packagePath = $this->getPackagePath();
|
||||
|
||||
$manifestPath = Util::concatPath($packagePath, $this->manifestName);
|
||||
if (!file_exists($manifestPath)) {
|
||||
$this->throwErrorAndRemovePackage('It\'s not an Installation package.');
|
||||
}
|
||||
|
||||
$manifestJson = $this->getFileManager()->getContents($manifestPath);
|
||||
$this->data['manifest'] = Json::decode($manifestJson, true);
|
||||
|
||||
if (!$this->data['manifest']) {
|
||||
$this->throwErrorAndRemovePackage('Syntax error in manifest.json.');
|
||||
}
|
||||
|
||||
if (!$this->checkManifest($this->data['manifest'])) {
|
||||
$this->throwErrorAndRemovePackage('Unsupported package.');
|
||||
}
|
||||
}
|
||||
|
||||
return $this->data['manifest'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the manifest is correct
|
||||
*
|
||||
* @param array $manifest
|
||||
* @return boolean
|
||||
*/
|
||||
protected function checkManifest(array $manifest)
|
||||
{
|
||||
$requiredFields = array(
|
||||
'name',
|
||||
'version',
|
||||
);
|
||||
|
||||
foreach ($requiredFields as $fieldName) {
|
||||
if (empty($manifest[$fieldName])) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Unzip a package archieve
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function unzipArchive($packagePath = null)
|
||||
{
|
||||
$packagePath = isset($packagePath) ? $packagePath : $this->getPackagePath();
|
||||
$packageArchivePath = $this->getPackagePath(true);
|
||||
|
||||
if (!file_exists($packageArchivePath)) {
|
||||
throw new Error('Package Archive doesn\'t exist.');
|
||||
}
|
||||
|
||||
$res = $this->getZipUtil()->unzip($packageArchivePath, $packagePath);
|
||||
if ($res === false) {
|
||||
throw new Error('Unnable to unzip the file - '.$packagePath.'.');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete temporary package files
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
protected function deletePackageFiles()
|
||||
{
|
||||
$packagePath = $this->getPackagePath();
|
||||
$res = $this->getFileManager()->removeInDir($packagePath, true);
|
||||
|
||||
return $res;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete temporary package archive
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
protected function deletePackageArchive()
|
||||
{
|
||||
$packageArchive = $this->getPackagePath(true);
|
||||
$res = $this->getFileManager()->removeFile($packageArchive);
|
||||
|
||||
return $res;
|
||||
}
|
||||
|
||||
protected function systemRebuild()
|
||||
{
|
||||
return $this->getContainer()->get('dataManager')->rebuild();
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute an action. For ex., execute uninstall action in install
|
||||
*
|
||||
* @param [type] $actionName [description]
|
||||
* @param [type] $data [description]
|
||||
* @return [type] [description]
|
||||
*/
|
||||
protected function executeAction($actionName, $data)
|
||||
{
|
||||
$currentAction = $this->getActionManager()->getAction();
|
||||
|
||||
$this->getActionManager()->setAction($actionName);
|
||||
$this->getActionManager()->run($data);
|
||||
|
||||
$this->getActionManager()->setAction($currentAction);
|
||||
}
|
||||
|
||||
protected function beforeRunAction()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
protected function afterRunAction()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM - Open Source CRM application.
|
||||
* Copyright (C) 2014 Yuri Kuznetsov, Taras Machyshyn, Oleksiy Avramenko
|
||||
* Website: http://www.espocrm.com
|
||||
*
|
||||
* EspoCRM is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* EspoCRM is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with EspoCRM. If not, see http://www.gnu.org/licenses/.
|
||||
************************************************************************/
|
||||
|
||||
namespace Espo\Core\Upgrades\Actions\Base;
|
||||
|
||||
class Delete extends \Espo\Core\Upgrades\Actions\Base
|
||||
{
|
||||
public function run($processId)
|
||||
{
|
||||
$GLOBALS['log']->debug('Delete package process ['.$processId.']: start run.');
|
||||
|
||||
if (empty($processId)) {
|
||||
throw new Error('Delete package package ID was not specified.');
|
||||
}
|
||||
|
||||
$this->setProcessId($processId);
|
||||
|
||||
$this->beforeRunAction();
|
||||
|
||||
/* delete a package */
|
||||
$this->deletePackage();
|
||||
|
||||
$this->afterRunAction();
|
||||
|
||||
$GLOBALS['log']->debug('Delete package process ['.$processId.']: end run.');
|
||||
}
|
||||
|
||||
protected function deletePackage()
|
||||
{
|
||||
$packageArchivePath = $this->getPackagePath(true);
|
||||
$res = $this->getFileManager()->removeFile($packageArchivePath);
|
||||
|
||||
return $res;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,112 @@
|
||||
<?php
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM - Open Source CRM application.
|
||||
* Copyright (C) 2014 Yuri Kuznetsov, Taras Machyshyn, Oleksiy Avramenko
|
||||
* Website: http://www.espocrm.com
|
||||
*
|
||||
* EspoCRM is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* EspoCRM is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with EspoCRM. If not, see http://www.gnu.org/licenses/.
|
||||
************************************************************************/
|
||||
|
||||
namespace Espo\Core\Upgrades\Actions\Base;
|
||||
|
||||
use Espo\Core\Exceptions\Error;
|
||||
|
||||
class Install extends \Espo\Core\Upgrades\Actions\Base
|
||||
{
|
||||
/**
|
||||
* Is copied extension files to Espo
|
||||
*
|
||||
* @var [type]
|
||||
*/
|
||||
protected $isCopied = null;
|
||||
|
||||
/**
|
||||
* Main installation process
|
||||
*
|
||||
* @param string $processId Upgrade/Extension ID, gotten in upload stage
|
||||
* @return bool
|
||||
*/
|
||||
public function run($processId)
|
||||
{
|
||||
$GLOBALS['log']->debug('Installation process ['.$processId.']: start run.');
|
||||
|
||||
if (empty($processId)) {
|
||||
throw new Error('Installation package ID was not specified.');
|
||||
}
|
||||
|
||||
$this->setProcessId($processId);
|
||||
|
||||
$this->isCopied = false;
|
||||
|
||||
/** check if an archive is unzipped, if no then unzip */
|
||||
$packagePath = $this->getPackagePath();
|
||||
if (!file_exists($packagePath)) {
|
||||
$this->unzipArchive();
|
||||
$this->isAcceptable();
|
||||
}
|
||||
|
||||
$this->beforeRunAction();
|
||||
|
||||
/* run before install script */
|
||||
$this->runScript('before');
|
||||
|
||||
/* remove files defined in a manifest */
|
||||
if (!$this->deleteFiles()) {
|
||||
$this->throwErrorAndRemovePackage('Permission denied to delete files.');
|
||||
}
|
||||
|
||||
/* copy files from directory "Files" to EspoCRM files */
|
||||
if (!$this->copyFiles()) {
|
||||
$this->throwErrorAndRemovePackage('Cannot copy files.');
|
||||
}
|
||||
$this->isCopied = true;
|
||||
|
||||
if (!$this->systemRebuild()) {
|
||||
$this->throwErrorAndRemovePackage('Error occurred while EspoCRM rebuild.');
|
||||
}
|
||||
|
||||
/* run before install script */
|
||||
$this->runScript('after');
|
||||
|
||||
$this->afterRunAction();
|
||||
|
||||
/* delete unziped files */
|
||||
$this->deletePackageFiles();
|
||||
|
||||
$GLOBALS['log']->debug('Installation process ['.$processId.']: end run.');
|
||||
}
|
||||
|
||||
protected function restoreFiles()
|
||||
{
|
||||
$backupPath = $this->getPath('backupPath');
|
||||
|
||||
$res = true;
|
||||
if ($this->isCopied) {
|
||||
$res &= $this->copy(array($backupPath, self::FILES), '', true);
|
||||
$GLOBALS['log']->info('Restore: copy back');
|
||||
}
|
||||
|
||||
$res &= $this->getFileManager()->removeInDir($backupPath, true);
|
||||
|
||||
return $res;
|
||||
}
|
||||
|
||||
protected function throwErrorAndRemovePackage($errorMessage = '')
|
||||
{
|
||||
$this->restoreFiles();
|
||||
parent::throwErrorAndRemovePackage($errorMessage);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,132 @@
|
||||
<?php
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM - Open Source CRM application.
|
||||
* Copyright (C) 2014 Yuri Kuznetsov, Taras Machyshyn, Oleksiy Avramenko
|
||||
* Website: http://www.espocrm.com
|
||||
*
|
||||
* EspoCRM is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* EspoCRM is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with EspoCRM. If not, see http://www.gnu.org/licenses/.
|
||||
************************************************************************/
|
||||
|
||||
namespace Espo\Core\Upgrades\Actions\Base;
|
||||
|
||||
use Espo\Core\Exceptions\Error,
|
||||
Espo\Core\Utils\Util;
|
||||
|
||||
class Uninstall extends \Espo\Core\Upgrades\Actions\Base
|
||||
{
|
||||
public function run($processId)
|
||||
{
|
||||
$GLOBALS['log']->debug('Uninstallation process ['.$processId.']: start run.');
|
||||
|
||||
if (empty($processId)) {
|
||||
throw new Error('Uninstallation package ID was not specified.');
|
||||
}
|
||||
|
||||
$this->setProcessId($processId);
|
||||
|
||||
$this->beforeRunAction();
|
||||
|
||||
/* run before install script */
|
||||
$this->runScript('beforeUninstall');
|
||||
|
||||
$backupPath = $this->getPath('backupPath');
|
||||
if (file_exists($backupPath)) {
|
||||
|
||||
/* remove extension files, saved in fileList */
|
||||
if (!$this->deleteFiles()) {
|
||||
throw new Error('Permission denied to delete files.');
|
||||
}
|
||||
|
||||
/* copy core files */
|
||||
if (!$this->copyFiles()) {
|
||||
throw new Error('Cannot copy files.');
|
||||
}
|
||||
}
|
||||
|
||||
if (!$this->systemRebuild()) {
|
||||
throw new Error('Error occurred while EspoCRM rebuild.');
|
||||
}
|
||||
|
||||
/* run before install script */
|
||||
$this->runScript('afterUninstall');
|
||||
|
||||
$this->afterRunAction();
|
||||
|
||||
/* delete backup files */
|
||||
$this->deletePackageFiles();
|
||||
|
||||
$GLOBALS['log']->debug('Uninstallation process ['.$processId.']: end run.');
|
||||
}
|
||||
|
||||
protected function getDeleteFileList()
|
||||
{
|
||||
$extensionEntity = $this->getExtensionEntity();
|
||||
return $extensionEntity->get('fileList');
|
||||
}
|
||||
|
||||
protected function restoreFiles()
|
||||
{
|
||||
$packagePath = $this->getPath('packagePath');
|
||||
$filesPath = Util::concatPath($packagePath, self::FILES);
|
||||
|
||||
if (!file_exists($filesPath)) {
|
||||
$this->unzipArchive($packagePath);
|
||||
}
|
||||
|
||||
$res = $this->copy($filesPath, '', true);
|
||||
$res &= $this->getFileManager()->removeInDir($packagePath, true);
|
||||
|
||||
return $res;
|
||||
}
|
||||
|
||||
protected function copyFiles()
|
||||
{
|
||||
$backupPath = $this->getPath('backupPath');
|
||||
$res = $this->copy(array($backupPath, self::FILES), '', true);
|
||||
|
||||
return $res;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get backup path
|
||||
*
|
||||
* @param string $processId
|
||||
* @return string
|
||||
*/
|
||||
protected function getPackagePath($isPackage = false)
|
||||
{
|
||||
if ($isPackage) {
|
||||
return $this->getPath('packagePath', $isPackage);
|
||||
}
|
||||
|
||||
return $this->getPath('backupPath');
|
||||
}
|
||||
|
||||
protected function deletePackageFiles()
|
||||
{
|
||||
$backupPath = $this->getPath('backupPath');
|
||||
$res = $this->getFileManager()->removeInDir($backupPath, true);
|
||||
|
||||
return $res;
|
||||
}
|
||||
|
||||
protected function throwErrorAndRemovePackage($errorMessage = '')
|
||||
{
|
||||
$this->restoreFiles();
|
||||
throw new Error($errorMessage);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM - Open Source CRM application.
|
||||
* Copyright (C) 2014 Yuri Kuznetsov, Taras Machyshyn, Oleksiy Avramenko
|
||||
* Website: http://www.espocrm.com
|
||||
*
|
||||
* EspoCRM is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* EspoCRM is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with EspoCRM. If not, see http://www.gnu.org/licenses/.
|
||||
************************************************************************/
|
||||
|
||||
namespace Espo\Core\Upgrades\Actions\Base;
|
||||
|
||||
use Espo\Core\Exceptions\Error;
|
||||
|
||||
class Upload extends \Espo\Core\Upgrades\Actions\Base
|
||||
{
|
||||
/**
|
||||
* Upload an upgrade/extension package
|
||||
*
|
||||
* @param [type] $contents
|
||||
* @return string ID of upgrade/extension process
|
||||
*/
|
||||
public function run($data)
|
||||
{
|
||||
$processId = $this->createProcessId();
|
||||
|
||||
$GLOBALS['log']->debug('Installation process ['.$processId.']: start upload the package.');
|
||||
|
||||
$packagePath = $this->getPackagePath();
|
||||
$packageArchivePath = $this->getPackagePath(true);
|
||||
|
||||
if (!empty($data)) {
|
||||
list($prefix, $contents) = explode(',', $data);
|
||||
$contents = base64_decode($contents);
|
||||
}
|
||||
|
||||
$res = $this->getFileManager()->putContents($packageArchivePath, $contents);
|
||||
if ($res === false) {
|
||||
throw new Error('Could not upload the package.');
|
||||
}
|
||||
|
||||
$this->unzipArchive();
|
||||
|
||||
$this->isAcceptable();
|
||||
|
||||
$GLOBALS['log']->debug('Installation process ['.$processId.']: end upload the package.');
|
||||
|
||||
return $processId;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM - Open Source CRM application.
|
||||
* Copyright (C) 2014 Yuri Kuznetsov, Taras Machyshyn, Oleksiy Avramenko
|
||||
* Website: http://www.espocrm.com
|
||||
*
|
||||
* EspoCRM is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* EspoCRM is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with EspoCRM. If not, see http://www.gnu.org/licenses/.
|
||||
************************************************************************/
|
||||
|
||||
namespace Espo\Core\Upgrades\Actions\Extension;
|
||||
|
||||
use Espo\Core\Exceptions\Error;
|
||||
|
||||
class Delete extends \Espo\Core\Upgrades\Actions\Base\Delete
|
||||
{
|
||||
protected $extensionEntity;
|
||||
|
||||
/**
|
||||
* Get entity of this extension
|
||||
*
|
||||
* @return \Espo\Entities\Extension
|
||||
*/
|
||||
protected function getExtensionEntity()
|
||||
{
|
||||
return $this->extensionEntity;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Extension Entity
|
||||
*
|
||||
* @param \Espo\Entities\Extension $extensionEntity
|
||||
*/
|
||||
protected function setExtensionEntity(\Espo\Entities\Extension $extensionEntity)
|
||||
{
|
||||
$this->extensionEntity = $extensionEntity;
|
||||
}
|
||||
|
||||
protected function beforeRunAction()
|
||||
{
|
||||
$processId = $this->getProcessId();
|
||||
|
||||
/** get extension entity */
|
||||
$extensionEntity = $this->getEntityManager()->getEntity('Extension', $processId);
|
||||
if (!isset($extensionEntity)) {
|
||||
throw new Error('Extension Entity not found.');
|
||||
}
|
||||
$this->setExtensionEntity($extensionEntity);
|
||||
}
|
||||
|
||||
protected function afterRunAction()
|
||||
{
|
||||
/** Delete extension entity */
|
||||
$extensionEntity = $this->getExtensionEntity();
|
||||
$this->getEntityManager()->removeEntity($extensionEntity);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,229 @@
|
||||
<?php
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM - Open Source CRM application.
|
||||
* Copyright (C) 2014 Yuri Kuznetsov, Taras Machyshyn, Oleksiy Avramenko
|
||||
* Website: http://www.espocrm.com
|
||||
*
|
||||
* EspoCRM is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* EspoCRM is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with EspoCRM. If not, see http://www.gnu.org/licenses/.
|
||||
************************************************************************/
|
||||
|
||||
namespace Espo\Core\Upgrades\Actions\Extension;
|
||||
|
||||
use Espo\Core\Exceptions\Error,
|
||||
Espo\Core\ExtensionManager;
|
||||
|
||||
class Install extends \Espo\Core\Upgrades\Actions\Base\Install
|
||||
{
|
||||
protected $extensionEntity = null;
|
||||
|
||||
protected function beforeRunAction()
|
||||
{
|
||||
$this->findExtension();
|
||||
if (!$this->isNew()) {
|
||||
$this->compareVersion();
|
||||
$this->uninstallExtension();
|
||||
$this->deleteExtension();
|
||||
}
|
||||
|
||||
$this->copyExistingFiles();
|
||||
}
|
||||
|
||||
protected function afterRunAction()
|
||||
{
|
||||
$this->storeExtension();
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy Existing files to backup directory
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function copyExistingFiles()
|
||||
{
|
||||
$fileList = $this->getCopyFileList();
|
||||
$backupPath = $this->getPath('backupPath');
|
||||
|
||||
$res = $this->copy('', array($backupPath, self::FILES), false, $fileList);
|
||||
|
||||
/** copy scripts files */
|
||||
$packagePath = $this->getPackagePath();
|
||||
$res &= $this->copy(array($packagePath, self::SCRIPTS), array($backupPath, self::SCRIPTS), true);
|
||||
|
||||
return $res;
|
||||
}
|
||||
|
||||
protected function restoreFiles()
|
||||
{
|
||||
$res = true;
|
||||
if ($this->isCopied) {
|
||||
$extensionFileList = $this->getCopyFileList();
|
||||
$res &= $this->getFileManager()->remove($extensionFileList);
|
||||
}
|
||||
|
||||
$res &= parent::restoreFiles();
|
||||
|
||||
return $res;
|
||||
}
|
||||
|
||||
protected function isNew()
|
||||
{
|
||||
$extensionEntity = $this->getExtensionEntity();
|
||||
|
||||
if (isset($extensionEntity)) {
|
||||
$id = $this->getExtensionEntity()->get('id');
|
||||
}
|
||||
|
||||
return isset($id) ? false : true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get extension ID. It's an ID of existing entity (if available) or Installation ID
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getExtensionId()
|
||||
{
|
||||
$extensionEntity = $this->getExtensionEntity();
|
||||
if (isset($extensionEntity)) {
|
||||
$extensionEntityId = $extensionEntity->get('id');
|
||||
}
|
||||
|
||||
if (!isset($extensionEntityId)) {
|
||||
return $this->getProcessId();
|
||||
}
|
||||
|
||||
return $extensionEntityId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get entity of this extension
|
||||
*
|
||||
* @return \Espo\Entities\Extension
|
||||
*/
|
||||
protected function getExtensionEntity()
|
||||
{
|
||||
return $this->extensionEntity;
|
||||
}
|
||||
|
||||
/**
|
||||
* Find Extension entity
|
||||
*
|
||||
* @return \Espo\Entities\Extension
|
||||
*/
|
||||
protected function findExtension()
|
||||
{
|
||||
$manifest = $this->getManifest();
|
||||
|
||||
$this->extensionEntity = $this->getEntityManager()->getRepository('Extension')->where(array(
|
||||
'name' => $manifest['name'],
|
||||
'isInstalled' => true,
|
||||
))->findOne();
|
||||
|
||||
return $this->extensionEntity;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a record of Extension Entity
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function storeExtension()
|
||||
{
|
||||
$entityManager = $this->getEntityManager();
|
||||
|
||||
$extensionEntity = $entityManager->getEntity('Extension', $this->getProcessId());
|
||||
if (!isset($extensionEntity)) {
|
||||
$extensionEntity = $entityManager->getEntity('Extension');
|
||||
}
|
||||
|
||||
$manifest = $this->getManifest();
|
||||
$fileList = $this->getCopyFileList();
|
||||
|
||||
$data = array(
|
||||
'id' => $this->getProcessId(),
|
||||
'name' => $manifest['name'],
|
||||
'isInstalled' => true,
|
||||
'version' => $manifest['version'],
|
||||
'fileList' => $fileList,
|
||||
'description' => $manifest['description'],
|
||||
);
|
||||
$extensionEntity->set($data);
|
||||
|
||||
return $entityManager->saveEntity($extensionEntity);
|
||||
}
|
||||
|
||||
/**
|
||||
* Compare version between installed and a new extensions
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function compareVersion()
|
||||
{
|
||||
$manifest = $this->getManifest();
|
||||
$extensionEntity = $this->getExtensionEntity();
|
||||
|
||||
if (isset($extensionEntity)) {
|
||||
$comparedVersion = version_compare($manifest['version'], $extensionEntity->get('version'));
|
||||
if ($comparedVersion <= 0) {
|
||||
$this->throwErrorAndRemovePackage('You cannot install an older version of this extension.');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Throw an exception and remove package files.
|
||||
* Redeclared to prevent of deleting a package of installed extension.
|
||||
*
|
||||
* @param string $errorMessage [description]
|
||||
* @return [type] [description]
|
||||
*/
|
||||
protected function throwErrorAndRemovePackage($errorMessage = '')
|
||||
{
|
||||
if (!$this->isNew()) {
|
||||
throw new Error($errorMessage);
|
||||
}
|
||||
|
||||
return parent::throwErrorAndRemovePackage($errorMessage);
|
||||
}
|
||||
|
||||
/**
|
||||
* If extension already installed, uninstall an old version
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function uninstallExtension()
|
||||
{
|
||||
$extensionEntity = $this->getExtensionEntity();
|
||||
|
||||
$this->executeAction(ExtensionManager::UNINSTALL, $extensionEntity->get('id'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete extension package
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function deleteExtension()
|
||||
{
|
||||
$extensionEntity = $this->getExtensionEntity();
|
||||
|
||||
$this->executeAction(ExtensionManager::DELETE, $extensionEntity->get('id'));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM - Open Source CRM application.
|
||||
* Copyright (C) 2014 Yuri Kuznetsov, Taras Machyshyn, Oleksiy Avramenko
|
||||
* Website: http://www.espocrm.com
|
||||
*
|
||||
* EspoCRM is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* EspoCRM is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with EspoCRM. If not, see http://www.gnu.org/licenses/.
|
||||
************************************************************************/
|
||||
|
||||
namespace Espo\Core\Upgrades\Actions\Extension;
|
||||
|
||||
use Espo\Core\Exceptions\Error;
|
||||
|
||||
class Uninstall extends \Espo\Core\Upgrades\Actions\Base\Uninstall
|
||||
{
|
||||
protected $extensionEntity;
|
||||
|
||||
/**
|
||||
* Get entity of this extension
|
||||
*
|
||||
* @return \Espo\Entities\Extension
|
||||
*/
|
||||
protected function getExtensionEntity()
|
||||
{
|
||||
return $this->extensionEntity;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Extension Entity
|
||||
*
|
||||
* @param \Espo\Entities\Extension $extensionEntity [description]
|
||||
*/
|
||||
protected function setExtensionEntity(\Espo\Entities\Extension $extensionEntity)
|
||||
{
|
||||
$this->extensionEntity = $extensionEntity;
|
||||
}
|
||||
|
||||
protected function beforeRunAction()
|
||||
{
|
||||
$processId = $this->getProcessId();
|
||||
|
||||
/** get extension entity */
|
||||
$extensionEntity = $this->getEntityManager()->getEntity('Extension', $processId);
|
||||
if (!isset($extensionEntity)) {
|
||||
throw new Error('Extension Entity not found.');
|
||||
}
|
||||
$this->setExtensionEntity($extensionEntity);
|
||||
}
|
||||
|
||||
protected function afterRunAction()
|
||||
{
|
||||
/** Set extension entity, isInstalled = false */
|
||||
$extensionEntity = $this->getExtensionEntity();
|
||||
|
||||
$extensionEntity->set('isInstalled', false);
|
||||
$this->getEntityManager()->saveEntity($extensionEntity);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM - Open Source CRM application.
|
||||
* Copyright (C) 2014 Yuri Kuznetsov, Taras Machyshyn, Oleksiy Avramenko
|
||||
* Website: http://www.espocrm.com
|
||||
*
|
||||
* EspoCRM is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* EspoCRM is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with EspoCRM. If not, see http://www.gnu.org/licenses/.
|
||||
************************************************************************/
|
||||
|
||||
namespace Espo\Core\Upgrades\Actions\Extension;
|
||||
|
||||
class Upload extends \Espo\Core\Upgrades\Actions\Base\Upload
|
||||
{
|
||||
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM - Open Source CRM application.
|
||||
* Copyright (C) 2014 Yuri Kuznetsov, Taras Machyshyn, Oleksiy Avramenko
|
||||
* Website: http://www.espocrm.com
|
||||
*
|
||||
* EspoCRM is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* EspoCRM is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with EspoCRM. If not, see http://www.gnu.org/licenses/.
|
||||
************************************************************************/
|
||||
|
||||
namespace Espo\Core\Upgrades\Actions\Upgrade;
|
||||
|
||||
class Install extends \Espo\Core\Upgrades\Actions\Base\Install
|
||||
{
|
||||
protected function systemRebuild()
|
||||
{
|
||||
$manifest = $this->getManifest();
|
||||
|
||||
$res = $this->getConfig()->set('version', $manifest['version']);
|
||||
if (method_exists($this->getConfig(), 'save')) {
|
||||
$res = $this->getConfig()->save();
|
||||
}
|
||||
$res &= parent::systemRebuild();
|
||||
|
||||
return $res;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete temporary package files
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
protected function deletePackageFiles()
|
||||
{
|
||||
$res = parent::deletePackageFiles();
|
||||
$res &= $this->deletePackageArchive();
|
||||
|
||||
return $res;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM - Open Source CRM application.
|
||||
* Copyright (C) 2014 Yuri Kuznetsov, Taras Machyshyn, Oleksiy Avramenko
|
||||
* Website: http://www.espocrm.com
|
||||
*
|
||||
* EspoCRM is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* EspoCRM is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with EspoCRM. If not, see http://www.gnu.org/licenses/.
|
||||
************************************************************************/
|
||||
|
||||
namespace Espo\Core\Upgrades\Actions\Upgrade;
|
||||
|
||||
class Upload extends \Espo\Core\Upgrades\Actions\Base\Upload
|
||||
{
|
||||
|
||||
}
|
||||
@@ -30,44 +30,23 @@ abstract class Base
|
||||
{
|
||||
private $container;
|
||||
|
||||
private $zipUtil;
|
||||
protected $name = null;
|
||||
|
||||
private $fileManager;
|
||||
protected $params = array();
|
||||
|
||||
private $config;
|
||||
const UPLOAD = 'upload';
|
||||
|
||||
protected $upgradeId = null;
|
||||
const INSTALL = 'install';
|
||||
|
||||
protected $manifestName = 'manifest.json';
|
||||
|
||||
protected $data;
|
||||
|
||||
protected $packagePath = null;
|
||||
|
||||
protected $packagePostfix = 'z';
|
||||
|
||||
protected $scriptNames = array(
|
||||
'before' => 'Before',
|
||||
'after' => 'After',
|
||||
);
|
||||
|
||||
protected $paths = array(
|
||||
'files' => 'files',
|
||||
'scripts' => 'scripts',
|
||||
);
|
||||
const UNINSTALL = 'uninstall';
|
||||
|
||||
const DELETE = 'delete';
|
||||
|
||||
public function __construct($container)
|
||||
{
|
||||
$this->container = $container;
|
||||
|
||||
$this->zipUtil = new \Espo\Core\Utils\File\ZipArchive($container->get('fileManager'));
|
||||
}
|
||||
|
||||
public function __destruct()
|
||||
{
|
||||
$this->upgradeId = null;
|
||||
$this->data = null;
|
||||
$this->actionManager = new ActionManager($this->name, $container, $this->params);
|
||||
}
|
||||
|
||||
protected function getContainer()
|
||||
@@ -75,319 +54,41 @@ abstract class Base
|
||||
return $this->container;
|
||||
}
|
||||
|
||||
protected function getZipUtil()
|
||||
protected function getActionManager()
|
||||
{
|
||||
return $this->zipUtil;
|
||||
}
|
||||
|
||||
protected function getFileManager()
|
||||
{
|
||||
if (!isset($this->fileManager)) {
|
||||
$this->fileManager = $this->getContainer()->get('fileManager');
|
||||
}
|
||||
return $this->fileManager;
|
||||
}
|
||||
|
||||
protected function getConfig()
|
||||
{
|
||||
if (!isset($this->config)) {
|
||||
$this->config = $this->getContainer()->get('config');
|
||||
}
|
||||
return $this->config;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Upload an upgrade package
|
||||
*
|
||||
* @param [type] $contents
|
||||
* @return string ID of upgrade process
|
||||
*/
|
||||
public function upload($data)
|
||||
{
|
||||
$upgradeId = $this->createUpgradeId();
|
||||
|
||||
$GLOBALS['log']->debug('Upgrade process ['.$upgradeId.']: start upload the package.');
|
||||
|
||||
$upgradePath = $this->getUpgradePath();
|
||||
$upgradePackagePath = $this->getUpgradePath(true);
|
||||
|
||||
if (!empty($data)) {
|
||||
list($prefix, $contents) = explode(',', $data);
|
||||
$contents = base64_decode($contents);
|
||||
}
|
||||
|
||||
$res = $this->getFileManager()->putContents($upgradePackagePath, $contents);
|
||||
if ($res === false) {
|
||||
throw new Error('Could not upload the package.');
|
||||
}
|
||||
|
||||
$res = $this->getZipUtil()->unzip($upgradePackagePath, $upgradePath);
|
||||
if ($res === false) {
|
||||
throw new Error('Unnable to unzip the file - '.$upgradePath.'.');
|
||||
}
|
||||
|
||||
if (!$this->isAcceptable()) {
|
||||
throw new Error("Your EspoCRM version doesn't match for this upgrade package.");
|
||||
}
|
||||
|
||||
$GLOBALS['log']->debug('Upgrade process ['.$upgradeId.']: end upload the package.');
|
||||
|
||||
return $upgradeId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Main upgrade process
|
||||
*
|
||||
* @param string $upgradeId Upgrade ID, gotten in upload stage
|
||||
* @return bool
|
||||
*/
|
||||
public function run($upgradeId)
|
||||
{
|
||||
$GLOBALS['log']->debug('Upgrade process ['.$upgradeId.']: start run.');
|
||||
|
||||
if (empty($upgradeId)) {
|
||||
throw new Error('Upgrade ID was not specified.');
|
||||
}
|
||||
|
||||
$this->setUpgradeId($upgradeId);
|
||||
|
||||
/* run before install script */
|
||||
$this->runScript('before');
|
||||
|
||||
/* remove files defined in a manifest */
|
||||
if (!$this->deleteFiles()) {
|
||||
throw new Error('Permission denied to delete files.');
|
||||
}
|
||||
|
||||
/* copy files from directory "Files" to EspoCRM files */
|
||||
if (!$this->copyFiles()) {
|
||||
throw new Error('Cannot copy files.');
|
||||
}
|
||||
|
||||
if (!$this->systemRebuild()) {
|
||||
throw new Error('Error occurred while EspoCRM rebuild.');
|
||||
}
|
||||
|
||||
/* run before install script */
|
||||
$this->runScript('after');
|
||||
|
||||
/* delete unziped files */
|
||||
$this->deletePackageFiles();
|
||||
|
||||
$GLOBALS['log']->debug('Upgrade process ['.$upgradeId.']: end run.');
|
||||
}
|
||||
|
||||
|
||||
protected function createUpgradeId()
|
||||
{
|
||||
if (isset($this->upgradeId)) {
|
||||
throw new Error('Another upgrade process is currently running.');
|
||||
}
|
||||
|
||||
$this->upgradeId = uniqid();
|
||||
|
||||
return $this->upgradeId;
|
||||
}
|
||||
|
||||
protected function getUpgradeId()
|
||||
{
|
||||
if (!isset($this->upgradeId)) {
|
||||
throw new Error("Upgrade ID was not specified.");
|
||||
}
|
||||
|
||||
return $this->upgradeId;
|
||||
}
|
||||
|
||||
protected function setUpgradeId($upgradeId)
|
||||
{
|
||||
$this->upgradeId = $upgradeId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if version of upgrade is acceptable to current version of EspoCRM
|
||||
*
|
||||
* @param string $version
|
||||
* @return boolean
|
||||
*/
|
||||
protected function isAcceptable()
|
||||
{
|
||||
$manifest = $this->getManifest();
|
||||
$version = $manifest['acceptableVersions'];
|
||||
|
||||
$currentVersion = $this->getConfig()->get('version');
|
||||
|
||||
if (is_string($version)) {
|
||||
$version = (array) $version;
|
||||
}
|
||||
|
||||
foreach ($version as $strVersion) {
|
||||
|
||||
$strVersion = trim($strVersion);
|
||||
|
||||
if ($strVersion == $currentVersion) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$strVersion = str_replace('\\', '', $strVersion);
|
||||
$strVersion = preg_quote($strVersion);
|
||||
$strVersion = str_replace('\\*', '+', $strVersion);
|
||||
|
||||
if (preg_match('/^'.$strVersion.'/', $currentVersion)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Run scripts by type
|
||||
* @param string $type Ex. "before", "after"
|
||||
* @return void
|
||||
*/
|
||||
protected function runScript($type)
|
||||
{
|
||||
$upgradePath = $this->getUpgradePath();
|
||||
|
||||
$scriptName = $this->scriptNames[$type];
|
||||
if (!isset($scriptName)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$beforeInstallScript = Util::concatPath( array($upgradePath, $this->paths['scripts'], $scriptName) ) . '.php';
|
||||
|
||||
if (file_exists($beforeInstallScript)) {
|
||||
require_once($beforeInstallScript);
|
||||
$script = new $scriptName();
|
||||
$script->run($this->getContainer());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get upgrade path
|
||||
*
|
||||
* @param string $upgradeId
|
||||
* @return string
|
||||
*/
|
||||
protected function getUpgradePath($isPackage = false)
|
||||
{
|
||||
$postfix = $isPackage ? $this->packagePostfix : '';
|
||||
|
||||
if (!isset($this->data['upgradePath'])) {
|
||||
$upgradeId = $this->getUpgradeId();
|
||||
$this->data['upgradePath'] = Util::concatPath($this->packagePath, $upgradeId);
|
||||
}
|
||||
|
||||
return $this->data['upgradePath'] . $postfix;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete files defined in a manifest
|
||||
*
|
||||
* @return boolen
|
||||
*/
|
||||
protected function deleteFiles()
|
||||
{
|
||||
$manifest = $this->getManifest();
|
||||
|
||||
if (!empty($manifest['delete'])) {
|
||||
return $this->getFileManager()->remove($manifest['delete']);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy files from upgrade package
|
||||
*
|
||||
* @param string $upgradeId
|
||||
* @return boolean
|
||||
*/
|
||||
protected function copyFiles()
|
||||
{
|
||||
$upgradePath = $this->getUpgradePath();
|
||||
$filesPath = Util::concatPath($upgradePath, $this->paths['files']);
|
||||
|
||||
return $this->getFileManager()->copy($filesPath, '', true);
|
||||
return $this->actionManager;
|
||||
}
|
||||
|
||||
public function getManifest()
|
||||
{
|
||||
if (!isset($this->data['manifest'])) {
|
||||
$upgradePath = $this->getUpgradePath();
|
||||
|
||||
$manifestPath = Util::concatPath($upgradePath, $this->manifestName);
|
||||
if (!file_exists($manifestPath)) {
|
||||
throw new Error('It\'s not an upgrade package.');
|
||||
}
|
||||
|
||||
$manifestJson = $this->getFileManager()->getContents($manifestPath);
|
||||
$this->data['manifest'] = Json::decode($manifestJson, true);
|
||||
|
||||
if (!$this->data['manifest']) {
|
||||
throw new Error('Syntax error in manifest.json.');
|
||||
}
|
||||
|
||||
if (!$this->checkManifest($this->data['manifest'])) {
|
||||
throw new Error('Unsupported package.');
|
||||
}
|
||||
}
|
||||
|
||||
return $this->data['manifest'];
|
||||
return $this->getActionManager()->getManifest();
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the manifest is correct
|
||||
*
|
||||
* @param array $manifest
|
||||
* @return boolean
|
||||
*/
|
||||
protected function checkManifest(array $manifest)
|
||||
public function upload($data)
|
||||
{
|
||||
$requiredFields = array(
|
||||
'name',
|
||||
'version',
|
||||
'acceptableVersions',
|
||||
);
|
||||
$this->getActionManager()->setAction(self::UPLOAD);
|
||||
|
||||
foreach ($requiredFields as $fieldName) {
|
||||
if (empty($manifest[$fieldName])) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
return $this->getActionManager()->run($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete temporary package files
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
protected function deletePackageFiles()
|
||||
public function install($processId)
|
||||
{
|
||||
$upgradePath = $this->getUpgradePath();
|
||||
$upgradePackagePath = $this->getUpgradePath(true);
|
||||
$this->getActionManager()->setAction(self::INSTALL);
|
||||
|
||||
$res = $this->getFileManager()->removeInDir($upgradePath, true);
|
||||
$res &= $this->getFileManager()->removeFile($upgradePackagePath);
|
||||
|
||||
return $res;
|
||||
return $this->getActionManager()->run($processId);
|
||||
}
|
||||
|
||||
protected function systemRebuild()
|
||||
public function uninstall($processId)
|
||||
{
|
||||
$manifest = $this->getManifest();
|
||||
$this->getActionManager()->setAction(self::UNINSTALL);
|
||||
|
||||
$res = $this->getConfig()->set('version', $manifest['version']);
|
||||
if (method_exists($this->getConfig(), 'save')) {
|
||||
$res = $this->getConfig()->save();
|
||||
}
|
||||
$res &= $this->getContainer()->get('dataManager')->rebuild();
|
||||
|
||||
return $res;
|
||||
return $this->getActionManager()->run($processId);
|
||||
}
|
||||
|
||||
public function delete($processId)
|
||||
{
|
||||
$this->getActionManager()->setAction(self::DELETE);
|
||||
|
||||
return $this->getActionManager()->run($processId);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -150,7 +150,7 @@ class Config
|
||||
|
||||
$removeData = empty($this->removeData) ? null : $this->removeData;
|
||||
|
||||
$result = $this->getFileManager()->mergeContentsPHP($this->configPath, $values, 1, $removeData);
|
||||
$result = $this->getFileManager()->mergeContentsPHP($this->configPath, $values, $removeData);
|
||||
if ($result) {
|
||||
$this->changedData = array();
|
||||
$this->removeData = array();
|
||||
|
||||
@@ -36,4 +36,4 @@ class JsonArray extends \Doctrine\DBAL\Types\JsonArrayType
|
||||
return 'TEXT';
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM - Open Source CRM application.
|
||||
* Copyright (C) 2014 Yuri Kuznetsov, Taras Machyshyn, Oleksiy Avramenko
|
||||
* Website: http://www.espocrm.com
|
||||
*
|
||||
* EspoCRM is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* EspoCRM is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with EspoCRM. If not, see http://www.gnu.org/licenses/.
|
||||
************************************************************************/
|
||||
|
||||
namespace Espo\Core\Utils\Database\DBAL\FieldTypes;
|
||||
|
||||
class JsonObject extends \Doctrine\DBAL\Types\ObjectType
|
||||
{
|
||||
const JSON_OBJECT = 'jsonObject';
|
||||
|
||||
public function getName()
|
||||
{
|
||||
return self::JSON_OBJECT;
|
||||
}
|
||||
|
||||
public static function getDbTypeName()
|
||||
{
|
||||
return 'TEXT';
|
||||
}
|
||||
|
||||
}
|
||||
@@ -29,79 +29,85 @@ class Comparator extends \Doctrine\DBAL\Schema\Comparator
|
||||
{
|
||||
|
||||
public function diffColumn(Column $column1, Column $column2)
|
||||
{
|
||||
$changedProperties = array();
|
||||
if ( $column1->getType() != $column2->getType() ) {
|
||||
{
|
||||
$changedProperties = array();
|
||||
if ( $column1->getType() != $column2->getType() ) {
|
||||
|
||||
//espo: fix problem with executing query for custom types
|
||||
$column1DbTypeName = method_exists($column1->getType(), 'getDbTypeName') ? $column1->getType()->getDbTypeName() : $column1->getType()->getName();
|
||||
$column2DbTypeName = method_exists($column2->getType(), 'getDbTypeName') ? $column2->getType()->getDbTypeName() : $column2->getType()->getName();
|
||||
|
||||
if (strtolower($column1DbTypeName) != strtolower($column2DbTypeName)) {
|
||||
$changedProperties[] = 'type';
|
||||
$changedProperties[] = 'type';
|
||||
}
|
||||
//END: espo
|
||||
}
|
||||
}
|
||||
|
||||
if ($column1->getNotnull() != $column2->getNotnull()) {
|
||||
$changedProperties[] = 'notnull';
|
||||
}
|
||||
if ($column1->getNotnull() != $column2->getNotnull()) {
|
||||
$changedProperties[] = 'notnull';
|
||||
}
|
||||
|
||||
if ($column1->getDefault() != $column2->getDefault()) {
|
||||
$changedProperties[] = 'default';
|
||||
}
|
||||
if ($column1->getDefault() != $column2->getDefault()) {
|
||||
$changedProperties[] = 'default';
|
||||
}
|
||||
|
||||
if ($column1->getUnsigned() != $column2->getUnsigned()) {
|
||||
$changedProperties[] = 'unsigned';
|
||||
}
|
||||
if ($column1->getUnsigned() != $column2->getUnsigned()) {
|
||||
$changedProperties[] = 'unsigned';
|
||||
}
|
||||
|
||||
if ($column1->getType() instanceof \Doctrine\DBAL\Types\StringType) {
|
||||
// check if value of length is set at all, default value assumed otherwise.
|
||||
$length1 = $column1->getLength() ?: 255;
|
||||
$length2 = $column2->getLength() ?: 255;
|
||||
if ($length1 != $length2) {
|
||||
$changedProperties[] = 'length';
|
||||
}
|
||||
if ($column1->getType() instanceof \Doctrine\DBAL\Types\StringType) {
|
||||
// check if value of length is set at all, default value assumed otherwise.
|
||||
$length1 = $column1->getLength() ?: 255;
|
||||
$length2 = $column2->getLength() ?: 255;
|
||||
|
||||
if ($column1->getFixed() != $column2->getFixed()) {
|
||||
$changedProperties[] = 'fixed';
|
||||
}
|
||||
}
|
||||
/** Espo: column length can be increased only */
|
||||
/*if ($length1 != $length2) {
|
||||
$changedProperties[] = 'length';
|
||||
}*/
|
||||
if ($length2 > $length1) {
|
||||
$changedProperties[] = 'length';
|
||||
}
|
||||
/** Espo: end */
|
||||
|
||||
if ($column1->getType() instanceof \Doctrine\DBAL\Types\DecimalType) {
|
||||
if (($column1->getPrecision()?:10) != ($column2->getPrecision()?:10)) {
|
||||
$changedProperties[] = 'precision';
|
||||
}
|
||||
if ($column1->getScale() != $column2->getScale()) {
|
||||
$changedProperties[] = 'scale';
|
||||
}
|
||||
}
|
||||
if ($column1->getFixed() != $column2->getFixed()) {
|
||||
$changedProperties[] = 'fixed';
|
||||
}
|
||||
}
|
||||
|
||||
if ($column1->getAutoincrement() != $column2->getAutoincrement()) {
|
||||
$changedProperties[] = 'autoincrement';
|
||||
}
|
||||
if ($column1->getType() instanceof \Doctrine\DBAL\Types\DecimalType) {
|
||||
if (($column1->getPrecision()?:10) != ($column2->getPrecision()?:10)) {
|
||||
$changedProperties[] = 'precision';
|
||||
}
|
||||
if ($column1->getScale() != $column2->getScale()) {
|
||||
$changedProperties[] = 'scale';
|
||||
}
|
||||
}
|
||||
|
||||
// only allow to delete comment if its set to '' not to null.
|
||||
if ($column1->getComment() !== null && $column1->getComment() != $column2->getComment()) {
|
||||
$changedProperties[] = 'comment';
|
||||
}
|
||||
if ($column1->getAutoincrement() != $column2->getAutoincrement()) {
|
||||
$changedProperties[] = 'autoincrement';
|
||||
}
|
||||
|
||||
$options1 = $column1->getCustomSchemaOptions();
|
||||
$options2 = $column2->getCustomSchemaOptions();
|
||||
// only allow to delete comment if its set to '' not to null.
|
||||
if ($column1->getComment() !== null && $column1->getComment() != $column2->getComment()) {
|
||||
$changedProperties[] = 'comment';
|
||||
}
|
||||
|
||||
$commonKeys = array_keys(array_intersect_key($options1, $options2));
|
||||
$options1 = $column1->getCustomSchemaOptions();
|
||||
$options2 = $column2->getCustomSchemaOptions();
|
||||
|
||||
foreach ($commonKeys as $key) {
|
||||
if ($options1[$key] !== $options2[$key]) {
|
||||
$changedProperties[] = $key;
|
||||
}
|
||||
}
|
||||
$commonKeys = array_keys(array_intersect_key($options1, $options2));
|
||||
|
||||
$diffKeys = array_keys(array_diff_key($options1, $options2) + array_diff_key($options2, $options1));
|
||||
foreach ($commonKeys as $key) {
|
||||
if ($options1[$key] !== $options2[$key]) {
|
||||
$changedProperties[] = $key;
|
||||
}
|
||||
}
|
||||
|
||||
$changedProperties = array_merge($changedProperties, $diffKeys);
|
||||
$diffKeys = array_keys(array_diff_key($options1, $options2) + array_diff_key($options2, $options1));
|
||||
|
||||
return $changedProperties;
|
||||
}
|
||||
$changedProperties = array_merge($changedProperties, $diffKeys);
|
||||
|
||||
return $changedProperties;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -164,8 +164,9 @@ class Converter
|
||||
{
|
||||
$entityDefs = $this->getEntityDefs();
|
||||
|
||||
$currentOrmMeta = $ormMeta;
|
||||
//load custom field definitions and customCodes
|
||||
foreach($ormMeta as $entityName => &$entityParams) {
|
||||
foreach($currentOrmMeta as $entityName => $entityParams) {
|
||||
foreach($entityParams['fields'] as $fieldName => $fieldParams) {
|
||||
|
||||
//load custom field definitions
|
||||
@@ -184,15 +185,15 @@ class Converter
|
||||
}
|
||||
|
||||
$ormMeta = Util::merge($ormMeta, $fieldResult);
|
||||
} //END: load custom field definitions
|
||||
|
||||
} //END: load custom field definitions
|
||||
|
||||
//todo move to separate file
|
||||
//add a field 'isFollowed' for scopes with 'stream => true'
|
||||
$scopeDefs = $this->getMetadata()->get('scopes.'.$entityName);
|
||||
if (isset($scopeDefs['stream']) && $scopeDefs['stream']) {
|
||||
if (!isset($entityParams['fields']['isFollowed'])) {
|
||||
$entityParams['fields']['isFollowed'] = array(
|
||||
$ormMeta[$entityName]['fields']['isFollowed'] = array(
|
||||
'type' => 'varchar',
|
||||
'notStorable' => true,
|
||||
);
|
||||
@@ -302,7 +303,7 @@ class Converter
|
||||
{
|
||||
/** set default type if exists */
|
||||
if (!isset($fieldParams['type']) || empty($fieldParams['type'])) {
|
||||
$GLOBALS['log']->warning('Field type does not exist for '.$entityName.':'.$fieldName.'. Use default type ['.$this->defaultFieldType.']');
|
||||
$GLOBALS['log']->debug('Field type does not exist for '.$entityName.':'.$fieldName.'. Use default type ['.$this->defaultFieldType.']');
|
||||
$fieldParams['type'] = $this->defaultFieldType;
|
||||
} /** END: set default type if exists */
|
||||
|
||||
@@ -353,19 +354,11 @@ class Converter
|
||||
//if empty field name, then use the main field
|
||||
if (trim($subFieldName) == '') {
|
||||
|
||||
if (!isset($fieldTypeMeta['fieldDefs'])) {
|
||||
$GLOBALS['log']->critical('Empty field defs for ['.$entityName.':'.$fieldName.'] using "actualFields". Main field ['.$fieldName.']');
|
||||
}
|
||||
|
||||
$subField['name'] = $fieldName;
|
||||
$subField['naming'] = $fieldName;
|
||||
|
||||
} else {
|
||||
|
||||
if (!isset($fieldTypeMeta['fields'][$subFieldName])) {
|
||||
$GLOBALS['log']->critical('Empty field defs for ['.$entityName.':'.$subFieldName.'] using "actualFields". Main field ['.$fieldName.']');
|
||||
}
|
||||
|
||||
$namingType = isset($fieldTypeMeta['naming']) ? $fieldTypeMeta['naming'] : $this->defaultNaming;
|
||||
|
||||
$subField['name'] = $subFieldName;
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM - Open Source CRM application.
|
||||
* Copyright (C) 2014 Yuri Kuznetsov, Taras Machyshyn, Oleksiy Avramenko
|
||||
* Website: http://www.espocrm.com
|
||||
*
|
||||
* EspoCRM is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* EspoCRM is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with EspoCRM. If not, see http://www.gnu.org/licenses/.
|
||||
************************************************************************/
|
||||
|
||||
namespace Espo\Core\Utils\Database\Orm\Fields;
|
||||
|
||||
use Espo\Core\Utils\Util;
|
||||
|
||||
class Currency extends \Espo\Core\Utils\Database\Orm\Base
|
||||
{
|
||||
protected function load($fieldName, $entityName)
|
||||
{
|
||||
$converedFieldName = $fieldName . 'Converted';
|
||||
|
||||
$currencyColumnName = Util::toUnderScore($fieldName);
|
||||
|
||||
$alias = Util::toUnderScore($fieldName) . "_currency_alias";
|
||||
|
||||
return array(
|
||||
$entityName => array(
|
||||
'fields' => array(
|
||||
$fieldName => array(
|
||||
"type" => "float",
|
||||
"orderBy" => $converedFieldName . " {direction}"
|
||||
),
|
||||
$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}"
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -33,6 +33,8 @@ class FieldManager
|
||||
|
||||
private $metadataUtils;
|
||||
|
||||
protected $isChanged = null;
|
||||
|
||||
protected $metadataType = 'entityDefs';
|
||||
|
||||
protected $customOptionName = 'isCustom';
|
||||
@@ -61,7 +63,6 @@ class FieldManager
|
||||
return $this->metadataUtils;
|
||||
}
|
||||
|
||||
|
||||
public function read($name, $scope)
|
||||
{
|
||||
$fieldDef = $this->getFieldDef($name, $scope);
|
||||
@@ -91,10 +92,11 @@ class FieldManager
|
||||
$res = true;
|
||||
if (isset($fieldDef['label'])) {
|
||||
$res &= $this->setLabel($name, $fieldDef['label'], $scope);
|
||||
unset($fieldDef['label']);
|
||||
}
|
||||
|
||||
$res &= $this->setEntityDefs($name, $fieldDef, $scope);
|
||||
if ($this->isDefsChanged($name, $fieldDef, $scope)) {
|
||||
$res &= $this->setEntityDefs($name, $fieldDef, $scope);
|
||||
}
|
||||
|
||||
return (bool) $res;
|
||||
}
|
||||
@@ -109,6 +111,7 @@ class FieldManager
|
||||
'fields.'.$name,
|
||||
'links.'.$name,
|
||||
);
|
||||
|
||||
$res = $this->getMetadata()->delete($unsets, $this->metadataType, $scope);
|
||||
|
||||
$this->deleteLabel($name, $scope);
|
||||
@@ -146,6 +149,42 @@ class FieldManager
|
||||
return $this->getMetadata()->get($this->metadataType.'.'.$scope.'.links.'.$name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare input fieldDefs, remove unnecessary fields
|
||||
*
|
||||
* @param string $fieldName
|
||||
* @param array $fieldDef
|
||||
* @param string $scope
|
||||
* @return array
|
||||
*/
|
||||
protected function prepareFieldDef($name, $fieldDef, $scope)
|
||||
{
|
||||
$unnecessaryFields = array(
|
||||
'name',
|
||||
'label',
|
||||
);
|
||||
|
||||
foreach ($unnecessaryFields as $fieldName) {
|
||||
if (isset($fieldDef[$fieldName])) {
|
||||
unset($fieldDef[$fieldName]);
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($fieldDef['linkDefs'])) {
|
||||
$linkDefs = $fieldDef['linkDefs'];
|
||||
unset($fieldDef['linkDefs']);
|
||||
}
|
||||
|
||||
$currentOptionList = array_keys((array) $this->getFieldDef($name, $scope));
|
||||
foreach ($fieldDef as $defName => $defValue) {
|
||||
if ( (!isset($defValue) || $defValue === '') && !in_array($defName, $currentOptionList) ) {
|
||||
unset($fieldDef[$defName]);
|
||||
}
|
||||
}
|
||||
|
||||
return $fieldDef;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add all needed block for a field defenition
|
||||
*
|
||||
@@ -156,20 +195,7 @@ class FieldManager
|
||||
*/
|
||||
protected function normalizeDefs($fieldName, array $fieldDef, $scope)
|
||||
{
|
||||
if (isset($fieldDef['name'])) {
|
||||
unset($fieldDef['name']);
|
||||
}
|
||||
|
||||
if (isset($fieldDef['linkDefs'])) {
|
||||
$linkDefs = $fieldDef['linkDefs'];
|
||||
unset($fieldDef['linkDefs']);
|
||||
}
|
||||
|
||||
foreach ($fieldDef as $defName => $defValue) {
|
||||
if (!isset($defValue) || (is_string($defValue) && $defValue == '') ) {
|
||||
unset($fieldDef[$defName]);
|
||||
}
|
||||
}
|
||||
$fieldDef = $this->prepareFieldDef($fieldName, $fieldDef, $scope);
|
||||
|
||||
$metaFieldDef = $this->getMetadataUtils()->getFieldDefsInFieldMeta($fieldDef);
|
||||
if (isset($metaFieldDef)) {
|
||||
@@ -194,6 +220,38 @@ class FieldManager
|
||||
return $defs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if changed metadata defenition for a field except 'label'
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
protected function isDefsChanged($name, $fieldDef, $scope)
|
||||
{
|
||||
$fieldDef = $this->prepareFieldDef($name, $fieldDef, $scope);
|
||||
$currentFieldDef = $this->getFieldDef($name, $scope);
|
||||
|
||||
$this->isChanged = Util::isEquals($fieldDef, $currentFieldDef) ? false : true;
|
||||
|
||||
return $this->isChanged;
|
||||
}
|
||||
|
||||
/**
|
||||
* Only for update method
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function isChanged()
|
||||
{
|
||||
return $this->isChanged;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a field is core field
|
||||
*
|
||||
* @param string $name
|
||||
* @param string $scope
|
||||
* @return boolean
|
||||
*/
|
||||
protected function isCore($name, $scope)
|
||||
{
|
||||
$existingField = $this->getFieldDef($name, $scope);
|
||||
|
||||
@@ -225,13 +225,12 @@ class Manager
|
||||
* @param string | array $path
|
||||
* @param string $content JSON string
|
||||
* @param bool $isJSON
|
||||
* @param string | array $mergeOptions
|
||||
* @param string | array $removeOptions - List of unset keys from content
|
||||
* @param bool $isReturn - Is result to be returned or stored
|
||||
*
|
||||
* @return bool | array
|
||||
*/
|
||||
public function mergeContents($path, $content, $isJSON = false, $mergeOptions = null, $removeOptions = null, $isReturn = false)
|
||||
public function mergeContents($path, $content, $isJSON = false, $removeOptions = null, $isReturn = false)
|
||||
{
|
||||
$fileContent = $this->getContents($path);
|
||||
|
||||
@@ -243,7 +242,7 @@ class Manager
|
||||
$newDataArray = Utils\Util::unsetInArray($newDataArray, $removeOptions);
|
||||
}
|
||||
|
||||
$data = Utils\Util::merge($savedDataArray, $newDataArray, $mergeOptions);
|
||||
$data = Utils\Util::merge($savedDataArray, $newDataArray);
|
||||
if ($isJSON) {
|
||||
$data = Utils\Json::encode($data, JSON_PRETTY_PRINT);
|
||||
}
|
||||
@@ -260,13 +259,12 @@ class Manager
|
||||
*
|
||||
* @param string | array $path
|
||||
* @param string $content JSON string
|
||||
* @param string | array $mergeOptions
|
||||
* @param string | array $removeOptions - List of unset keys from content
|
||||
* @return bool
|
||||
*/
|
||||
public function mergeContentsPHP($path, $content, $mergeOptions = null, $removeOptions = null)
|
||||
public function mergeContentsPHP($path, $content, $removeOptions = null)
|
||||
{
|
||||
$data = $this->mergeContents($path, $content, false, $mergeOptions, $removeOptions, true);
|
||||
$data = $this->mergeContents($path, $content, false, $removeOptions, true);
|
||||
|
||||
return $this->putContentsPHP($path, $data);
|
||||
}
|
||||
@@ -362,40 +360,71 @@ class Manager
|
||||
|
||||
/**
|
||||
* Copy files from one direcoty to another
|
||||
* Ex. $sourcePath = 'data/uploads/extensions/file.json', $destPath = 'data/uploads/backup', result will be data/uploads/backup/data/uploads/backup/file.json.
|
||||
*
|
||||
* @param string $sourcePath
|
||||
* @param string $destPath
|
||||
* @param boolean $recursively
|
||||
* @param array $fileList - list of files that should be copied
|
||||
* @param boolean $copyOnlyFiles - copy only files, instead of full path with directories, Ex. $sourcePath = 'data/uploads/extensions/file.json', $destPath = 'data/uploads/backup', result will be 'data/uploads/backup/file.json'
|
||||
* @return boolen
|
||||
*/
|
||||
public function copy($sourcePath, $destPath, $recursively = false)
|
||||
public function copy($sourcePath, $destPath, $recursively = false, array $fileList = null, $copyOnlyFiles = false)
|
||||
{
|
||||
$sourcePath = $this->concatPaths($sourcePath);
|
||||
$destPath = $this->concatPaths($destPath);
|
||||
|
||||
if (is_file($sourcePath)) {
|
||||
$fileList = (array) $sourcePath;
|
||||
if (isset($fileList)) {
|
||||
if (!empty($sourcePath)) {
|
||||
foreach ($fileList as &$fileName) {
|
||||
$fileName = $this->concatPaths(array($sourcePath, $fileName));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$fileList = $this->getFileList($sourcePath, $recursively, '', 'all', true);
|
||||
$fileList = is_file($sourcePath) ? (array) $sourcePath : $this->getFileList($sourcePath, $recursively, '', 'file', true);
|
||||
}
|
||||
|
||||
/** Check permission before copying */
|
||||
$permissionDeniedList = array();
|
||||
foreach ($fileList as $file) {
|
||||
|
||||
if ($copyOnlyFiles) {
|
||||
$file = pathinfo($file, PATHINFO_BASENAME);
|
||||
}
|
||||
|
||||
$destFile = $this->concatPaths(array($destPath, $file));
|
||||
|
||||
$isFileExists = file_exists($destFile);
|
||||
|
||||
if ($this->checkCreateFile($destFile) === false) {
|
||||
$permissionDeniedList[] = $destFile;
|
||||
} else if (!$isFileExists) {
|
||||
$this->removeFile($destFile);
|
||||
}
|
||||
}
|
||||
/** END */
|
||||
|
||||
if (!empty($permissionDeniedList)) {
|
||||
$betterPermissionList = $this->getPermissionUtils()->arrangePermissionList($permissionDeniedList);
|
||||
throw new Error("Permission denied in <br>". implode(", <br>", $betterPermissionList));
|
||||
}
|
||||
|
||||
$res = true;
|
||||
foreach ($fileList as $file) {
|
||||
|
||||
$sourceFile = $this->concatPaths(array($sourcePath, $file));
|
||||
$destFile = $this->concatPaths(array($destPath, $file));
|
||||
|
||||
if ($this->checkCreateFile($destFile) === false) {
|
||||
throw new Error('Permission denied in '. $destFile);
|
||||
if ($copyOnlyFiles) {
|
||||
$file = pathinfo($file, PATHINFO_BASENAME);
|
||||
}
|
||||
|
||||
$sourceFile = is_file($sourcePath) ? $sourcePath : $this->concatPaths(array($sourcePath, $file));
|
||||
$destFile = $this->concatPaths(array($destPath, $file));
|
||||
|
||||
$res &= copy($sourceFile, $destFile);
|
||||
}
|
||||
|
||||
return $res;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create a new file if not exists with all folders in the path.
|
||||
*
|
||||
@@ -471,17 +500,21 @@ class Manager
|
||||
$fileList = $this->getFileList($dirPath, false);
|
||||
|
||||
$result = true;
|
||||
foreach ($fileList as $file) {
|
||||
$fullPath = Utils\Util::concatPath($dirPath, $file);
|
||||
if (is_dir($fullPath)) {
|
||||
$result &= $this->removeInDir($fullPath, true);
|
||||
} else {
|
||||
$result &= unlink($fullPath);
|
||||
if (is_array($fileList)) {
|
||||
foreach ($fileList as $file) {
|
||||
$fullPath = Utils\Util::concatPath($dirPath, $file);
|
||||
if (is_dir($fullPath)) {
|
||||
$result &= $this->removeInDir($fullPath, true);
|
||||
} else if (file_exists($fullPath)) {
|
||||
$result &= unlink($fullPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($removeWithDir) {
|
||||
rmdir($dirPath);
|
||||
if (file_exists($dirPath)) {
|
||||
rmdir($dirPath);
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
@@ -566,7 +599,6 @@ class Manager
|
||||
return $pathInfo['dirname'];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return content of PHP file
|
||||
*
|
||||
|
||||
@@ -420,7 +420,7 @@ class Permission
|
||||
|
||||
$owner = $defaultPermissions['user'];
|
||||
if (empty($owner) && $usePosix) {
|
||||
$owner = posix_getuid();
|
||||
$owner = function_exists('posix_getuid') ? posix_getuid() : null;
|
||||
}
|
||||
|
||||
if (empty($owner)) {
|
||||
@@ -441,7 +441,7 @@ class Permission
|
||||
|
||||
$group = $defaultPermissions['group'];
|
||||
if (empty($group) && $usePosix) {
|
||||
$group = posix_getegid();
|
||||
$group = function_exists('posix_getegid') ? posix_getegid() : null;
|
||||
}
|
||||
|
||||
if (empty($group)) {
|
||||
@@ -535,6 +535,71 @@ class Permission
|
||||
return $this->permissionErrorRules;
|
||||
}
|
||||
|
||||
/**
|
||||
* Arrange permission file list
|
||||
* e.g. array('application/Espo/Controllers/Email.php', 'application/Espo/Controllers/Import.php'), result is array('application/Espo/Controllers')
|
||||
*
|
||||
* @param array $fileList
|
||||
* @return array
|
||||
*/
|
||||
public function arrangePermissionList($fileList)
|
||||
{
|
||||
$betterList = array();
|
||||
foreach ($fileList as $fileName) {
|
||||
|
||||
$pathInfo = pathinfo($fileName);
|
||||
$dirname = $pathInfo['dirname'];
|
||||
|
||||
$currentPath = $fileName;
|
||||
if ($this->getSearchCount($dirname, $fileList) > 1) {
|
||||
$currentPath = $dirname;
|
||||
}
|
||||
|
||||
if (!$this->isItemIncludes($currentPath, $betterList)) {
|
||||
$betterList[] = $currentPath;
|
||||
}
|
||||
}
|
||||
|
||||
return $betterList;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get count of a search string in a array
|
||||
*
|
||||
* @param string $search
|
||||
* @param array $array
|
||||
* @return bool
|
||||
*/
|
||||
protected function getSearchCount($search, array $array)
|
||||
{
|
||||
$search = $this->getPregQuote($search);
|
||||
|
||||
$number = 0;
|
||||
foreach ($array as $value) {
|
||||
if (preg_match('/^'.$search.'/', $value)) {
|
||||
$number++;
|
||||
}
|
||||
}
|
||||
|
||||
return $number;
|
||||
}
|
||||
|
||||
protected function isItemIncludes($item, $array)
|
||||
{
|
||||
foreach ($array as $value) {
|
||||
$value = $this->getPregQuote($value);
|
||||
if (preg_match('/^'.$value.'/', $item)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
protected function getPregQuote($string)
|
||||
{
|
||||
return preg_quote($string, '/-+=.');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -38,24 +38,21 @@ class Unifier
|
||||
$this->fileManager = $fileManager;
|
||||
}
|
||||
|
||||
|
||||
protected function getFileManager()
|
||||
{
|
||||
return $this->fileManager;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Unite file content to the file
|
||||
*
|
||||
* @param [type] $name [description]
|
||||
* @param [type] $paths [description]
|
||||
* @param string $name
|
||||
* @param array $paths
|
||||
* @param boolean $recursively Note: only for first level of sub directory, other levels of sub directories will be ignored
|
||||
* @param [type] $mergeLevel - merge level, see Espo\Core\Utils\Util::merge()
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function unify($name, $paths, $recursively = false, $mergeLevel = null, $mergeKeyName = null)
|
||||
public function unify($name, $paths, $recursively = false)
|
||||
{
|
||||
$content = $this->unifySingle($paths['corePath'], $name, $recursively);
|
||||
|
||||
@@ -65,19 +62,17 @@ class Unifier
|
||||
|
||||
foreach ($dirList as $dirName) {
|
||||
$curPath = str_replace('{*}', $dirName, $paths['modulePath']);
|
||||
$content = Utils\Util::merge($content, $this->unifySingle($curPath, $name, $recursively, $dirName), $mergeLevel, $mergeKeyName);
|
||||
$content = Utils\Util::merge($content, $this->unifySingle($curPath, $name, $recursively, $dirName));
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($paths['customPath'])) {
|
||||
$content = Utils\Util::merge($content, $this->unifySingle($paths['customPath'], $name, $recursively), $mergeLevel, $mergeKeyName);
|
||||
$content = Utils\Util::merge($content, $this->unifySingle($paths['customPath'], $name, $recursively));
|
||||
}
|
||||
|
||||
return $content;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Unite file content to the file for one directory [NOW ONLY FOR METADATA, NEED TO CHECK FOR LAYOUTS AND OTHERS]
|
||||
*
|
||||
@@ -161,7 +156,7 @@ class Unifier
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function loadDefaultValues($name, $type='metadata')
|
||||
protected function loadDefaultValues($name, $type = 'metadata')
|
||||
{
|
||||
$defaultPath = $this->params['defaultsPath'];
|
||||
|
||||
|
||||
@@ -241,7 +241,7 @@ class Language
|
||||
$i18nCacheFile = str_replace('{*}', $i18nName, $this->cacheFile);
|
||||
|
||||
if ($i18nName != $this->defaultLanguage) {
|
||||
$i18nData = Util::merge($this->fullData[$this->defaultLanguage], $i18nData, null, null, true);
|
||||
$i18nData = Util::merge($this->fullData[$this->defaultLanguage], $i18nData);
|
||||
}
|
||||
$result &= $this->getFileManager()->putContentsPHP($i18nCacheFile, $i18nData);
|
||||
}
|
||||
|
||||
@@ -186,7 +186,7 @@ class Metadata
|
||||
{
|
||||
$data = false;
|
||||
if (!file_exists($this->cacheFile) || $reload) {
|
||||
$data = $this->getUnifier()->unify($this->name, $this->paths, true, 5, 'options');
|
||||
$data = $this->getUnifier()->unify($this->name, $this->paths, true);
|
||||
|
||||
if ($data === false) {
|
||||
$GLOBALS['log']->emergency('Metadata:getMetadata() - metadata unite file cannot be created');
|
||||
@@ -246,7 +246,7 @@ class Metadata
|
||||
{
|
||||
$path = $this->paths['customPath'];
|
||||
|
||||
$result = $this->getFileManager()->mergeContents(array($path, $type, $scope.'.json'), $data, true, array(3, 'options'));
|
||||
$result = $this->getFileManager()->mergeContents(array($path, $type, $scope.'.json'), $data, true);
|
||||
if ($result === false) {
|
||||
throw new Error("Error saving metadata. See log file for details.");
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ class System
|
||||
{
|
||||
$serverSoft = $_SERVER['SERVER_SOFTWARE'];
|
||||
|
||||
preg_match('/^(.*)\//i', $serverSoft, $match);
|
||||
preg_match('/^(.*?)\//i', $serverSoft, $match);
|
||||
if (empty($match[1])) {
|
||||
preg_match('/^(.*)\/?/i', $serverSoft, $match);
|
||||
}
|
||||
|
||||
@@ -109,107 +109,51 @@ class Util
|
||||
}
|
||||
|
||||
/**
|
||||
* Merge arrays (default PHP function is not suitable)
|
||||
* Merge arrays recursively (default PHP function is not suitable)
|
||||
*
|
||||
* @param array $array
|
||||
* @param array $mainArray - chief array (priority is same as for array_merge())
|
||||
* @param array $rewriteLevel - Merge by rewrite level, level numering starts from 1. Ex.
|
||||
* array(
|
||||
* 'level1' => array(
|
||||
* 'level2' => array(
|
||||
* 'level3' => array(
|
||||
* 'key1' => 'value',
|
||||
* 'key2' => 'value',
|
||||
* ),
|
||||
* ),
|
||||
* ),
|
||||
* )
|
||||
* @param $rewriteKeyName string - Rewrite key name. It is ignored if $rewriteLevel is NULL.
|
||||
* @param $rewriteArrays bool - Rewrite single arrays. Examples:
|
||||
* TRUE: array is [0, 1, 2], main array is [3, 4, 5], Result is [3, 4, 5].
|
||||
* FALSE: array is [0, 1, 2], main array is [3, 4, 5], Result is [0, 1, 2, 3, 4, 5].
|
||||
* @param array $currentArray
|
||||
* @param array $newArray - chief array (priority is same as for array_merge())
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function merge($array, $mainArray, $rewriteLevel = null, $rewriteKeyName = null, $rewriteArrays = false)
|
||||
public static function merge($currentArray, $newArray)
|
||||
{
|
||||
if (is_array($array) && !is_array($mainArray)) {
|
||||
return $array;
|
||||
} else if (!is_array($array) && is_array($mainArray)) {
|
||||
return $mainArray;
|
||||
} else if (!is_array($array) && !is_array($mainArray)) {
|
||||
$mergeIdentifier = '__APPEND__';
|
||||
|
||||
if (is_array($currentArray) && (!is_array($newArray) || empty($newArray))) {
|
||||
return $currentArray;
|
||||
} else if ((!is_array($currentArray) || empty($currentArray)) && is_array($newArray)) {
|
||||
return $newArray;
|
||||
} else if ((!is_array($currentArray) || empty($currentArray)) && (!is_array($newArray) || empty($newArray))) {
|
||||
return array();
|
||||
}
|
||||
|
||||
if (is_array($rewriteLevel)) {
|
||||
if (isset($rewriteLevel[1])) {
|
||||
$rewriteKeyName = $rewriteLevel[1];
|
||||
}
|
||||
if (isset($rewriteLevel[0])) {
|
||||
$rewriteLevel = $rewriteLevel[0];
|
||||
}
|
||||
}
|
||||
/** add root items from currentArray */
|
||||
foreach ($currentArray as $currentName => $currentValue) {
|
||||
|
||||
foreach($mainArray as $mainKey => $mainValue) {
|
||||
if (!array_key_exists($currentName, $newArray)) {
|
||||
|
||||
$found = false;
|
||||
foreach($array as $key => $value) {
|
||||
$newArray[$currentName] = $currentValue;
|
||||
|
||||
if ((string)$mainKey == (string)$key) {
|
||||
} else if (is_array($currentValue) && is_array($newArray[$currentName])) {
|
||||
|
||||
$found = true;
|
||||
if (is_array($mainValue) || is_array($value)) {
|
||||
|
||||
$rowRewriteLevel = $rewriteLevel;
|
||||
|
||||
/** check the $rewriteKeyName */
|
||||
if (isset($rowRewriteLevel) && $rowRewriteLevel == 1 && isset($rewriteKeyName)) {
|
||||
$rewriteKeyName = is_array($rewriteKeyName) ? $rewriteKeyName : (array) $rewriteKeyName;
|
||||
|
||||
if (!in_array((string)$key, $rewriteKeyName)) {
|
||||
$rowRewriteLevel = null;
|
||||
}
|
||||
} /** END: check the $rewriteKeyName */
|
||||
|
||||
if (!isset($rowRewriteLevel) || $rowRewriteLevel != 1) {
|
||||
$array[$mainKey] = static::merge((array) $value, (array) $mainValue, --$rowRewriteLevel, $rewriteKeyName, $rewriteArrays);
|
||||
continue;
|
||||
}
|
||||
|
||||
$mergeValue = array('mergeLevel' => (array) $value);
|
||||
$mergeMainValue = array('mergeLevel' => (array) $mainValue);
|
||||
$mergeRes = array_merge($mergeValue, $mergeMainValue);
|
||||
$array[$mainKey] = $mergeRes['mergeLevel'];
|
||||
continue;
|
||||
}
|
||||
|
||||
/** merge logic */
|
||||
if (!is_numeric($mainKey)) {
|
||||
$array[$mainKey] = $mainValue;
|
||||
}
|
||||
elseif (!in_array($mainValue, $array)) {
|
||||
if ($rewriteArrays) {
|
||||
$array[$mainKey] = $mainValue;
|
||||
} else {
|
||||
$array[] = $mainValue;
|
||||
}
|
||||
} /** END: merge logic */
|
||||
|
||||
break;
|
||||
/** check __APPEND__ identifier */
|
||||
$appendKey = array_search($mergeIdentifier, $newArray[$currentName], true);
|
||||
if ($appendKey !== false) {
|
||||
unset($newArray[$currentName][$appendKey]);
|
||||
$newArray[$currentName] = array_merge($currentValue, $newArray[$currentName]);
|
||||
} else if (!static::isSingleArray($newArray[$currentName])) {
|
||||
$newArray[$currentName] = static::merge($currentValue, $newArray[$currentName]);
|
||||
}
|
||||
}
|
||||
/** add an item if key not found */
|
||||
if (!$found) {
|
||||
$array[$mainKey] = $mainValue;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return $array;
|
||||
return $newArray;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a full path of the file
|
||||
* Get a full path of the file
|
||||
*
|
||||
* @param string | array $folderPath - Folder path, Ex. myfolder
|
||||
* @param string $filePath - File path, Ex. file.json
|
||||
@@ -239,7 +183,6 @@ class Util
|
||||
return $folderPath . static::getSeparator() . $filePath;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Convert array to object format recursively
|
||||
*
|
||||
@@ -255,7 +198,6 @@ class Util
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Convert object to array format recursively
|
||||
*
|
||||
@@ -285,7 +227,6 @@ class Util
|
||||
return $name;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get Naming according to prefix or postfix type
|
||||
*
|
||||
@@ -306,7 +247,6 @@ class Util
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Replace $search in array recursively
|
||||
*
|
||||
@@ -343,19 +283,23 @@ class Util
|
||||
* @param array $content
|
||||
* @param string | array $unsets in format
|
||||
* array(
|
||||
* 'EntityName1' => array( 'unset1', 'unset2' ),
|
||||
* 'EntityName2' => array( 'unset1', 'unset2' ),
|
||||
* 'EntityName1' => array( 'unset1', 'unset2' ),
|
||||
* 'EntityName2' => array( 'unset1', 'unset2' ),
|
||||
* )
|
||||
* OR
|
||||
* array('EntityName1.unset1', 'EntityName1.unset2', .....)
|
||||
* OR
|
||||
* 'EntityName1.unset1'
|
||||
* OR
|
||||
* array('EntityName1.unset1', 'EntityName1.unset2', .....)
|
||||
* OR
|
||||
* 'EntityName1.unset1'
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function unsetInArray(array $content, $unsets)
|
||||
{
|
||||
if (is_string($unsets)) {
|
||||
if (empty($unsets)) {
|
||||
return $content;
|
||||
}
|
||||
|
||||
if (is_string($unsets)) {
|
||||
$unsets = (array) $unsets;
|
||||
}
|
||||
|
||||
@@ -373,10 +317,11 @@ class Util
|
||||
}
|
||||
|
||||
$unsetElem = $currVal . "['{$lastKey}']";
|
||||
|
||||
$currVal = "
|
||||
if (isset({$unsetElem}) || array_key_exists({$lastKey}, {$currVal})) {
|
||||
unset({$unsetElem});
|
||||
} ";
|
||||
if (isset({$unsetElem}) || ( is_array({$currVal}) && array_key_exists({$lastKey}, {$currVal}) )) {
|
||||
unset({$unsetElem});
|
||||
} ";
|
||||
eval($currVal);
|
||||
}
|
||||
}
|
||||
@@ -385,7 +330,6 @@ class Util
|
||||
return $content;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get class name from the file path
|
||||
*
|
||||
@@ -402,7 +346,6 @@ class Util
|
||||
return $className;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return values of defined $key.
|
||||
*
|
||||
@@ -431,6 +374,55 @@ class Util
|
||||
return $lastItem;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if two variables are equals
|
||||
*
|
||||
* @param mixed $var1
|
||||
* @param mixed $var2
|
||||
* @return boolean
|
||||
*/
|
||||
public static function isEquals($var1, $var2)
|
||||
{
|
||||
if (is_array($var1)) {
|
||||
static::ksortRecursive($var1);
|
||||
}
|
||||
if (is_array($var2)) {
|
||||
static::ksortRecursive($var2);
|
||||
}
|
||||
|
||||
return ($var1 === $var2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sort array recursively
|
||||
* @param array $array
|
||||
* @return bool
|
||||
*/
|
||||
public static function ksortRecursive(&$array)
|
||||
{
|
||||
if (!is_array($array)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
ksort($array);
|
||||
foreach ($array as $key => $value) {
|
||||
static::ksortRecursive($array[$key]);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public static function isSingleArray(array $array)
|
||||
{
|
||||
foreach ($array as $key => $value) {
|
||||
if (!is_int($key)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -41,7 +41,7 @@ return array (
|
||||
'weekStart' => 0,
|
||||
'thousandSeparator' => ',',
|
||||
'decimalMark' => '.',
|
||||
'exportDelimiter' => ',',
|
||||
'exportDelimiter' => ';',
|
||||
'currencyList' =>
|
||||
array (
|
||||
),
|
||||
@@ -66,6 +66,7 @@ return array (
|
||||
'nl_NL',
|
||||
'tr_TR',
|
||||
'ro_RO',
|
||||
'ru_RU',
|
||||
'pl_PL',
|
||||
'pt_BR',
|
||||
'vi_VN'
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM - Open Source CRM application.
|
||||
* Copyright (C) 2014 Yuri Kuznetsov, Taras Machyshyn, Oleksiy Avramenko
|
||||
* Website: http://www.espocrm.com
|
||||
*
|
||||
* EspoCRM is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* EspoCRM is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with EspoCRM. If not, see http://www.gnu.org/licenses/.
|
||||
************************************************************************/
|
||||
|
||||
namespace Espo\Entities;
|
||||
|
||||
class Extension extends \Espo\Core\ORM\Entity
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@@ -36,17 +36,29 @@ class Integration extends \Espo\Core\ORM\Entity
|
||||
}
|
||||
} else {
|
||||
if ($this->get('data')) {
|
||||
$data = json_decode($this->get('data'), true);
|
||||
$data = $this->get('data');
|
||||
} else {
|
||||
$data = array();
|
||||
$data = new \stdClass();
|
||||
}
|
||||
if (isset($data[$name])) {
|
||||
return $data[$name];
|
||||
if (isset($data->$name)) {
|
||||
return $data->$name;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public function clear($name)
|
||||
{
|
||||
parent::clear($name);
|
||||
|
||||
$data = $this->get('data');
|
||||
if (empty($data)) {
|
||||
$data = new \stdClass();
|
||||
}
|
||||
unset($data->$name);
|
||||
$this->set('data', $data);
|
||||
}
|
||||
|
||||
public function set($p1, $p2)
|
||||
{
|
||||
if (is_array($p1)) {
|
||||
@@ -68,12 +80,15 @@ class Integration extends \Espo\Core\ORM\Entity
|
||||
if ($this->hasField($name)) {
|
||||
$this->valuesContainer[$name] = $value;
|
||||
} else {
|
||||
$data = json_decode($this->get('data'), true);
|
||||
if (empty($data)) {
|
||||
$data = array();
|
||||
if (!$this->get('enabled')) {
|
||||
return;
|
||||
}
|
||||
$data[$name] = $value;
|
||||
$this->set('data', json_encode($data));
|
||||
$data = $this->get('data');
|
||||
if (empty($data)) {
|
||||
$data = new \stdClass();
|
||||
}
|
||||
$data->$name = $value;
|
||||
$this->set('data', $data);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -85,7 +100,7 @@ class Integration extends \Espo\Core\ORM\Entity
|
||||
|
||||
foreach ($arr as $field => $value) {
|
||||
if (is_string($field)) {
|
||||
if (is_array($value)) {
|
||||
if (is_array($value) || ($value instanceof \stdClass)) {
|
||||
$value = json_encode($value);
|
||||
}
|
||||
|
||||
@@ -112,6 +127,12 @@ class Integration extends \Espo\Core\ORM\Entity
|
||||
$value = null;
|
||||
}
|
||||
break;
|
||||
case self::JSON_OBJECT:
|
||||
$value = is_string($value) ? json_decode($value) : $value;
|
||||
if (!($value instanceof \stdClass) && !is_array($value)) {
|
||||
$value = null;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@@ -139,12 +160,14 @@ class Integration extends \Espo\Core\ORM\Entity
|
||||
}
|
||||
}
|
||||
|
||||
$data = json_decode($this->get('data'), true);
|
||||
$data = $this->get('data');
|
||||
if (empty($data)) {
|
||||
$data = array();
|
||||
$data = new \stdClass();
|
||||
}
|
||||
|
||||
$dataArr = get_object_vars($data);
|
||||
|
||||
$arr = array_merge($arr, $data);
|
||||
$arr = array_merge($arr, $dataArr);
|
||||
return $arr;
|
||||
}
|
||||
|
||||
|
||||
@@ -72,7 +72,7 @@ class Image extends \Espo\Core\EntryPoints\Base
|
||||
|
||||
if ($attachment->get('parentId') && $attachment->get('parentType')) {
|
||||
$parent = $this->getEntityManager()->getEntity($attachment->get('parentType'), $attachment->get('parentId'));
|
||||
if (!$this->getAcl()->check($parent)) {
|
||||
if ($parent && !$this->getAcl()->check($parent)) {
|
||||
throw new Forbidden();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,109 @@
|
||||
<?php
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM - Open Source CRM application.
|
||||
* Copyright (C) 2014 Yuri Kuznetsov, Taras Machyshyn, Oleksiy Avramenko
|
||||
* Website: http://www.espocrm.com
|
||||
*
|
||||
* EspoCRM is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* EspoCRM is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with EspoCRM. If not, see http://www.gnu.org/licenses/.
|
||||
************************************************************************/
|
||||
|
||||
namespace Espo\Hooks\Note;
|
||||
|
||||
use Espo\ORM\Entity;
|
||||
|
||||
class Mentions extends \Espo\Core\Hooks\Base
|
||||
{
|
||||
public static $order = 9;
|
||||
|
||||
protected $notificationService = null;
|
||||
|
||||
protected function init()
|
||||
{
|
||||
$this->dependencies[] = 'serviceFactory';
|
||||
}
|
||||
|
||||
protected function getServiceFactory()
|
||||
{
|
||||
return $this->getInjection('serviceFactory');
|
||||
}
|
||||
|
||||
protected function addMentionData($entity)
|
||||
{
|
||||
$post = $entity->get('post');
|
||||
|
||||
$mentionData = new \stdClass();
|
||||
|
||||
$previousMentionList = array();
|
||||
if ($entity->isFetched()) {
|
||||
$data = $entity->get('data');
|
||||
if (!empty($data) && !empty($data->mentions)) {
|
||||
$previousMentionList = array_keys(get_object_vars($data->mentions));
|
||||
}
|
||||
}
|
||||
|
||||
preg_match_all('/(@\w+)/', $post, $matches);
|
||||
|
||||
if (is_array($matches) && !empty($matches[0]) && is_array($matches[0])) {
|
||||
foreach ($matches[0] as $item) {
|
||||
$userName = substr($item, 1);
|
||||
$user = $this->getEntityManager()->getRepository('User')->where(array('userName' => $userName))->findOne();
|
||||
if ($user) {
|
||||
$m = array(
|
||||
'id' => $user->id,
|
||||
'name' => $user->get('name'),
|
||||
'userName' => $user->get('userName'),
|
||||
'_scope' => $user->getEntityName()
|
||||
);
|
||||
$mentionData->$item = (object) $m;
|
||||
if (!in_array($item, $previousMentionList)) {
|
||||
$this->notifyAboutMention($entity, $user);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$data = $entity->get('data');
|
||||
if (empty($data)) {
|
||||
$data = new \stdClass();
|
||||
}
|
||||
$data->mentions = $mentionData;
|
||||
|
||||
$entity->set('data', $data);
|
||||
}
|
||||
|
||||
public function beforeSave(Entity $entity)
|
||||
{
|
||||
if ($entity->get('type') == 'Post') {
|
||||
$post = $entity->get('post');
|
||||
|
||||
$this->addMentionData($entity);
|
||||
}
|
||||
}
|
||||
|
||||
protected function notifyAboutMention(Entity $entity, \Espo\Entities\User $user)
|
||||
{
|
||||
$this->getNotificationService()->notifyAboutMentionInPost($user->id, $entity->id);
|
||||
}
|
||||
|
||||
protected function getNotificationService()
|
||||
{
|
||||
if (empty($this->notificationService)) {
|
||||
$this->notificationService = $this->getServiceFactory()->create('Notification');
|
||||
}
|
||||
return $this->notificationService;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,6 +28,8 @@ class Notifications extends \Espo\Core\Hooks\Base
|
||||
{
|
||||
protected $notificationService = null;
|
||||
|
||||
public static $order = 14;
|
||||
|
||||
protected function init()
|
||||
{
|
||||
$this->dependencies[] = 'serviceFactory';
|
||||
@@ -38,6 +40,19 @@ class Notifications extends \Espo\Core\Hooks\Base
|
||||
return $this->getInjection('serviceFactory');
|
||||
}
|
||||
|
||||
protected function getMentionedUserList($entity)
|
||||
{
|
||||
$mentionedUserList = array();
|
||||
$data = $entity->get('data');
|
||||
if (($data instanceof \stdClass) && ($data->mentions instanceof \stdClass)) {
|
||||
$mentions = get_object_vars($data->mentions);
|
||||
foreach ($mentions as $d) {
|
||||
$mentionedUserList[] = $d->id;
|
||||
}
|
||||
}
|
||||
return $mentionedUserList;
|
||||
}
|
||||
|
||||
public function afterSave(Entity $entity)
|
||||
{
|
||||
if (!$entity->isFetched()) {
|
||||
@@ -46,6 +61,9 @@ class Notifications extends \Espo\Core\Hooks\Base
|
||||
$parentId = $entity->get('parentId');
|
||||
|
||||
if ($parentType && $parentId) {
|
||||
|
||||
$mentionedUserList = $this->getMentionedUserList($entity);
|
||||
|
||||
$pdo = $this->getEntityManager()->getPDO();
|
||||
$sql = "
|
||||
SELECT user_id AS userId
|
||||
@@ -55,7 +73,7 @@ class Notifications extends \Espo\Core\Hooks\Base
|
||||
$sth->execute();
|
||||
$userIdList = array();
|
||||
while ($row = $sth->fetch(\PDO::FETCH_ASSOC)) {
|
||||
if ($this->getUser()->id != $row['userId']) {
|
||||
if ($this->getUser()->id != $row['userId'] && !in_array($row['userId'], $mentionedUserList)) {
|
||||
$userIdList[] = $row['userId'];
|
||||
}
|
||||
}
|
||||
@@ -64,10 +82,10 @@ class Notifications extends \Espo\Core\Hooks\Base
|
||||
$job->set(array(
|
||||
'serviceName' => 'Notification',
|
||||
'method' => 'notifyAboutNoteFromJob',
|
||||
'data' => json_encode(array(
|
||||
'data' => array(
|
||||
'userIdList' => $userIdList,
|
||||
'noteId' => $entity->id
|
||||
)),
|
||||
),
|
||||
'executeTime' => date('Y-m-d H:i:s'),
|
||||
));
|
||||
$this->getEntityManager()->saveEntity($job);
|
||||
|
||||
@@ -79,6 +79,8 @@ class Invitations
|
||||
$bodyTpl = file_get_contents($bodyTplFileName);
|
||||
|
||||
$subject = $this->parseInvitationTemplate($subjectTpl, $entity, $invitee, $uid);
|
||||
$subject = str_replace(array("\n", "\r"), '', $subject);
|
||||
|
||||
$body = $this->parseInvitationTemplate($bodyTpl, $entity, $invitee, $uid);
|
||||
|
||||
$email->set('subject', $subject);
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM - Open Source CRM application.
|
||||
* Copyright (C) 2014 Yuri Kuznetsov, Taras Machyshyn, Oleksiy Avramenko
|
||||
* Website: http://www.espocrm.com
|
||||
*
|
||||
* EspoCRM is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* EspoCRM is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with EspoCRM. If not, see http://www.gnu.org/licenses/.
|
||||
************************************************************************/
|
||||
|
||||
namespace Espo\Modules\Crm\Controllers;
|
||||
|
||||
class Contract extends \Espo\Core\Controllers\Record
|
||||
{
|
||||
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM - Open Source CRM application.
|
||||
* Copyright (C) 2014 Yuri Kuznetsov, Taras Machyshyn, Oleksiy Avramenko
|
||||
* Website: http://www.espocrm.com
|
||||
*
|
||||
* EspoCRM is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* EspoCRM is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with EspoCRM. If not, see http://www.gnu.org/licenses/.
|
||||
************************************************************************/
|
||||
|
||||
namespace Espo\Modules\Crm\Controllers;
|
||||
|
||||
class Document extends \Espo\Core\Controllers\Record
|
||||
{
|
||||
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM - Open Source CRM application.
|
||||
* Copyright (C) 2014 Yuri Kuznetsov, Taras Machyshyn, Oleksiy Avramenko
|
||||
* Website: http://www.espocrm.com
|
||||
*
|
||||
* EspoCRM is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* EspoCRM is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with EspoCRM. If not, see http://www.gnu.org/licenses/.
|
||||
************************************************************************/
|
||||
|
||||
namespace Espo\Modules\Crm\Entities;
|
||||
|
||||
class Contract extends \Espo\Core\Entities\Person
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM - Open Source CRM application.
|
||||
* Copyright (C) 2014 Yuri Kuznetsov, Taras Machyshyn, Oleksiy Avramenko
|
||||
* Website: http://www.espocrm.com
|
||||
*
|
||||
* EspoCRM is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* EspoCRM is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with EspoCRM. If not, see http://www.gnu.org/licenses/.
|
||||
************************************************************************/
|
||||
|
||||
namespace Espo\Modules\Crm\Entities;
|
||||
|
||||
class Document extends \Espo\Core\Entities\Person
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@@ -26,18 +26,7 @@ use Espo\ORM\Entity;
|
||||
|
||||
class Lead extends \Espo\Core\ORM\Repositories\RDB
|
||||
{
|
||||
public function handleSelectParams(&$params)
|
||||
{
|
||||
parent::handleSelectParams($params);
|
||||
|
||||
if (empty($params['customJoin'])) {
|
||||
$params['customJoin'] = '';
|
||||
}
|
||||
|
||||
$params['customJoin'] .= "
|
||||
LEFT JOIN currency ON currency.id = lead.opportunity_amount_currency
|
||||
";
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -26,18 +26,7 @@ use Espo\ORM\Entity;
|
||||
|
||||
class Opportunity extends \Espo\Core\ORM\Repositories\RDB
|
||||
{
|
||||
public function handleSelectParams(&$params)
|
||||
{
|
||||
parent::handleSelectParams($params);
|
||||
|
||||
if (empty($params['customJoin'])) {
|
||||
$params['customJoin'] = '';
|
||||
}
|
||||
|
||||
$params['customJoin'] .= "
|
||||
LEFT JOIN currency ON currency.id = opportunity.amount_currency
|
||||
";
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -15,7 +15,8 @@
|
||||
"links": {
|
||||
"contacts": "Contacts",
|
||||
"opportunities": "Opportunities",
|
||||
"cases": "Cases"
|
||||
"cases": "Cases",
|
||||
"documents": "Documents"
|
||||
},
|
||||
"options": {
|
||||
"type": {
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
{
|
||||
"labels": {
|
||||
"Create Document": "Create Document",
|
||||
"Details": "Details"
|
||||
},
|
||||
"fields": {
|
||||
"name": "Name",
|
||||
"status": "Status",
|
||||
"file": "File",
|
||||
"type": "Type",
|
||||
"source": "Source",
|
||||
"publishDate": "Publish Date",
|
||||
"expirationDate": "Expiration Date",
|
||||
"description": "Description"
|
||||
},
|
||||
"links": {
|
||||
"accounts": "Accounts",
|
||||
"opportunities": "Opportunities"
|
||||
},
|
||||
"options": {
|
||||
"status": {
|
||||
"Active": "Active",
|
||||
"Draft": "Draft",
|
||||
"Expired": "Expired",
|
||||
"Canceled": "Canceled"
|
||||
}
|
||||
},
|
||||
"presetFilters": {
|
||||
"active": "Active",
|
||||
"draft": "Draft"
|
||||
}
|
||||
}
|
||||
@@ -10,7 +10,8 @@
|
||||
"Call": "Call",
|
||||
"Task": "Task",
|
||||
"Case": "Case",
|
||||
"InboundEmail": "Inbound Email"
|
||||
"InboundEmail": "Inbound Email",
|
||||
"Document": "Document"
|
||||
},
|
||||
"scopeNamesPlural": {
|
||||
"Account": "Accounts",
|
||||
@@ -23,7 +24,8 @@
|
||||
"Call": "Calls",
|
||||
"Task": "Tasks",
|
||||
"Case": "Cases",
|
||||
"InboundEmail": "Inbound Emails"
|
||||
"InboundEmail": "Inbound Emails",
|
||||
"Document": "Documents"
|
||||
},
|
||||
"dashlets": {
|
||||
"Leads": "My Leads",
|
||||
|
||||
@@ -10,10 +10,12 @@
|
||||
"closeDate": "Close Date",
|
||||
"contacts": "Contacts",
|
||||
"description": "Description",
|
||||
"amountConverted": "Amount (converted)"
|
||||
"amountConverted": "Amount (converted)",
|
||||
"amountWeightedConverted": "Amount Weighted"
|
||||
},
|
||||
"links": {
|
||||
"contacts": "Contacts"
|
||||
"contacts": "Contacts",
|
||||
"documents": "Documents"
|
||||
},
|
||||
"options": {
|
||||
"stage": {
|
||||
|
||||
@@ -29,7 +29,7 @@
|
||||
"Create Task": "Create Task"
|
||||
},
|
||||
"presetFilters": {
|
||||
"active": "Active",
|
||||
"actual": "Actual",
|
||||
"completed": "Completed",
|
||||
"todays": "Today's",
|
||||
"overdue": "Overdue"
|
||||
|
||||
@@ -3,14 +3,14 @@
|
||||
"name": "Nome",
|
||||
"emailAddress": "E-mail",
|
||||
"website": "Website",
|
||||
"phone": "Telefone",
|
||||
"fax": "Fax",
|
||||
"phoneNumber": "Telefone",
|
||||
"billingAddress": "Endereço de Cobrança",
|
||||
"shippingAddress": "Endereço de Entrega",
|
||||
"description": "Descrição",
|
||||
"sicCode": "Código SIC",
|
||||
"sicCode": "CNPJ",
|
||||
"industry": "Indústria",
|
||||
"type": "Tipo"
|
||||
"type": "Tipo",
|
||||
"contactRole": "Regra"
|
||||
},
|
||||
"links": {
|
||||
"contacts": "Contatos",
|
||||
@@ -25,13 +25,13 @@
|
||||
"Reseller": "Revendedor"
|
||||
},
|
||||
"industry": {
|
||||
"Apparel": "Apparel",
|
||||
"Banking": "Banking",
|
||||
"Computer Software": "Computer Software",
|
||||
"Education": "Education",
|
||||
"Electronics": "Electronics",
|
||||
"Finance": "Finance",
|
||||
"Insurance": "Insurance"
|
||||
"Apparel": "Vestuário",
|
||||
"Banking": "Banco",
|
||||
"Computer Software": "Software",
|
||||
"Education": "Educação",
|
||||
"Electronics": "Eletrônicos",
|
||||
"Finance": "Finanças",
|
||||
"Insurance": "Seguros"
|
||||
}
|
||||
},
|
||||
"labels": {
|
||||
|
||||
@@ -23,12 +23,22 @@
|
||||
"direction": {
|
||||
"Outbound": "Saída",
|
||||
"Inbound": "Entrada"
|
||||
}
|
||||
},
|
||||
"acceptanceStatus": {
|
||||
"None": "Nenhum",
|
||||
"Accepted": "Aceita",
|
||||
"Declined": "Rejeitada"
|
||||
}
|
||||
},
|
||||
"labels": {
|
||||
"Create Call": "Criar Ligação",
|
||||
"Set Held": "Marcar como realizada",
|
||||
"Set Not Held": "Marcar como não realizada",
|
||||
"Send Invitations": "Enviar Convites"
|
||||
}
|
||||
},
|
||||
"presetFilters": {
|
||||
"planned": "Planejado",
|
||||
"held": "Realizado",
|
||||
"todays": "Hoje"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,5 +34,9 @@
|
||||
},
|
||||
"labels": {
|
||||
"Create Case": "Criar Atendimento"
|
||||
}
|
||||
},
|
||||
"presetFilters": {
|
||||
"open": "Aberto",
|
||||
"closed": "Fechado"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,12 +4,13 @@
|
||||
"emailAddress": "E-mail",
|
||||
"title": "Cargo",
|
||||
"account": "Conta",
|
||||
"phone": "Telefone",
|
||||
"phoneOffice": "Telefone (Comercial)",
|
||||
"fax": "Fax",
|
||||
"accountType": "Tipo de Conta",
|
||||
"accounts": "Contas",
|
||||
"phoneNumber": "Telefone",
|
||||
"accountType": "Tipo de Conta",
|
||||
"doNotCall": "Não Ligar",
|
||||
"address": "Endereço",
|
||||
"opportunityRole": "Regra de Oportunidade",
|
||||
"accountRole": "Regra",
|
||||
"description": "Descrição"
|
||||
},
|
||||
"links": {
|
||||
@@ -18,5 +19,13 @@
|
||||
},
|
||||
"labels": {
|
||||
"Create Contact": "Criar Contato"
|
||||
}
|
||||
},
|
||||
"options": {
|
||||
"opportunityRole": {
|
||||
"": "--Nenhum--",
|
||||
"Decision Maker": "Tomador de Decisão",
|
||||
"Evaluator": "Avaliador",
|
||||
"Influencer": "Influenciador"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
"Account": "Contas",
|
||||
"Contact": "Contatos",
|
||||
"Lead": "Leads",
|
||||
"Prospect": "Prospectos",
|
||||
"Target": "Alvos",
|
||||
"Opportunity": "Oportunidades",
|
||||
"Meeting": "Reuniões",
|
||||
"Calendar": "Calendário",
|
||||
@@ -31,6 +31,8 @@
|
||||
"Tasks": "Minhas Tarefas",
|
||||
"Cases": "Meus Atendimentos",
|
||||
"Calendar": "Calendário",
|
||||
"Calls": "Minhas Ligações",
|
||||
"Meetings": "Minhas Reuniões",
|
||||
"OpportunitiesByStage": "Oportunidades por Estágio",
|
||||
"OpportunitiesByLeadSource": "Oportunities por Origem do Lead",
|
||||
"SalesByMonth": "Vendas Por Mês",
|
||||
|
||||
@@ -15,9 +15,18 @@
|
||||
"reply": "Responder",
|
||||
"caseDistribution": "Distribuição do Atendimento",
|
||||
"replyEmailTemplate": "Template do E-mail de Resposta",
|
||||
"replyFromAddress": "E-mail de Resposta (From)",
|
||||
"replyFromAddress": "E-mail de Resposta (From)",
|
||||
"replyToAddress": "Responder para o Endereço",
|
||||
"replyFromName": "Nome de Resposta (FromName)"
|
||||
},
|
||||
"tooltips": {
|
||||
"reply": "Notificar rementente que seus e-mails foram recebidos.",
|
||||
"createCase": "Criar automaticamente um atendimento para os e-mais recebidos.",
|
||||
"replyToAddress": "Especifique o endereço de e-mail desta caixa postal para que as respostas cheguem aqui.",
|
||||
"caseDistribution": "Como os atendimentos serão distribuídos. Assinados diretamente ao usuário ou entregues ao time.",
|
||||
"assignToUser": "Usuário responsável pelos e-mails/atendimentos.",
|
||||
"team": "Time que será relacionado aos e-mails/atendimentos."
|
||||
},
|
||||
"links": {
|
||||
},
|
||||
"options": {
|
||||
|
||||
@@ -9,15 +9,14 @@
|
||||
"emailAddress": "E-mail",
|
||||
"title": "Cargo",
|
||||
"website": "Website",
|
||||
"phone": "Telefone",
|
||||
"phoneOffice": "Telefone (Comercial)",
|
||||
"fax": "Fax",
|
||||
"phoneNumber": "Telefone",
|
||||
"accountName": "Conta",
|
||||
"doNotCall": "Não Ligar",
|
||||
"address": "Endereço",
|
||||
"status": "Status",
|
||||
"source": "Origem",
|
||||
"opportunityAmount": "Valor da Oportunidade",
|
||||
"opportunityAmountConverted": "Valor da Oportunidade (convertido)",
|
||||
"description": "Descrição",
|
||||
"createdAccount": "Conta",
|
||||
"createdContact": "Contato",
|
||||
@@ -44,5 +43,8 @@
|
||||
"Campaign": "Campanha",
|
||||
"Other": "Outro"
|
||||
}
|
||||
}
|
||||
},
|
||||
"presetFilters": {
|
||||
"active": "Ativo"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,12 +18,24 @@
|
||||
"Planned": "Planejada",
|
||||
"Held": "Realizada",
|
||||
"Not Held": "Não Realizada"
|
||||
}
|
||||
},
|
||||
"acceptanceStatus": {
|
||||
"None": "Nenhum",
|
||||
"Accepted": "Aceita",
|
||||
"Declined": "Rejeitada"
|
||||
}
|
||||
},
|
||||
"labels": {
|
||||
"Create Meeting": "Criar Reunião",
|
||||
"Set Held": "Marcar como realizada",
|
||||
"Set Not Held": "Marcar como não realizada",
|
||||
"Send Invitations": "Enviar Convites"
|
||||
}
|
||||
"Send Invitations": "Enviar convites",
|
||||
"Saved as Held": "Salvo como realizada",
|
||||
"Saved as Not Held": "Salvo como não realizada"
|
||||
},
|
||||
"presetFilters": {
|
||||
"planned": "Planejada",
|
||||
"held": "Realizada",
|
||||
"todays": "Hoje"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,8 +7,10 @@
|
||||
"probability": "Probabilidade, %",
|
||||
"leadSource": "Lead de Origem",
|
||||
"doNotCall": "Não ligar",
|
||||
"closeDate": "Data para Fechamento",
|
||||
"description": "Descrição"
|
||||
"closeDate": "Data de Fechamento",
|
||||
"contacts": "Contatos",
|
||||
"description": "Descrição",
|
||||
"amountConverted": "Valor (convertido)"
|
||||
},
|
||||
"links": {
|
||||
"contacts": "Contatos"
|
||||
@@ -25,19 +27,13 @@
|
||||
"Negotiation/Review": "Negociação/Revisão",
|
||||
"Closed Won": "Ganha",
|
||||
"Closed Lost": "Perdida"
|
||||
},
|
||||
"leadSource": {
|
||||
"Call": "Ligação",
|
||||
"Email": "E-mail",
|
||||
"Existing Customer": "Cliente Existente",
|
||||
"Partner": "Parceiro",
|
||||
"Public Relations": "Relacionamento",
|
||||
"Web Site": "Website",
|
||||
"Campaign": "Campanha",
|
||||
"Other": "Outros"
|
||||
}
|
||||
},
|
||||
"labels": {
|
||||
"Create Opportunity": "Create Opportunity"
|
||||
}
|
||||
"Create Opportunity": "Criar Oportunidade"
|
||||
},
|
||||
"presetFilters": {
|
||||
"open": "Aberta",
|
||||
"won": "Ganha"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
{
|
||||
"fields": {
|
||||
"name": "Nome",
|
||||
"emailAddress": "E-mail",
|
||||
"title": "Cargo",
|
||||
"website": "Website",
|
||||
"accountName": "Conta",
|
||||
"phoneNumber": "Telefone",
|
||||
"doNotCall": "Não Ligar",
|
||||
"address": "Endereço",
|
||||
"description": "Descrição"
|
||||
},
|
||||
"links": {
|
||||
},
|
||||
"labels": {
|
||||
"Create Target": "Criar Alvo",
|
||||
"Convert to Lead": "Converter para Lead"
|
||||
}
|
||||
}
|
||||
@@ -27,5 +27,11 @@
|
||||
},
|
||||
"labels": {
|
||||
"Create Task": "Criar Tarefa"
|
||||
}
|
||||
},
|
||||
"presetFilters": {
|
||||
"active": "Ativa",
|
||||
"completed": "Completa",
|
||||
"todays": "Hoje",
|
||||
"overdue": "Atrasada"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
{
|
||||
"fields": {
|
||||
"name": "Имя",
|
||||
"emailAddress": "Почта",
|
||||
"website": "Интернет сайт",
|
||||
"phoneNumber": "Телефонный номер",
|
||||
"billingAddress": "Платежный адрес",
|
||||
"shippingAddress": "Почтовый адрес",
|
||||
"description": "Описание",
|
||||
"sicCode": "SicCode",
|
||||
"industry": "Промышленность",
|
||||
"type": "Раздел",
|
||||
"contactRole": "Роль"
|
||||
},
|
||||
"links": {
|
||||
"contacts": "Контакты",
|
||||
"opportunities": "Возможности",
|
||||
"cases": "Обращения"
|
||||
},
|
||||
"options": {
|
||||
"type": {
|
||||
"Customer": "Заказчик",
|
||||
"Investor": "Вкладчик",
|
||||
"Partner": "Партнер",
|
||||
"Reseller": "Посредник"
|
||||
},
|
||||
"industry": {
|
||||
"Apparel": "Одежда",
|
||||
"Banking": "Банковское дело",
|
||||
"Computer Software": "Программное обеспечение",
|
||||
"Education": "Образование",
|
||||
"Electronics": "Электроника",
|
||||
"Finance": "Финансы",
|
||||
"Insurance": "Страхование"
|
||||
}
|
||||
},
|
||||
"labels": {
|
||||
"Create Account": "Создать новую организацию"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"modes": {
|
||||
"month": "месяц",
|
||||
"week": "неделя",
|
||||
"day": "день",
|
||||
"agendaWeek": "На неделю",
|
||||
"agendaDay": "На день"
|
||||
},
|
||||
"labels": {
|
||||
"Today": "Сегодня",
|
||||
"Create": "Создать"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
{
|
||||
"fields": {
|
||||
"name": "Тема",
|
||||
"parent": "Источник",
|
||||
"status": "Статус",
|
||||
"dateStart": "Дата начала",
|
||||
"dateEnd": "Дата окончания",
|
||||
"direction": "Категория",
|
||||
"duration": "Длительность",
|
||||
"description": "Описание",
|
||||
"users": "Пользователи",
|
||||
"contacts": "Контакты",
|
||||
"leads": "Лиды"
|
||||
},
|
||||
"links": {
|
||||
},
|
||||
"options": {
|
||||
"status": {
|
||||
"Planned": "Запланированный",
|
||||
"Held": "Выполнен",
|
||||
"Not Held": "Не состоялся"
|
||||
},
|
||||
"direction": {
|
||||
"Outbound": "Исходящий",
|
||||
"Inbound": "Входящий"
|
||||
}
|
||||
},
|
||||
"labels": {
|
||||
"Create Call": "Новый звонок",
|
||||
"Set Held": "Был выполнен",
|
||||
"Set Not Held": "Не состоялся",
|
||||
"Send Invitations": "Отправить приглашения"
|
||||
},
|
||||
"presetFilters": {
|
||||
"planned": "Запланированные",
|
||||
"held": "Отложенные",
|
||||
"todays": "На сегодня"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
{
|
||||
"fields": {
|
||||
"name": "Имя",
|
||||
"number": "Номер",
|
||||
"status": "Статус",
|
||||
"account": "Организация",
|
||||
"contact": "Контакт",
|
||||
"priority": "Приоритет",
|
||||
"type": "Раздел",
|
||||
"description": "Описание"
|
||||
},
|
||||
"links": {
|
||||
},
|
||||
"options": {
|
||||
"status": {
|
||||
"New": "Новый",
|
||||
"Assigned": "На рассмотрении",
|
||||
"Pending": "Текущее",
|
||||
"Closed": "Закрыто",
|
||||
"Rejected": "Отказано",
|
||||
"Duplicate": "Копия"
|
||||
},
|
||||
"priority" : {
|
||||
"Low": "Низкий",
|
||||
"Normal": "Нормальный",
|
||||
"High": "Высокий",
|
||||
"Urgent": "Срочно"
|
||||
},
|
||||
"type": {
|
||||
"Question": "Вопрос",
|
||||
"Incident": "Происшествие",
|
||||
"Problem": "Проблема"
|
||||
}
|
||||
},
|
||||
"labels": {
|
||||
"Create Case": "Создать обращение"
|
||||
},
|
||||
"presetFilters": {
|
||||
"open": "Открыто",
|
||||
"closed": "Закрыто"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
{
|
||||
"fields": {
|
||||
"name": "Полное имя",
|
||||
"emailAddress": "E-mail",
|
||||
"title": "Должность",
|
||||
"account": "Организация",
|
||||
"accounts": "Организации",
|
||||
"phoneNumber": "Телефон",
|
||||
"accountType": "Тип организации",
|
||||
"doNotCall": "Не звонить",
|
||||
"address": "Адрес",
|
||||
"opportunityRole": "Роль в возможности",
|
||||
"accountRole": "Роль",
|
||||
"description": "Описание",
|
||||
"owner":"Пригласивший"
|
||||
},
|
||||
"links": {
|
||||
"orders": "Заказы",
|
||||
"cases": "Обращения"
|
||||
},
|
||||
"labels": {
|
||||
"Create Contact": "Создать контакт"
|
||||
},
|
||||
"options": {
|
||||
"opportunityRole": {
|
||||
"": "--Нет--",
|
||||
"Decision Maker": "Принимающий решение",
|
||||
"Evaluator": "Оценщик",
|
||||
"Influencer": "Консультант"
|
||||
},
|
||||
"salutationName": {
|
||||
"options": {
|
||||
"Жен": "Жен. ",
|
||||
"Муж": "Муж. "
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
{
|
||||
"scopeNames": {
|
||||
"Account": "Организация",
|
||||
"Contact": "Контакт",
|
||||
"Lead": "Лид",
|
||||
"Target": "Цель",
|
||||
"Opportunity": "Возможность",
|
||||
"Meeting": "Встреча",
|
||||
"Calendar": "Календарь",
|
||||
"Call": "Вызов",
|
||||
"Task": "Задача",
|
||||
"Case": "Обращение",
|
||||
"InboundEmail": "Входящая почта"
|
||||
},
|
||||
"scopeNamesPlural": {
|
||||
"Account": "Организации",
|
||||
"Contact": "Контакты",
|
||||
"Lead": "Лиды",
|
||||
"Target": "Цели",
|
||||
"Opportunity": "Возможности",
|
||||
"Meeting": "Встречи",
|
||||
"Calendar": "Календарь",
|
||||
"Call": "Звонки",
|
||||
"Task": "Задачи",
|
||||
"Case": "Обращения",
|
||||
"InboundEmail": "Входящие письма"
|
||||
},
|
||||
"dashlets": {
|
||||
"Leads": "Мои Лиды",
|
||||
"Opportunities": "Мои возможности",
|
||||
"Tasks": "Мои задачи",
|
||||
"Cases": "Мои обращения",
|
||||
"Calendar": "Календарь",
|
||||
"Calls": "Мои звонки",
|
||||
"Meetings": "Мои встречи",
|
||||
"OpportunitiesByStage": "Возможности в ожидании",
|
||||
"OpportunitiesByLeadSource": "Возможности в разработке",
|
||||
"SalesByMonth": "Продажи по месяцам",
|
||||
"SalesPipeline": "Источники продаж"
|
||||
},
|
||||
"labels": {
|
||||
"Create InboundEmail": "Создать входящую почту",
|
||||
"Activities": "Мероприятия",
|
||||
"History": "История",
|
||||
"Attendees": "Участники",
|
||||
"Schedule Meeting": "Запланировать встречу",
|
||||
"Schedule Call": "Запланировать звонок",
|
||||
"Compose Email": "Создать e-mail",
|
||||
"Log Meeting": "Записать встречу",
|
||||
"Log Call": "Записать звонок",
|
||||
"Archive Email": "Архив e-mail",
|
||||
"Create Task": "Создать задачу",
|
||||
"Tasks": "Задачи"
|
||||
},
|
||||
"fields": {
|
||||
"billingAddressCity": "Город",
|
||||
"billingAddressCountry": "Страна",
|
||||
"billingAddressPostalCode": "Почтовый код",
|
||||
"billingAddressState": "Регион",
|
||||
"billingAddressStreet": "Улица",
|
||||
"addressCity": "Город",
|
||||
"addressStreet": "Улица",
|
||||
"addressCountry": "Страна",
|
||||
"addressState": "Регион",
|
||||
"addressPostalCode": "Почтовый код",
|
||||
"shippingAddressCity": "Город доставки",
|
||||
"shippingAddressStreet": "Улица доставки",
|
||||
"shippingAddressCountry": "Страна доставки",
|
||||
"shippingAddressState": "Регион доставки",
|
||||
"shippingAddressPostalCode": "Почтовый код доставки"
|
||||
},
|
||||
"links": {
|
||||
"contacts": "Контакты",
|
||||
"opportunities": "Возможности",
|
||||
"leads": "Лиды",
|
||||
"meetings": "Встречи",
|
||||
"calls": "Звонки",
|
||||
"tasks": "Задачи",
|
||||
"emails": "E-mail адреса"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
{
|
||||
"fields": {
|
||||
"name": "Имя",
|
||||
"team": "Команда",
|
||||
"status": "Состояние",
|
||||
"assignToUser": "Связаться с пользователем",
|
||||
"host": "Хост",
|
||||
"username": "Имя пользователя",
|
||||
"password": "Пароль",
|
||||
"port": "Порт",
|
||||
"monitoredFolders": "Отслеживаемые разделы",
|
||||
"trashFolder": "Корзина",
|
||||
"ssl": "SSL",
|
||||
"createCase": "Создать обращение",
|
||||
"reply": "Ответ",
|
||||
"caseDistribution": "Распределение обращений",
|
||||
"replyEmailTemplate": "Ответить по образцу",
|
||||
"replyFromAddress": "Ответить с адреса",
|
||||
"replyToAddress": "Адрес для получения ответа",
|
||||
"replyFromName": "Ответить от имени"
|
||||
},
|
||||
"tooltips": {
|
||||
"reply": "Уведомить отправителей, что их письма были получены.",
|
||||
"createCase": "Автоматически создавать обращение из входящих писем.",
|
||||
"replyToAddress": "Укажите адрес для этого ящика, чтобы ответы приходили в него.",
|
||||
"caseDistribution": "Как обращения будут назначаться: на пользователя или среди группы.",
|
||||
"assignToUser": "Пользователь, на которого письма и обращения будут назначаться.",
|
||||
"team": "Группа, к которой будут относиться письма и обращения."
|
||||
},
|
||||
"links": {
|
||||
},
|
||||
"options": {
|
||||
"status": {
|
||||
"Active": "Активный",
|
||||
"Inactive": "Неактивный"
|
||||
},
|
||||
"caseDistribution": {
|
||||
"Direct-Assignment": "Прямая задача",
|
||||
"Round-Robin": "Циклическая",
|
||||
"Least-Busy": "Наиболее свободный"
|
||||
}
|
||||
},
|
||||
"labels": {
|
||||
"Create InboundEmail": "Создать входящее письмо",
|
||||
"IMAP": "IMAP",
|
||||
"Actions": "Действия",
|
||||
"Main": "Главная"
|
||||
},
|
||||
"messages": {
|
||||
"couldNotConnectToImap": "Не получается подключиться к серверу IMAP"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
{
|
||||
"labels": {
|
||||
"Converted To": "Преобразован в",
|
||||
"Create Lead": "Создать Лид",
|
||||
"Convert": "Преобразовать"
|
||||
},
|
||||
"fields": {
|
||||
"name": "Полное имя",
|
||||
"emailAddress": "E-mail",
|
||||
"title": "Должность",
|
||||
"website": "Сайт",
|
||||
"phoneNumber": "Телефон",
|
||||
"accountName": "Название организации",
|
||||
"doNotCall": "Не звонить",
|
||||
"address": "Адрес",
|
||||
"status": "Статус",
|
||||
"source": "Источник",
|
||||
"opportunityAmount": "Возможный доход",
|
||||
"opportunityAmountConverted": "Возможный доход (конвертирован)",
|
||||
"description": "Описание",
|
||||
"createdAccount": "Созданная организация",
|
||||
"createdContact": "Созданный контакт",
|
||||
"createdOpportunity": "Созданная возможность"
|
||||
},
|
||||
"links": {
|
||||
},
|
||||
"options": {
|
||||
"status": {
|
||||
"New": "Новый",
|
||||
"Assigned": "Назначено",
|
||||
"In Process": "В процессе",
|
||||
"Converted": "Преобразовано",
|
||||
"Recycled": "Восстановленный",
|
||||
"Dead": "Мертв"
|
||||
},
|
||||
"source": {
|
||||
"Call": "Звонок",
|
||||
"Email": "E-mail",
|
||||
"Partner": "Партнеры",
|
||||
"Other": "Другое",
|
||||
"friend": "подруга/друг",
|
||||
"relative": "родственник",
|
||||
"1happy": "1 happy",
|
||||
"autopay": "автопей",
|
||||
"vk": "вконтакт",
|
||||
"wife": "жена/муж",
|
||||
"BA": "ба/аба",
|
||||
"mother": "мама/дочь",
|
||||
"radio": "сарафанное радио",
|
||||
"talk": "мое общение",
|
||||
"magic": "волшебным образом"
|
||||
}
|
||||
},
|
||||
"presetFilters": {
|
||||
"active": "Только активные"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
{
|
||||
"fields": {
|
||||
"name": "Имя",
|
||||
"parent": "Источник",
|
||||
"status": "Статус",
|
||||
"dateStart": "Дата начала",
|
||||
"dateEnd": "Дата окончания",
|
||||
"duration": "Продолжительность",
|
||||
"description": "Описание",
|
||||
"users": "Пользователи",
|
||||
"contacts": "Контакты",
|
||||
"leads": "Лиды"
|
||||
},
|
||||
"links": {
|
||||
},
|
||||
"options": {
|
||||
"status": {
|
||||
"Planned": "Запланирована",
|
||||
"Held": "Проведена",
|
||||
"Not Held": "Не состоялась"
|
||||
}
|
||||
},
|
||||
"labels": {
|
||||
"Create Meeting": "Создать встречу",
|
||||
"Set Held": "Была проведена",
|
||||
"Set Not Held": "Не состоялась",
|
||||
"Send Invitations": "Отправить приглашение",
|
||||
"Saved as Held": "Сохранено как состоявшееся",
|
||||
"Saved as Not Held": "Сохранено как несостоявшееся"
|
||||
},
|
||||
"presetFilters": {
|
||||
"planned": "Запланированные",
|
||||
"held": "Проведенные",
|
||||
"todays": "На сегодня"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
{
|
||||
"fields": {
|
||||
"name": "Имя",
|
||||
"account": "Организация",
|
||||
"stage": "Стадия",
|
||||
"amount": "Сумма",
|
||||
"probability": "Вероятность успеха, %",
|
||||
"leadSource": "Лид",
|
||||
"doNotCall": "Не звонить",
|
||||
"closeDate": "Дата закрытия",
|
||||
"contacts": "Контакты",
|
||||
"description": "Описание",
|
||||
"amountConverted": "Сумма (сконвертирована)"
|
||||
},
|
||||
"links": {
|
||||
"contacts": "Контакты"
|
||||
},
|
||||
"options": {
|
||||
"stage": {
|
||||
"Prospecting": "Привлечение клиента",
|
||||
"Qualification": "Оценка возможности",
|
||||
"Needs Analysis": "Требует анализа",
|
||||
"Value Proposition": "Выбор предложения/оферты",
|
||||
"Id. Decision Makers": "Определение ответственного лица",
|
||||
"Perception Analysis": "Проведение анализа",
|
||||
"Proposal/Price Quote": "Отправлено предложение/оферта",
|
||||
"Negotiation/Review": "Согласование/рассмотрение",
|
||||
"Closed Won": "Закрыто - Успех",
|
||||
"Closed Lost": "Закрыто - Провал"
|
||||
}
|
||||
},
|
||||
"labels": {
|
||||
"Create Opportunity": "Создать возможность"
|
||||
},
|
||||
"presetFilters": {
|
||||
"open": "Открытые",
|
||||
"won": "Успешные"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
{
|
||||
"fields": {
|
||||
"name": "Имя",
|
||||
"emailAddress": "E-mail",
|
||||
"title": "Название",
|
||||
"website": "Сайт",
|
||||
"accountName": "Название организации",
|
||||
"phoneNumber": "Телефон",
|
||||
"doNotCall": "Не звонить",
|
||||
"address": "Адрес",
|
||||
"description": "Описание"
|
||||
},
|
||||
"links": {
|
||||
},
|
||||
"labels": {
|
||||
"Create Target": "Создать цель",
|
||||
"Convert to Lead": "Преобразовать в Лид"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
{
|
||||
"fields": {
|
||||
"name": "Имя",
|
||||
"parent": "Источник",
|
||||
"status": "Статус",
|
||||
"dateStart": "Дата начала",
|
||||
"dateEnd": "Дата окончания",
|
||||
"priority": "Приоритет",
|
||||
"description": "Описание",
|
||||
"isOverdue": "Просрочена"
|
||||
},
|
||||
"links": {
|
||||
},
|
||||
"options": {
|
||||
"status": {
|
||||
"Not Started": "Не началась",
|
||||
"Started": "Началась",
|
||||
"Completed": "Завершена",
|
||||
"Canceled": "Отменена"
|
||||
},
|
||||
"priority" : {
|
||||
"Low": "Низкий",
|
||||
"Normal": "Нормальный",
|
||||
"High": "Высокий",
|
||||
"Urgent": "Срочно"
|
||||
}
|
||||
},
|
||||
"labels": {
|
||||
"Create Task": "Создать задачу"
|
||||
},
|
||||
"presetFilters": {
|
||||
"active": "Активные",
|
||||
"completed": "Завершенные",
|
||||
"todays": "На сегодня",
|
||||
"overdue": "Просроченные"
|
||||
}
|
||||
}
|
||||
@@ -1 +1 @@
|
||||
["contacts","opportunities","cases"]
|
||||
["contacts","opportunities","cases","documents"]
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
[
|
||||
{
|
||||
"label":false,
|
||||
"rows":[
|
||||
[{"name":"file"}, {"name":"source"}],
|
||||
[{"name":"name"}, {"name":"status"}],
|
||||
[{"name":"type"}, false]
|
||||
]
|
||||
},
|
||||
{
|
||||
"label": "Details",
|
||||
"rows": [
|
||||
[{"name":"publishDate"}, {"name":"expirationDate"}],
|
||||
[{"name":"description"}, false]
|
||||
]
|
||||
}
|
||||
]
|
||||
@@ -0,0 +1,12 @@
|
||||
[
|
||||
{
|
||||
"label": false,
|
||||
"rows": [
|
||||
[{"name":"source"}],
|
||||
[{"name":"file"}],
|
||||
[{"name":"name"}],
|
||||
[{"name":"type"}],
|
||||
[{"name":"status"}]
|
||||
]
|
||||
}
|
||||
]
|
||||
@@ -0,0 +1,6 @@
|
||||
[
|
||||
"type",
|
||||
"status",
|
||||
"publishDate",
|
||||
"expirationDate"
|
||||
]
|
||||
@@ -0,0 +1,7 @@
|
||||
[
|
||||
{"name":"name","width":25,"link":true},
|
||||
{"name":"file","width":25},
|
||||
{"name":"type"},
|
||||
{"name":"status"},
|
||||
{"name":"createdAt"}
|
||||
]
|
||||
@@ -0,0 +1,7 @@
|
||||
[
|
||||
{"name":"name","width":30,"link":true},
|
||||
{"name":"file","width":10, "view": "Crm:Document.Fields.FileShort","notSortable": true},
|
||||
{"name":"type"},
|
||||
{"name":"status"},
|
||||
{"name":"createdAt"}
|
||||
]
|
||||
@@ -0,0 +1,26 @@
|
||||
{
|
||||
"controller": "Controllers.Record",
|
||||
"presetFilters": [
|
||||
{
|
||||
"name":"active",
|
||||
"style": "primary",
|
||||
"data": {
|
||||
"status": {
|
||||
"type": "in",
|
||||
"value": ["Active"]
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"name":"draft",
|
||||
"style": "default",
|
||||
"data": {
|
||||
"status": {
|
||||
"type": "in",
|
||||
"value": ["Draft"]
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"boolFilters": ["onlyMy"]
|
||||
}
|
||||
@@ -2,7 +2,7 @@
|
||||
"controller": "Controllers.Record",
|
||||
"presetFilters": [
|
||||
{
|
||||
"name":"active",
|
||||
"name":"actual",
|
||||
"style": "primary",
|
||||
"data": {
|
||||
"status": {
|
||||
|
||||
@@ -133,6 +133,11 @@
|
||||
"entity": "Case",
|
||||
"foreign": "account"
|
||||
},
|
||||
"documents": {
|
||||
"type": "hasMany",
|
||||
"entity": "Document",
|
||||
"foreign": "accounts"
|
||||
},
|
||||
"meetings": {
|
||||
"type": "hasChildren",
|
||||
"entity": "Meeting",
|
||||
|
||||
@@ -0,0 +1,99 @@
|
||||
{
|
||||
"fields": {
|
||||
"name": {
|
||||
"type": "varchar",
|
||||
"required": true,
|
||||
"view": "Crm:Document.Fields.Name"
|
||||
},
|
||||
"file": {
|
||||
"type": "file",
|
||||
"required": true
|
||||
},
|
||||
"status": {
|
||||
"type": "enum",
|
||||
"options": ["Active", "Draft", "Expired", "Canceled"],
|
||||
"view": "Fields.EnumStyled",
|
||||
"style": {
|
||||
"Canceled": "danger",
|
||||
"Expired": "danger"
|
||||
}
|
||||
},
|
||||
"source": {
|
||||
"type": "enum",
|
||||
"options": ["Espo"],
|
||||
"default": "Espo"
|
||||
},
|
||||
"type": {
|
||||
"type": "enum",
|
||||
"options": ["", "Contract", "NDA", "EULA", "License Agreement"]
|
||||
},
|
||||
"publishDate": {
|
||||
"type": "date",
|
||||
"required": true,
|
||||
"default": "javascript: return this.dateTime.getToday();"
|
||||
},
|
||||
"expirationDate": {
|
||||
"type": "date",
|
||||
"after": "publishDate"
|
||||
},
|
||||
"description": {
|
||||
"type": "text"
|
||||
},
|
||||
"createdAt": {
|
||||
"type": "datetime",
|
||||
"readOnly": true
|
||||
},
|
||||
"modifiedAt": {
|
||||
"type": "datetime",
|
||||
"readOnly": true
|
||||
},
|
||||
"createdBy": {
|
||||
"type": "link",
|
||||
"readOnly": true
|
||||
},
|
||||
"modifiedBy": {
|
||||
"type": "link",
|
||||
"readOnly": true
|
||||
},
|
||||
"assignedUser": {
|
||||
"type": "link",
|
||||
"required": true
|
||||
},
|
||||
"teams": {
|
||||
"type": "linkMultiple"
|
||||
}
|
||||
},
|
||||
"links": {
|
||||
"accounts": {
|
||||
"type": "hasMany",
|
||||
"entity": "Account",
|
||||
"foreign": "documents"
|
||||
},
|
||||
"opportunities": {
|
||||
"type": "hasMany",
|
||||
"entity": "Opportunity",
|
||||
"foreign": "documents"
|
||||
},
|
||||
"createdBy": {
|
||||
"type": "belongsTo",
|
||||
"entity": "User"
|
||||
},
|
||||
"modifiedBy": {
|
||||
"type": "belongsTo",
|
||||
"entity": "User"
|
||||
},
|
||||
"assignedUser": {
|
||||
"type": "belongsTo",
|
||||
"entity": "User"
|
||||
},
|
||||
"teams": {
|
||||
"type": "hasMany",
|
||||
"entity": "Team",
|
||||
"relationName": "EntityTeam"
|
||||
}
|
||||
},
|
||||
"collection": {
|
||||
"sortBy": "createdAt",
|
||||
"asc": false
|
||||
}
|
||||
}
|
||||
@@ -39,22 +39,11 @@
|
||||
},
|
||||
"opportunityAmount": {
|
||||
"type": "currency",
|
||||
"audited": true,
|
||||
"orderBy": "opportunityAmountConverted {direction}"
|
||||
"audited": true
|
||||
},
|
||||
"opportunityAmountConverted": {
|
||||
"type": "float",
|
||||
"notStorable": true,
|
||||
"readOnly": true,
|
||||
"select": "lead.opportunity_amount * currency.rate",
|
||||
"where": {
|
||||
"=": "lead.opportunity_amount * currency.rate = {value}",
|
||||
">": "lead.opportunity_amount * currency.rate > {value}",
|
||||
"<": "lead.opportunity_amount * currency.rate < {value}",
|
||||
">=": "lead.opportunity_amount * currency.rate >= {value}",
|
||||
"<=": "lead.opportunity_amount * currency.rate <= {value}",
|
||||
"<>": "lead.opportunity_amount * currency.rate <> {value}"
|
||||
}
|
||||
"type": "currencyConverted",
|
||||
"readOnly": true
|
||||
},
|
||||
"website": {
|
||||
"type": "url"
|
||||
|
||||
@@ -7,22 +7,27 @@
|
||||
"amount": {
|
||||
"type": "currency",
|
||||
"required": true,
|
||||
"audited": true,
|
||||
"orderBy": "amountConverted {direction}"
|
||||
"audited": true
|
||||
},
|
||||
"amountConverted": {
|
||||
"type": "currencyConverted",
|
||||
"readOnly": true
|
||||
},
|
||||
"amountWeightedConverted": {
|
||||
"type": "float",
|
||||
"notStorable": true,
|
||||
"readOnly": true,
|
||||
"select": "opportunity.amount * currency.rate",
|
||||
"notStorable": true,
|
||||
"select": "opportunity.amount * amount_currency_alias.rate * opportunity.probability / 100",
|
||||
"where": {
|
||||
"=": "opportunity.amount * currency.rate = {value}",
|
||||
">": "opportunity.amount * currency.rate > {value}",
|
||||
"<": "opportunity.amount * currency.rate < {value}",
|
||||
">=": "opportunity.amount * currency.rate >= {value}",
|
||||
"<=": "opportunity.amount * currency.rate <= {value}",
|
||||
"<>": "opportunity.amount * currency.rate <> {value}"
|
||||
}
|
||||
"=": "(opportunity.amount * amount_currency_alias.rate * opportunity.probability / 100) = {value}",
|
||||
"<": "(opportunity.amount * amount_currency_alias.rate * opportunity.probability / 100) < {value}",
|
||||
">": "(opportunity.amount * amount_currency_alias.rate * opportunity.probability / 100) > {value}",
|
||||
"<=": "(opportunity.amount * amount_currency_alias.rate * opportunity.probability / 100) <= {value}",
|
||||
">=": "(opportunity.amount * amount_currency_alias.rate * opportunity.probability / 100) >= {value}",
|
||||
"<>": "(opportunity.amount * amount_currency_alias.rate * opportunity.probability / 100) <> {value}"
|
||||
},
|
||||
"orderBy": "amountWeightedConverted {direction}",
|
||||
"view": "Fields.CurrencyConverted"
|
||||
},
|
||||
"account": {
|
||||
"type": "link",
|
||||
@@ -136,6 +141,11 @@
|
||||
"type": "hasChildren",
|
||||
"entity": "Email",
|
||||
"foreign": "parent"
|
||||
},
|
||||
"documents": {
|
||||
"type": "hasMany",
|
||||
"entity": "Document",
|
||||
"foreign": "opportunities"
|
||||
}
|
||||
},
|
||||
"collection": {
|
||||
|
||||
@@ -9,8 +9,7 @@
|
||||
"options": ["Not Started", "Started", "Completed", "Canceled"],
|
||||
"view": "Fields.EnumStyled",
|
||||
"style": {
|
||||
"Completed": "success",
|
||||
"Canceled": "danger"
|
||||
"Completed": "success"
|
||||
}
|
||||
},
|
||||
"priority": {
|
||||
@@ -24,11 +23,13 @@
|
||||
},
|
||||
"dateEnd": {
|
||||
"type": "datetime",
|
||||
"after": "dateStart"
|
||||
"after": "dateStart",
|
||||
"view": "Crm:Task.Fields.DateEnd"
|
||||
},
|
||||
"isOverdue": {
|
||||
"type": "base",
|
||||
"db": false,
|
||||
"type": "bool",
|
||||
"readOnly": true,
|
||||
"notStorable": true,
|
||||
"view": "Crm:Task.Fields.IsOverdue"
|
||||
},
|
||||
"description": {
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user