mirror of
https://github.com/espocrm/espocrm.git
synced 2026-03-08 03:47:01 +00:00
Compare commits
332 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
359a4ecc45 | ||
|
|
2538f8befc | ||
|
|
3bb0fdbf91 | ||
|
|
caec038c2c | ||
|
|
331602e32b | ||
|
|
cdbc91afcd | ||
|
|
b2fb451620 | ||
|
|
a548245fca | ||
|
|
d12ae68bf4 | ||
|
|
bfb0fcba0c | ||
|
|
40e639f4ba | ||
|
|
831b240f99 | ||
|
|
363aea4c96 | ||
|
|
8bbd918c51 | ||
|
|
304078420c | ||
|
|
6a7a7d9f04 | ||
|
|
fbeb19e69f | ||
|
|
7cfc539ce9 | ||
|
|
b65e23edfe | ||
|
|
3ba308e513 | ||
|
|
6379198019 | ||
|
|
016992573f | ||
|
|
96e827d64d | ||
|
|
cae40465f5 | ||
|
|
d2669dba5e | ||
|
|
e3aa0a40fe | ||
|
|
8dd9fb089a | ||
|
|
e2e384dd76 | ||
|
|
8a4e36a02d | ||
|
|
c4037c0333 | ||
|
|
cb3200f5dd | ||
|
|
e6def8bd4b | ||
|
|
218ce00930 | ||
|
|
ad12f78668 | ||
|
|
ea07895f02 | ||
|
|
023ab86684 | ||
|
|
dc6ba1128d | ||
|
|
40e6c6a648 | ||
|
|
982e3bd9b7 | ||
|
|
efefd8864c | ||
|
|
ca40ed79ee | ||
|
|
07866a266f | ||
|
|
5007b090fd | ||
|
|
95f6b8cd5c | ||
|
|
93f5da1a62 | ||
|
|
8632064bf7 | ||
|
|
544ad898a3 | ||
|
|
ea17b967c2 | ||
|
|
8db78f61d6 | ||
|
|
161673b88a | ||
|
|
6d81d9f6b2 | ||
|
|
f3ed8a67bc | ||
|
|
06702345da | ||
|
|
a5cb57dcfd | ||
|
|
36a4e48a2b | ||
|
|
074bd5a724 | ||
|
|
36b1fbff36 | ||
|
|
620e695d7e | ||
|
|
74dc2c07ea | ||
|
|
3b17d0ade3 | ||
|
|
07cf316c9c | ||
|
|
fa17104d13 | ||
|
|
274663e426 | ||
|
|
ec338fb0fd | ||
|
|
0093fb6670 | ||
|
|
8d36142ad1 | ||
|
|
8bcbec1e11 | ||
|
|
a1a8c157a0 | ||
|
|
7349edcb0c | ||
|
|
594eec29ce | ||
|
|
ff9db53f4f | ||
|
|
2f3fe50aff | ||
|
|
1e1a8c0ad0 | ||
|
|
03196e5728 | ||
|
|
c3bbdb2722 | ||
|
|
9e0e743dc5 | ||
|
|
a565b9c981 | ||
|
|
d85135dd69 | ||
|
|
380304dca1 | ||
|
|
c95c564961 | ||
|
|
9022aebc7e | ||
|
|
b91d6dc2cf | ||
|
|
1a2a8e6b9e | ||
|
|
6bf1de18e7 | ||
|
|
77fba6eb88 | ||
|
|
2e5cef2abb | ||
|
|
2dbb44eb16 | ||
|
|
6dc23517cc | ||
|
|
6c74281190 | ||
|
|
fa993957a1 | ||
|
|
bfa16ecabe | ||
|
|
c359b450f8 | ||
|
|
a638713e80 | ||
|
|
86715684e1 | ||
|
|
b79ea12b44 | ||
|
|
9f24998184 | ||
|
|
88018bf500 | ||
|
|
f95436f513 | ||
|
|
fa8c5adc25 | ||
|
|
0ee966eddd | ||
|
|
f723882f60 | ||
|
|
8333c51e42 | ||
|
|
6abc64fcb2 | ||
|
|
837b324fe8 | ||
|
|
6c56269f18 | ||
|
|
1101d717f2 | ||
|
|
8e177749ef | ||
|
|
ce30c759a3 | ||
|
|
56abf49301 | ||
|
|
f726881f48 | ||
|
|
d908da46cb | ||
|
|
230428456a | ||
|
|
fda8de500c | ||
|
|
583f3d33e8 | ||
|
|
d0abed98d1 | ||
|
|
38b820739d | ||
|
|
0ccda10de8 | ||
|
|
5358984b2d | ||
|
|
e972276487 | ||
|
|
91d4d9bcf9 | ||
|
|
7f3b489832 | ||
|
|
107584e0f9 | ||
|
|
0bf33e6110 | ||
|
|
9aaedea764 | ||
|
|
33c3594273 | ||
|
|
72824c2796 | ||
|
|
bf56c5fe60 | ||
|
|
5c93b49f6a | ||
|
|
f60fd168e6 | ||
|
|
1399913606 | ||
|
|
b233ab506d | ||
|
|
053793be9c | ||
|
|
53503fa615 | ||
|
|
ed4081596b | ||
|
|
6bdfb30c33 | ||
|
|
322d4cffcf | ||
|
|
1a9e03d540 | ||
|
|
cff5e0f688 | ||
|
|
85fb55c999 | ||
|
|
b944a98cf6 | ||
|
|
9c73f83353 | ||
|
|
5caa29b948 | ||
|
|
71efbe8eea | ||
|
|
81077a1c38 | ||
|
|
32e882780e | ||
|
|
23a373f2cf | ||
|
|
0a2c79ba81 | ||
|
|
5360ba0147 | ||
|
|
6620254d00 | ||
|
|
f6eb0bcce8 | ||
|
|
c1116ff5dc | ||
|
|
330fef673a | ||
|
|
7dcdfcd231 | ||
|
|
0eadb9af69 | ||
|
|
a269c0c96c | ||
|
|
ed37380d8e | ||
|
|
fdef9838d1 | ||
|
|
3c3518b857 | ||
|
|
e85f21da92 | ||
|
|
f3ab0a734c | ||
|
|
33adc67dee | ||
|
|
18e475e1b6 | ||
|
|
438c0f7edd | ||
|
|
3159c9d288 | ||
|
|
fe0f93784b | ||
|
|
2d237eae29 | ||
|
|
747aa2d882 | ||
|
|
46a7119ce1 | ||
|
|
c18342694f | ||
|
|
bb47b70f31 | ||
|
|
07767b2dae | ||
|
|
88037c8291 | ||
|
|
ee03c686ca | ||
|
|
78140f7d5e | ||
|
|
549acfd032 | ||
|
|
e4dab33792 | ||
|
|
287f95a8ac | ||
|
|
4951f8464e | ||
|
|
8ed9b9ebd2 | ||
|
|
96ed9612d4 | ||
|
|
1fd77a4c13 | ||
|
|
2390ac10a8 | ||
|
|
03572ecaad | ||
|
|
c1ac692304 | ||
|
|
f371090bde | ||
|
|
e28341f154 | ||
|
|
870f871ceb | ||
|
|
c18d892a4e | ||
|
|
c8bfd1c6dd | ||
|
|
c582860d5c | ||
|
|
1796db30fa | ||
|
|
25aa0ec564 | ||
|
|
f3dc904c65 | ||
|
|
343d33e741 | ||
|
|
276480dcfa | ||
|
|
b00b725af5 | ||
|
|
ab71ced531 | ||
|
|
ba7988a842 | ||
|
|
e1355acda1 | ||
|
|
1853f4f113 | ||
|
|
da677cfae8 | ||
|
|
272bccc2fd | ||
|
|
5372155773 | ||
|
|
e1579295da | ||
|
|
cc708e03d1 | ||
|
|
34e91958d6 | ||
|
|
928e4c2fb5 | ||
|
|
cf86fcda85 | ||
|
|
db3b36a639 | ||
|
|
a4a731437e | ||
|
|
51f4c7fa09 | ||
|
|
cbce4fc327 | ||
|
|
4e953f6fa8 | ||
|
|
0ed0420a4b | ||
|
|
16961795af | ||
|
|
c52c7fed59 | ||
|
|
95c00fc49d | ||
|
|
9f8606dd06 | ||
|
|
b33dc9baae | ||
|
|
8cb95f1b0e | ||
|
|
86cd1ab864 | ||
|
|
df842f3e3e | ||
|
|
572455ecf6 | ||
|
|
7692f9e3ad | ||
|
|
be0c1d8ab1 | ||
|
|
4a6c3d9e18 | ||
|
|
e0fdbd90fd | ||
|
|
18a3f2658a | ||
|
|
80ee06ec1d | ||
|
|
f16adeed99 | ||
|
|
9ca39f3559 | ||
|
|
19285372d6 | ||
|
|
61df6bec45 | ||
|
|
8904d4ddaf | ||
|
|
ca5fba97df | ||
|
|
fa755efefb | ||
|
|
d6085f4985 | ||
|
|
4c01e9329d | ||
|
|
9813eeb5bc | ||
|
|
09d571a639 | ||
|
|
fffd44316e | ||
|
|
a704830b86 | ||
|
|
7910f71428 | ||
|
|
52dcc51f4f | ||
|
|
f870ded9e0 | ||
|
|
224c72c875 | ||
|
|
ed50802073 | ||
|
|
1f5036eb5f | ||
|
|
701a60a07f | ||
|
|
c760f7364c | ||
|
|
4c28409a36 | ||
|
|
e932681166 | ||
|
|
a8209488ee | ||
|
|
d48642ca81 | ||
|
|
6561c4b6c2 | ||
|
|
4f5f84c8f7 | ||
|
|
56a04336fe | ||
|
|
1814529d3e | ||
|
|
1dbe2d9eac | ||
|
|
4ca099afc4 | ||
|
|
7ca09bc893 | ||
|
|
0a4a8c956a | ||
|
|
6f2a7ae08f | ||
|
|
45a9dd1226 | ||
|
|
9d904171c9 | ||
|
|
53abea7cdd | ||
|
|
6427604724 | ||
|
|
0d72dc7c2f | ||
|
|
9ee5a98ff4 | ||
|
|
3f0c92744c | ||
|
|
7a87749c4c | ||
|
|
0eaab6b7ee | ||
|
|
b52722565a | ||
|
|
80fd2a2006 | ||
|
|
1c1fdffb7d | ||
|
|
53481890db | ||
|
|
b82a3d0f31 | ||
|
|
1700b27501 | ||
|
|
635064e116 | ||
|
|
f6e45d8a68 | ||
|
|
ee0cf4bca5 | ||
|
|
ae98290721 | ||
|
|
24bbcf0e0a | ||
|
|
23b1945a3e | ||
|
|
e1fe3c03dd | ||
|
|
7e0034f674 | ||
|
|
d73cfbca53 | ||
|
|
3eec2b2a33 | ||
|
|
d60dc744e6 | ||
|
|
bd66211c3c | ||
|
|
2f341c8967 | ||
|
|
5c7612c9cf | ||
|
|
b41c0f34aa | ||
|
|
14eebc7392 | ||
|
|
5a86d0e396 | ||
|
|
a4e0c8107d | ||
|
|
1652de16a7 | ||
|
|
ad539e19a2 | ||
|
|
592f073bf9 | ||
|
|
d5c1d1b86e | ||
|
|
bd70e2424c | ||
|
|
06d6299d7f | ||
|
|
d00d2bdb0f | ||
|
|
9f481f6887 | ||
|
|
47d0501828 | ||
|
|
a4cd8dccfe | ||
|
|
eee0f0eb13 | ||
|
|
67b9600341 | ||
|
|
4c0329e6be | ||
|
|
ff6cd18411 | ||
|
|
8d4219802b | ||
|
|
07e7374a18 | ||
|
|
060f517591 | ||
|
|
1af5e93bd3 | ||
|
|
38df3162b3 | ||
|
|
e03298b041 | ||
|
|
80278b7213 | ||
|
|
a701905e9c | ||
|
|
59b896e594 | ||
|
|
ba4c8e0afd | ||
|
|
9175d8c7ce | ||
|
|
052fee6ba2 | ||
|
|
aae3afc895 | ||
|
|
1892ff6cae | ||
|
|
aa3e9fd8b0 | ||
|
|
2863092911 | ||
|
|
1c36421157 | ||
|
|
77f7da0ba5 | ||
|
|
a5f858dda2 | ||
|
|
a5b7bfc00e | ||
|
|
4d2cb6c38e | ||
|
|
b6bd70d47c |
10
.gitignore
vendored
10
.gitignore
vendored
@@ -2,16 +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/cache/*
|
||||
composer.phar
|
||||
vendor/
|
||||
|
||||
26
.htaccess
26
.htaccess
@@ -1,10 +1,26 @@
|
||||
<ifModule mod_headers.c>
|
||||
Header always set Access-Control-Allow-Methods "POST, GET, PUT, PATCH, DELETE"
|
||||
</ifModule>
|
||||
|
||||
DirectoryIndex index.php index.html
|
||||
|
||||
RedirectMatch 403 \.config$
|
||||
|
||||
<IfModule mod_rewrite.c>
|
||||
RewriteEngine On
|
||||
RewriteRule .* - [E=HTTP_ESPO_CGI_AUTH:%{HTTP:Authorization}]
|
||||
RewriteEngine On
|
||||
|
||||
RewriteRule reset/?$ reset.html [QSA,L]
|
||||
# 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]
|
||||
</IfModule>
|
||||
98
Gruntfile.js
98
Gruntfile.js
@@ -1,4 +1,50 @@
|
||||
module.exports = function (grunt) {
|
||||
|
||||
var jsFilesToMinify = [
|
||||
'client/lib/jquery-2.0.2.min.js',
|
||||
'client/lib/underscore-min.js',
|
||||
'client/lib/backbone-min.js',
|
||||
'client/lib/handlebars.js',
|
||||
'client/lib/base64.js',
|
||||
'client/lib/jquery-ui.min.js',
|
||||
'client/lib/moment.min.js',
|
||||
'client/lib/moment-timezone-with-data.min.js',
|
||||
'client/lib/jquery.timepicker.min.js',
|
||||
'client/lib/jquery.autocomplete.js',
|
||||
'client/lib/bootstrap.min.js',
|
||||
'client/lib/bootstrap-datepicker.js',
|
||||
'client/lib/bull.min.js',
|
||||
'client/src/namespace.js',
|
||||
'client/src/exceptions.js',
|
||||
'client/src/app.js',
|
||||
'client/src/utils.js',
|
||||
'client/src/storage.js',
|
||||
'client/src/loader.js',
|
||||
'client/src/pre-loader.js',
|
||||
'client/src/ui.js',
|
||||
'client/src/acl.js',
|
||||
'client/src/model.js',
|
||||
'client/src/model-offline.js',
|
||||
'client/src/metadata.js',
|
||||
'client/src/language.js',
|
||||
'client/src/cache.js',
|
||||
'client/src/controller.js',
|
||||
'client/src/router.js',
|
||||
'client/src/date-time.js',
|
||||
'client/src/field-manager.js',
|
||||
'client/src/search-manager.js',
|
||||
'client/src/collection.js',
|
||||
'client/src/multi-collection.js',
|
||||
'client/src/view-helper.js',
|
||||
'client/src/layout-manager.js',
|
||||
'client/src/model-factory.js',
|
||||
'client/src/collection-factory.js',
|
||||
'client/src/models/settings.js',
|
||||
'client/src/models/user.js',
|
||||
'client/src/models/preferences.js',
|
||||
'client/src/controllers/base.js',
|
||||
'client/src/view.js',
|
||||
];
|
||||
|
||||
grunt.initConfig({
|
||||
pkg: grunt.file.readJSON('package.json'),
|
||||
@@ -44,53 +90,9 @@ module.exports = function (grunt) {
|
||||
mangle: false,
|
||||
banner: '/*! <%= pkg.name %> <%= grunt.template.today("yyyy-mm-dd") %> */\n',
|
||||
},
|
||||
'build/tmp/client/espo.min.js': [
|
||||
'frontend/client/lib/jquery-2.0.2.min.js',
|
||||
'frontend/client/lib/underscore-min.js',
|
||||
'frontend/client/lib/backbone-min.js',
|
||||
'frontend/client/lib/handlebars.js',
|
||||
'frontend/client/lib/base64.js',
|
||||
'frontend/client/lib/jquery-ui.min.js',
|
||||
'frontend/client/lib/moment.min.js',
|
||||
'frontend/client/lib/moment-timezone-with-data.min.js',
|
||||
'frontend/client/lib/jquery.timepicker.min.js',
|
||||
'frontend/client/lib/jquery.autocomplete.js',
|
||||
'frontend/client/lib/bootstrap.min.js',
|
||||
'frontend/client/lib/bootstrap-datepicker.js',
|
||||
'frontend/client/lib/bull.min.js',
|
||||
'frontend/client/src/namespace.js',
|
||||
'frontend/client/src/exceptions.js',
|
||||
'frontend/client/src/app.js',
|
||||
'frontend/client/src/utils.js',
|
||||
'frontend/client/src/storage.js',
|
||||
'frontend/client/src/loader.js',
|
||||
'frontend/client/src/pre-loader.js',
|
||||
'frontend/client/src/ui.js',
|
||||
'frontend/client/src/acl.js',
|
||||
'frontend/client/src/model.js',
|
||||
'frontend/client/src/model-offline.js',
|
||||
'frontend/client/src/metadata.js',
|
||||
'frontend/client/src/language.js',
|
||||
'frontend/client/src/cache.js',
|
||||
'frontend/client/src/controller.js',
|
||||
'frontend/client/src/router.js',
|
||||
'frontend/client/src/date-time.js',
|
||||
'frontend/client/src/field-manager.js',
|
||||
'frontend/client/src/search-manager.js',
|
||||
'frontend/client/src/collection.js',
|
||||
'frontend/client/src/multi-collection.js',
|
||||
'frontend/client/src/view-helper.js',
|
||||
'frontend/client/src/layout-manager.js',
|
||||
'frontend/client/src/model-factory.js',
|
||||
'frontend/client/src/collection-factory.js',
|
||||
'frontend/client/src/models/settings.js',
|
||||
'frontend/client/src/models/user.js',
|
||||
'frontend/client/src/models/preferences.js',
|
||||
'frontend/client/src/controllers/base.js',
|
||||
'frontend/client/src/view.js',
|
||||
'frontend/client/src/views/base.js',
|
||||
'frontend/client/src/views/login.js',
|
||||
]
|
||||
'build/tmp/client/espo.min.js': jsFilesToMinify.map(function (item) {
|
||||
return 'frontend/' + item;
|
||||
})
|
||||
},
|
||||
copy: {
|
||||
frontendFolders: {
|
||||
@@ -134,7 +136,7 @@ module.exports = function (grunt) {
|
||||
'index.php',
|
||||
'LICENSE.txt',
|
||||
'.htaccess',
|
||||
'Web.config',
|
||||
'web.config',
|
||||
],
|
||||
dest: 'build/tmp/',
|
||||
},
|
||||
|
||||
29
README.md
Normal file
29
README.md
Normal file
@@ -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).
|
||||
|
||||
22
Web.config
22
Web.config
@@ -1,22 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<configuration>
|
||||
|
||||
<system.webServer>
|
||||
<rewrite>
|
||||
<rules>
|
||||
<rule name="rule 1X" stopProcessing="true">
|
||||
<match url="reset/?$" />
|
||||
<action type="Rewrite" url="reset.html" appendQueryString="true" />
|
||||
</rule>
|
||||
</rules>
|
||||
</rewrite>
|
||||
|
||||
<defaultDocument>
|
||||
<files>
|
||||
<clear />
|
||||
<add value="index.php" />
|
||||
</files>
|
||||
</defaultDocument>
|
||||
</system.webServer>
|
||||
|
||||
</configuration>
|
||||
@@ -1,2 +0,0 @@
|
||||
Order Deny,Allow
|
||||
Deny from all
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -24,5 +24,11 @@ namespace Espo\Controllers;
|
||||
|
||||
class Email extends \Espo\Core\Controllers\Record
|
||||
{
|
||||
|
||||
public function actionGetCopiedAttachments($params, $data, $request)
|
||||
{
|
||||
$id = $request->get('id');
|
||||
|
||||
return $this->getRecordService()->getCopiedAttachments($id);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
40
application/Espo/Controllers/EmailAccount.php
Normal file
40
application/Espo/Controllers/EmailAccount.php
Normal file
@@ -0,0 +1,40 @@
|
||||
<?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;
|
||||
|
||||
class EmailAccount extends \Espo\Core\Controllers\Record
|
||||
{
|
||||
public function actionGetFolders($params, $data, $request)
|
||||
{
|
||||
return $this->getRecordService()->getFolders(array(
|
||||
'host' => $request->get('host'),
|
||||
'port' => $request->get('port'),
|
||||
'ssl' => $request->get('ssl'),
|
||||
'username' => $request->get('username'),
|
||||
'password' => $request->get('password'),
|
||||
'id' => $request->get('id')
|
||||
));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,5 +24,14 @@ namespace Espo\Controllers;
|
||||
|
||||
class EmailAddress extends \Espo\Core\Controllers\Record
|
||||
{
|
||||
|
||||
public function actionSearchInAddressBook($params, $data, $request)
|
||||
{
|
||||
$q = $request->get('q');
|
||||
$limit = intval($request->get('limit'));
|
||||
if (empty($limit) || $limit > 30) {
|
||||
$limit = 5;
|
||||
}
|
||||
return $this->getRecordService()->searchInAddressBook($q, $limit);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
131
application/Espo/Controllers/Extension.php
Normal file
131
application/Espo/Controllers/Extension.php
Normal file
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
124
application/Espo/Controllers/ExternalAccount.php
Normal file
124
application/Espo/Controllers/ExternalAccount.php
Normal file
@@ -0,0 +1,124 @@
|
||||
<?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 ExternalAccount extends \Espo\Core\Controllers\Record
|
||||
{
|
||||
public static $defaultAction = 'list';
|
||||
|
||||
public function actionList($params, $data, $request)
|
||||
{
|
||||
$integrations = $this->getEntityManager()->getRepository('Integration')->find();
|
||||
$arr = array();
|
||||
foreach ($integrations as $entity) {
|
||||
if ($entity->get('enabled') && $this->getMetadata()->get('integrations.' . $entity->id .'.allowUserAccounts')) {
|
||||
$arr[] = array(
|
||||
'id' => $entity->id
|
||||
);
|
||||
}
|
||||
}
|
||||
return array(
|
||||
'list' => $arr
|
||||
);
|
||||
}
|
||||
|
||||
public function actionGetOAuth2Info($params, $data, $request)
|
||||
{
|
||||
$id = $request->get('id');
|
||||
list($integration, $userId) = explode('__', $id);
|
||||
|
||||
|
||||
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',
|
||||
'isConnected' => $this->getRecordService()->ping($integration, $userId)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public function actionRead($params, $data, $request)
|
||||
{
|
||||
list($integration, $userId) = explode('__', $params['id']);
|
||||
|
||||
if ($this->getUser()->id != $userId) {
|
||||
throw new Forbidden();
|
||||
}
|
||||
|
||||
$entity = $this->getEntityManager()->getEntity('ExternalAccount', $params['id']);
|
||||
return $entity->toArray();
|
||||
}
|
||||
|
||||
public function actionUpdate($params, $data)
|
||||
{
|
||||
return $this->actionPatch($params, $data);
|
||||
}
|
||||
|
||||
public function actionPatch($params, $data)
|
||||
{
|
||||
list($integration, $userId) = explode('__', $params['id']);
|
||||
|
||||
|
||||
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']);
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ class GlobalSearch extends \Espo\Core\Controllers\Base
|
||||
$offset = $request->get('offset');
|
||||
$maxSize = $request->get('maxSize');
|
||||
|
||||
return $this->getService('GlobalSearch')->find($query, $offset);
|
||||
return $this->getService('GlobalSearch')->find($query, $offset, $maxSize);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -44,7 +44,8 @@ class Import extends \Espo\Core\Controllers\Base
|
||||
$contents = $data;
|
||||
|
||||
$attachment = $this->getEntityManager()->getEntity('Attachment');
|
||||
$attachment->set('type', 'text/csv');
|
||||
$attachment->set('type', 'text/csv');
|
||||
$attachment->set('role', 'Import File');
|
||||
$this->getEntityManager()->saveEntity($attachment);
|
||||
|
||||
$this->getFileManager()->putContents('data/upload/' . $attachment->id, $contents);
|
||||
|
||||
61
application/Espo/Controllers/Integration.php
Normal file
61
application/Espo/Controllers/Integration.php
Normal file
@@ -0,0 +1,61 @@
|
||||
<?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;
|
||||
|
||||
class Integration extends \Espo\Core\Controllers\Record
|
||||
{
|
||||
protected function checkControllerAccess()
|
||||
{
|
||||
if (!$this->getUser()->isAdmin()) {
|
||||
throw new Forbidden();
|
||||
}
|
||||
}
|
||||
|
||||
public function actionIndex($params, $data, $request)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public function actionRead($params, $data, $request)
|
||||
{
|
||||
$entity = $this->getEntityManager()->getEntity('Integration', $params['id']);
|
||||
return $entity->toArray();
|
||||
}
|
||||
|
||||
public function actionUpdate($params, $data)
|
||||
{
|
||||
return $this->actionPatch($params, $data);
|
||||
}
|
||||
|
||||
public function actionPatch($params, $data)
|
||||
{
|
||||
$entity = $this->getEntityManager()->getEntity('Integration', $params['id']);
|
||||
$entity->set($data);
|
||||
$this->getEntityManager()->saveEntity($entity);
|
||||
|
||||
return $entity->toArray();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -68,6 +68,8 @@ class Preferences extends \Espo\Core\Controllers\Base
|
||||
$entity->set('smtpEmailAddress', $user->get('emailAddress'));
|
||||
$entity->set('name', $user->get('name'));
|
||||
|
||||
$entity->clear('smtpPassword');
|
||||
|
||||
return $entity->toArray();
|
||||
}
|
||||
throw new Error();
|
||||
@@ -83,6 +85,9 @@ class Preferences extends \Espo\Core\Controllers\Base
|
||||
|
||||
$entity->set('smtpEmailAddress', $user->get('emailAddress'));
|
||||
$entity->set('name', $user->get('name'));
|
||||
|
||||
$entity->clear('smtpPassword');
|
||||
|
||||
if ($entity) {
|
||||
return $entity->toArray();
|
||||
}
|
||||
|
||||
@@ -63,6 +63,12 @@ class Settings extends \Espo\Core\Controllers\Base
|
||||
throw new Error('Cannot save settings');
|
||||
}
|
||||
|
||||
/** Rebuild for Currency Settings */
|
||||
if (isset($data['baseCurrency']) || isset($data['currencyRates'])) {
|
||||
$this->getContainer()->get('dataManager')->rebuildDatabase(array());
|
||||
}
|
||||
/** END Rebuild for Currency Settings */
|
||||
|
||||
return $this->getConfigData();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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'));
|
||||
|
||||
@@ -44,7 +44,7 @@ class User extends \Espo\Core\Controllers\Record
|
||||
throw new NotFound();
|
||||
}
|
||||
|
||||
$acl = new \Espo\Core\Acl($user);
|
||||
$acl = new \Espo\Core\Acl($user, $this->getConfig(), $this->getContainer()->get('fileManager'), $this->getMetadata());
|
||||
|
||||
return $acl->toArray();
|
||||
}
|
||||
|
||||
@@ -24,6 +24,8 @@ namespace Espo\Core;
|
||||
|
||||
use \Espo\Core\Exceptions\Error;
|
||||
|
||||
use \Espo\ORM\Entity;
|
||||
|
||||
class Acl
|
||||
{
|
||||
private $data = array();
|
||||
@@ -34,11 +36,15 @@ class Acl
|
||||
|
||||
private $levelList = array('all', 'team', 'own', 'no');
|
||||
|
||||
private $fileManager;
|
||||
protected $fileManager;
|
||||
|
||||
protected $metadata;
|
||||
|
||||
public function __construct(\Espo\Entities\User $user, $config = null, $fileManager = null)
|
||||
public function __construct(\Espo\Entities\User $user, $config = null, $fileManager = null, $metadata = null)
|
||||
{
|
||||
$this->user = $user;
|
||||
$this->user = $user;
|
||||
|
||||
$this->metadata = $metadata;
|
||||
|
||||
if (!$this->user->isFetched()) {
|
||||
throw new Error();
|
||||
@@ -66,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) {
|
||||
@@ -96,6 +102,9 @@ class Acl
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if ($inTeam === null && $entity) {
|
||||
$inTeam = $this->checkInTeam($entity);
|
||||
}
|
||||
|
||||
if ($inTeam) {
|
||||
if ($value === 'team') {
|
||||
@@ -125,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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -164,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)) {
|
||||
@@ -197,32 +221,11 @@ class Acl
|
||||
|
||||
private function initSolid()
|
||||
{
|
||||
$this->data['User'] = array(
|
||||
'read' => 'all',
|
||||
'edit' => 'no',
|
||||
'delete' => 'no',
|
||||
);
|
||||
$this->data['Team'] = array(
|
||||
'read' => 'all',
|
||||
'edit' => 'no',
|
||||
'delete' => 'no',
|
||||
);
|
||||
$this->data['Role'] = false;
|
||||
$this->data['Note'] = array(
|
||||
'read' => 'own',
|
||||
'edit' => 'own',
|
||||
'delete' => 'own',
|
||||
);
|
||||
$this->data['EmailAddress'] = array(
|
||||
'read' => 'no',
|
||||
'edit' => 'no',
|
||||
'delete' => 'no',
|
||||
);
|
||||
$this->data['Note'] = array(
|
||||
'read' => 'all',
|
||||
'edit' => 'own',
|
||||
'delete' => 'own',
|
||||
);
|
||||
$data = $this->metadata->get('app.acl.solid', array());
|
||||
|
||||
foreach ($data as $entityName => $item) {
|
||||
$this->data[$entityName] = $item;
|
||||
}
|
||||
}
|
||||
|
||||
private function merge($tables)
|
||||
|
||||
@@ -51,7 +51,6 @@ class Container
|
||||
$obj = $this->$loadMethod();
|
||||
$this->data[$name] = $obj;
|
||||
} else {
|
||||
//external loader class \Espo\Core\Loaders\<className> or \Espo\Custom\Core\Loaders\<className> with load() method
|
||||
$className = '\Espo\Custom\Core\Loaders\\'.ucfirst($name);
|
||||
if (!class_exists($className)) {
|
||||
$className = '\Espo\Core\Loaders\\'.ucfirst($name);
|
||||
@@ -63,13 +62,18 @@ class Container
|
||||
}
|
||||
}
|
||||
|
||||
// TODO throw an exception
|
||||
return null;
|
||||
}
|
||||
|
||||
protected function getServiceClassName($name, $default)
|
||||
{
|
||||
$metadata = $this->get('metadata');
|
||||
$className = $metadata->get('app.serviceContainer.classNames.' . $name, $default);
|
||||
return $className;
|
||||
}
|
||||
|
||||
private function loadSlim()
|
||||
{
|
||||
//return new \Slim\Slim();
|
||||
return new \Espo\Core\Utils\Api\Slim();
|
||||
}
|
||||
|
||||
@@ -108,7 +112,8 @@ class Container
|
||||
|
||||
private function loadMailSender()
|
||||
{
|
||||
return new \Espo\Core\Mail\Sender(
|
||||
$className = $this->getServiceClassName('mailSernder', '\\Espo\\Core\\Mail\\Sender');
|
||||
return new $className(
|
||||
$this->get('config')
|
||||
);
|
||||
}
|
||||
@@ -157,10 +162,12 @@ class Container
|
||||
|
||||
private function loadAcl()
|
||||
{
|
||||
return new \Espo\Core\Acl(
|
||||
$className = $this->getServiceClassName('acl', '\\Espo\\Core\\Acl');
|
||||
return new $className(
|
||||
$this->get('user'),
|
||||
$this->get('config'),
|
||||
$this->get('fileManager')
|
||||
$this->get('fileManager'),
|
||||
$this->get('metadata')
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -78,7 +78,7 @@ class ControllerManager
|
||||
throw new NotFound("Controller '$controllerName' is not found");
|
||||
}
|
||||
|
||||
$controller = new $controllerClassName($this->container);
|
||||
$controller = new $controllerClassName($this->container, $request->getMethod());
|
||||
|
||||
if ($actionName == 'index') {
|
||||
$actionName = $controllerClassName::$defaultAction;
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
*
|
||||
* 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\Controllers;
|
||||
|
||||
@@ -29,15 +29,21 @@ use \Espo\Core\Utils\Util;
|
||||
abstract class Base
|
||||
{
|
||||
protected $name;
|
||||
|
||||
|
||||
private $container;
|
||||
|
||||
|
||||
private $requestMethod;
|
||||
|
||||
public static $defaultAction = 'index';
|
||||
|
||||
public function __construct(Container $container)
|
||||
public function __construct(Container $container, $requestMethod = null)
|
||||
{
|
||||
$this->container = $container;
|
||||
|
||||
|
||||
if (isset($requestMethod)) {
|
||||
$this->setRequestMethod($requestMethod);
|
||||
}
|
||||
|
||||
if (empty($this->name)) {
|
||||
$name = get_class($this);
|
||||
if (preg_match('@\\\\([\w]+)$@', $name, $matches)) {
|
||||
@@ -45,40 +51,55 @@ abstract class Base
|
||||
}
|
||||
$this->name = $name;
|
||||
}
|
||||
|
||||
|
||||
$this->checkControllerAccess();
|
||||
}
|
||||
|
||||
|
||||
protected function checkControllerAccess()
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
protected function getContainer()
|
||||
{
|
||||
return $this->container;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get request method name (Uppercase)
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getRequestMethod()
|
||||
{
|
||||
return $this->requestMethod;
|
||||
}
|
||||
|
||||
protected function setRequestMethod($requestMethod)
|
||||
{
|
||||
$this->requestMethod = strtoupper($requestMethod);
|
||||
}
|
||||
|
||||
protected function getUser()
|
||||
{
|
||||
return $this->container->get('user');
|
||||
}
|
||||
|
||||
|
||||
protected function getAcl()
|
||||
{
|
||||
return $this->container->get('acl');
|
||||
}
|
||||
|
||||
|
||||
protected function getConfig()
|
||||
{
|
||||
return $this->container->get('config');
|
||||
}
|
||||
|
||||
|
||||
protected function getPreferences()
|
||||
{
|
||||
return $this->container->get('preferences');
|
||||
}
|
||||
|
||||
|
||||
protected function getMetadata()
|
||||
{
|
||||
return $this->container->get('metadata');
|
||||
@@ -88,7 +109,7 @@ abstract class Base
|
||||
{
|
||||
return $this->container->get('serviceFactory');
|
||||
}
|
||||
|
||||
|
||||
protected function getService($name)
|
||||
{
|
||||
return $this->getServiceFactory()->create($name);
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
*
|
||||
* 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\Cron;
|
||||
|
||||
@@ -46,22 +46,22 @@ class Service
|
||||
$serviceName = $job['service_name'];
|
||||
|
||||
if (!$this->getServiceFactory()->checkExists($serviceName)) {
|
||||
throw new NotFound();
|
||||
throw new NotFound();
|
||||
}
|
||||
|
||||
$service = $this->getServiceFactory()->create($serviceName);
|
||||
$serviceMethod = $job['method'];
|
||||
$service = $this->getServiceFactory()->create($serviceName);
|
||||
$serviceMethod = $job['method'];
|
||||
|
||||
if (!method_exists($service, $serviceMethod)) {
|
||||
throw new NotFound();
|
||||
}
|
||||
throw new NotFound();
|
||||
}
|
||||
|
||||
$data = $job['data'];
|
||||
if (Json::isJSON($data)) {
|
||||
$data = Json::decode($data, true);
|
||||
}
|
||||
|
||||
$service->$serviceMethod($data);
|
||||
$service->$serviceMethod($data);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -34,6 +34,11 @@ class CronManager
|
||||
private $jobService;
|
||||
private $scheduledJobService;
|
||||
|
||||
const PENDING = 'Pending';
|
||||
const RUNNING = 'Running';
|
||||
const SUCCESS = 'Success';
|
||||
const FAILED = 'Failed';
|
||||
|
||||
protected $lastRunTime = 'data/cache/application/cronLastRunTime.php';
|
||||
|
||||
|
||||
@@ -128,13 +133,12 @@ class CronManager
|
||||
//Check scheduled jobs and create related jobs
|
||||
$this->createJobsFromScheduledJobs();
|
||||
|
||||
|
||||
$pendingJobs = $this->getJobService()->getPendingJobs();
|
||||
|
||||
foreach ($pendingJobs as $job) {
|
||||
|
||||
$this->getJobService()->updateEntity($job['id'], array(
|
||||
'status' => 'Running',
|
||||
'status' => self::RUNNING,
|
||||
));
|
||||
|
||||
$isSuccess = true;
|
||||
@@ -150,7 +154,7 @@ class CronManager
|
||||
$GLOBALS['log']->error('Failed job running, job ['.$job['id'].']. Error Details: '.$e->getMessage());
|
||||
}
|
||||
|
||||
$status = $isSuccess ? 'Success' : 'Failed';
|
||||
$status = $isSuccess ? self::SUCCESS : self::FAILED;
|
||||
|
||||
$this->getJobService()->updateEntity($job['id'], array(
|
||||
'status' => $status,
|
||||
@@ -180,7 +184,6 @@ class CronManager
|
||||
$cronExpression = \Cron\CronExpression::factory($scheduling);
|
||||
|
||||
try {
|
||||
//$nextDate = $cronExpression->getNextRunDate()->format('Y-m-d H:i:s');
|
||||
$prevDate = $cronExpression->getPreviousRunDate()->format('Y-m-d H:i:s');
|
||||
} catch (\Exception $e) {
|
||||
$GLOBALS['log']->error('ScheduledJob ['.$scheduledJob['id'].']: CronExpression - Impossible CRON expression ['.$scheduling.']');
|
||||
@@ -197,7 +200,7 @@ class CronManager
|
||||
//create a job
|
||||
$data = array(
|
||||
'name' => $scheduledJob['name'],
|
||||
'status' => 'Pending',
|
||||
'status' => self::PENDING,
|
||||
'scheduledJobId' => $scheduledJob['id'],
|
||||
'executeTime' => $prevDate,
|
||||
'method' => $scheduledJob['job'],
|
||||
|
||||
@@ -121,8 +121,9 @@ class DataManager
|
||||
*/
|
||||
public function updateCacheTimestamp()
|
||||
{
|
||||
return $this->getContainer()->get('config')->updateCacheTimestamp();
|
||||
$this->getContainer()->get('config')->updateCacheTimestamp();
|
||||
$this->getContainer()->get('config')->save();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
41
application/Espo/Core/ExtensionManager.php
Normal file
41
application/Espo/Core/ExtensionManager.php
Normal file
@@ -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',
|
||||
)
|
||||
);
|
||||
}
|
||||
125
application/Espo/Core/ExternalAccount/ClientManager.php
Normal file
125
application/Espo/Core/ExternalAccount/ClientManager.php
Normal file
@@ -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,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
34
application/Espo/Core/ExternalAccount/Clients/Google.php
Normal file
34
application/Espo/Core/ExternalAccount/Clients/Google.php
Normal file
@@ -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';
|
||||
}
|
||||
}
|
||||
|
||||
35
application/Espo/Core/ExternalAccount/Clients/IClient.php
Normal file
35
application/Espo/Core/ExternalAccount/Clients/IClient.php
Normal file
@@ -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();
|
||||
}
|
||||
|
||||
209
application/Espo/Core/ExternalAccount/Clients/OAuth2Abstract.php
Normal file
209
application/Espo/Core/ExternalAccount/Clients/OAuth2Abstract.php
Normal file
@@ -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'
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
248
application/Espo/Core/ExternalAccount/OAuth2/Client.php
Normal file
248
application/Espo/Core/ExternalAccount/OAuth2/Client.php
Normal file
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ namespace Espo\Core\Loaders;
|
||||
use Doctrine\ORM\Tools\Setup,
|
||||
Espo\Core\Doctrine\ORM\Mapping\Driver\EspoPHPDriver;
|
||||
|
||||
class EntityManager
|
||||
class EntityManager implements Loader
|
||||
{
|
||||
private $container;
|
||||
|
||||
|
||||
31
application/Espo/Core/Loaders/Loader.php
Normal file
31
application/Espo/Core/Loaders/Loader.php
Normal file
@@ -0,0 +1,31 @@
|
||||
<?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\Loaders;
|
||||
|
||||
|
||||
interface Loader
|
||||
{
|
||||
public function load();
|
||||
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ namespace Espo\Core\Loaders;
|
||||
use Espo\Core\Utils,
|
||||
Espo\Core\Utils\Log\Monolog\Handler;
|
||||
|
||||
class Log
|
||||
class Log implements Loader
|
||||
{
|
||||
private $container;
|
||||
|
||||
|
||||
244
application/Espo/Core/Mail/Importer.php
Normal file
244
application/Espo/Core/Mail/Importer.php
Normal file
@@ -0,0 +1,244 @@
|
||||
<?php
|
||||
|
||||
namespace Espo\Core\Mail;
|
||||
|
||||
use \Zend\Mime\Mime as Mime;
|
||||
|
||||
class Importer
|
||||
{
|
||||
private $entityManager;
|
||||
|
||||
private $fileManager;
|
||||
|
||||
public function __construct($entityManager, $fileManager)
|
||||
{
|
||||
$this->entityManager = $entityManager;
|
||||
$this->fileManager = $fileManager;
|
||||
}
|
||||
|
||||
protected function getEntityManager()
|
||||
{
|
||||
return $this->entityManager;
|
||||
}
|
||||
|
||||
protected function getFileManager()
|
||||
{
|
||||
return $this->fileManager;
|
||||
}
|
||||
|
||||
public function importMessage($message, $userId, $teamsIds = array())
|
||||
{
|
||||
try {
|
||||
$email = $this->getEntityManager()->getEntity('Email');
|
||||
|
||||
$email->set('isHtml', false);
|
||||
$email->set('name', $message->subject);
|
||||
$email->set('status', 'Archived');
|
||||
$email->set('attachmentsIds', array());
|
||||
$email->set('assignedUserId', $userId);
|
||||
$email->set('teamsIds', $teamsIds);
|
||||
|
||||
$fromArr = $this->getAddressListFromMessage($message, 'from');
|
||||
if (isset($message->from)) {
|
||||
$email->set('fromName', $message->from);
|
||||
}
|
||||
$email->set('from', $fromArr[0]);
|
||||
$email->set('to', implode(';', $this->getAddressListFromMessage($message, 'to')));
|
||||
$email->set('cc', implode(';', $this->getAddressListFromMessage($message, 'cc')));
|
||||
|
||||
if (isset($message->messageId) && !empty($message->messageId)) {
|
||||
$email->set('messageId', $message->messageId);
|
||||
if (isset($message->deliveredTo)) {
|
||||
$email->set('messageIdInternal', $message->messageId . '-' . $message->deliveredTo);
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->checkIsDuplicate($email)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (isset($message->date)) {
|
||||
$dt = new \DateTime($message->date);
|
||||
if ($dt) {
|
||||
$dateSent = $dt->setTimezone(new \DateTimeZone('UTC'))->format('Y-m-d H:i:s');
|
||||
$email->set('dateSent', $dateSent);
|
||||
}
|
||||
}
|
||||
if (isset($message->deliveryDate)) {
|
||||
$dt = new \DateTime($message->deliveryDate);
|
||||
if ($dt) {
|
||||
$deliveryDate = $dt->setTimezone(new \DateTimeZone('UTC'))->format('Y-m-d H:i:s');
|
||||
$email->set('deliveryDate', $deliveryDate);
|
||||
}
|
||||
}
|
||||
|
||||
$inlineIds = array();
|
||||
|
||||
if ($message->isMultipart()) {
|
||||
foreach (new \RecursiveIteratorIterator($message) as $part) {
|
||||
$this->importPartDataToEmail($email, $part, $inlineIds);
|
||||
}
|
||||
} else {
|
||||
$this->importPartDataToEmail($email, $message, $inlineIds);
|
||||
}
|
||||
|
||||
$body = $email->get('body');
|
||||
if (!empty($body)) {
|
||||
foreach ($inlineIds as $cid => $attachmentId) {
|
||||
$body = str_replace('cid:' . $cid, '?entryPoint=attachment&id=' . $attachmentId, $body);
|
||||
}
|
||||
$email->set('body', $body);
|
||||
}
|
||||
|
||||
$this->getEntityManager()->saveEntity($email);
|
||||
|
||||
return $email;
|
||||
|
||||
} catch (\Exception $e) {}
|
||||
}
|
||||
|
||||
protected function checkIsDuplicate($email)
|
||||
{
|
||||
if ($email->get('messageIdInternal')) {
|
||||
$duplicate = $this->getEntityManager()->getRepository('Email')->where(array(
|
||||
'messageIdInternal' => $email->get('messageIdInternal')
|
||||
))->findOne();
|
||||
if ($duplicate) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected function getAddressListFromMessage($message, $type)
|
||||
{
|
||||
$addressList = array();
|
||||
if (isset($message->$type)) {
|
||||
|
||||
$list = $message->getHeader($type)->getAddressList();
|
||||
foreach ($list as $address) {
|
||||
$addressList[] = $address->getEmail();
|
||||
}
|
||||
}
|
||||
return $addressList;
|
||||
}
|
||||
|
||||
protected function importPartDataToEmail(\Espo\Entities\Email $email, $part, &$inlineIds = array())
|
||||
{
|
||||
try {
|
||||
$type = strtok($part->contentType, ';');
|
||||
$encoding = null;
|
||||
|
||||
switch ($type) {
|
||||
case 'text/plain':
|
||||
$content = $this->getContentFromPart($part);
|
||||
if (!$email->get('body')) {
|
||||
$email->set('body', $content);
|
||||
}
|
||||
$email->set('bodyPlain', $content);
|
||||
break;
|
||||
case 'text/html':
|
||||
$content = $this->getContentFromPart($part);
|
||||
$email->set('body', $content);
|
||||
$email->set('isHtml', true);
|
||||
break;
|
||||
default:
|
||||
$content = $part->getContent();
|
||||
$disposition = null;
|
||||
|
||||
$fileName = null;
|
||||
$contentId = null;
|
||||
|
||||
if (isset($part->ContentDisposition)) {
|
||||
if (strpos($part->ContentDisposition, 'attachment') === 0) {
|
||||
if (preg_match('/filename="?([^"]+)"?/i', $part->ContentDisposition, $m)) {
|
||||
$fileName = $m[1];
|
||||
$disposition = 'attachment';
|
||||
}
|
||||
} else if (strpos($part->ContentDisposition, 'inline') === 0) {
|
||||
$contentId = trim($part->contentID, '<>');
|
||||
$fileName = $contentId;
|
||||
$disposition = 'inline';
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($part->contentTransferEncoding)) {
|
||||
$encoding = strtolower($part->getHeader('Content-Transfer-Encoding')->getTransferEncoding());
|
||||
}
|
||||
|
||||
$attachment = $this->getEntityManager()->getEntity('Attachment');
|
||||
$attachment->set('name', $fileName);
|
||||
$attachment->set('type', $type);
|
||||
|
||||
if ($disposition == 'inline') {
|
||||
$attachment->set('role', 'Inline Attachment');
|
||||
} else {
|
||||
$attachment->set('role', 'Attachment');
|
||||
}
|
||||
|
||||
if ($encoding == 'base64') {
|
||||
$content = base64_decode($content);
|
||||
}
|
||||
|
||||
$attachment->set('size', strlen($content));
|
||||
|
||||
$this->getEntityManager()->saveEntity($attachment);
|
||||
|
||||
$path = 'data/upload/' . $attachment->id;
|
||||
$this->getFileManager()->putContents($path, $content);
|
||||
|
||||
if ($disposition == 'attachment') {
|
||||
$attachmentsIds = $email->get('attachmentsIds');
|
||||
$attachmentsIds[] = $attachment->id;
|
||||
$email->set('attachmentsIds', $attachmentsIds);
|
||||
} else if ($disposition == 'inline') {
|
||||
$inlineIds[$contentId] = $attachment->id;
|
||||
}
|
||||
}
|
||||
} catch (\Exception $e) {}
|
||||
}
|
||||
|
||||
protected function getContentFromPart($part)
|
||||
{
|
||||
if ($part instanceof \Zend\Mime\Part) {
|
||||
$content = $part->getRawContent();
|
||||
if (strtolower($part->charset) != 'utf-8') {
|
||||
$content = mb_convert_encoding($content, 'UTF-8', $part->charset);
|
||||
}
|
||||
} else {
|
||||
$content = $part->getContent();
|
||||
|
||||
$encoding = null;
|
||||
|
||||
if (isset($part->contentTransferEncoding)) {
|
||||
$cteHeader = $part->getHeader('Content-Transfer-Encoding');
|
||||
$encoding = strtolower($cteHeader->getTransferEncoding());
|
||||
}
|
||||
|
||||
if ($encoding == 'base64') {
|
||||
$content = base64_decode($content);
|
||||
}
|
||||
|
||||
$charset = 'UTF-8';
|
||||
|
||||
if (isset($part->contentType)) {
|
||||
$ctHeader = $part->getHeader('Content-Type');
|
||||
$charsetParamValue = $ctHeader->getParameter('charset');
|
||||
if (!empty($charsetParamValue)) {
|
||||
$charset = strtoupper($charsetParamValue);
|
||||
}
|
||||
}
|
||||
|
||||
if ($charset !== 'UTF-8') {
|
||||
$content = mb_convert_encoding($content, 'UTF-8', $charset);
|
||||
}
|
||||
|
||||
if (isset($part->contentTransferEncoding)) {
|
||||
$cteHeader = $part->getHeader('Content-Transfer-Encoding');
|
||||
if ($cteHeader->getTransferEncoding() == 'quoted-printable') {
|
||||
$content = quoted_printable_decode($content);
|
||||
}
|
||||
}
|
||||
}
|
||||
return $content;
|
||||
}
|
||||
}
|
||||
@@ -124,23 +124,25 @@ class Sender
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function send(Email $email)
|
||||
public function send(Email $email, $params = array())
|
||||
{
|
||||
$message = new Message();
|
||||
|
||||
$config = $this->config;
|
||||
|
||||
$params = $this->params + $params;
|
||||
|
||||
if ($email->get('from')) {
|
||||
$fromName = null;
|
||||
if (!empty($this->params['fromName'])) {
|
||||
$fromName = $this->params['fromName'];
|
||||
if (!empty($params['fromName'])) {
|
||||
$fromName = $params['fromName'];
|
||||
} else {
|
||||
$fromName = $config->get('outboundEmailFromName');
|
||||
}
|
||||
$message->addFrom(trim($email->get('from')), $fromName);
|
||||
} else {
|
||||
if (!empty($this->params['fromAddress'])) {
|
||||
$fromAddress = $this->params['fromAddress'];
|
||||
if (!empty($params['fromAddress'])) {
|
||||
$fromAddress = $params['fromAddress'];
|
||||
} else {
|
||||
if (!$config->get('outboundEmailFromAddress')) {
|
||||
throw new Error('outboundEmailFromAddress is not specified in config.');
|
||||
@@ -148,14 +150,22 @@ class Sender
|
||||
$fromAddress = $config->get('outboundEmailFromAddress');
|
||||
}
|
||||
|
||||
if (!empty($this->params['fromName'])) {
|
||||
$fromName = $this->params['fromName'];
|
||||
if (!empty($params['fromName'])) {
|
||||
$fromName = $params['fromName'];
|
||||
} else {
|
||||
$fromName = $config->get('outboundEmailFromName');
|
||||
}
|
||||
|
||||
$message->addFrom($fromAddress, $fromName);
|
||||
}
|
||||
|
||||
if (!empty($params['replyToAddress'])) {
|
||||
$replyToName = null;
|
||||
if (!empty($params['replyToName'])) {
|
||||
$replyToName = $params['replyToName'];
|
||||
}
|
||||
$message->setReplyTo($params['replyToAddress'], $replyToName);
|
||||
}
|
||||
|
||||
$value = $email->get('to');
|
||||
if ($value) {
|
||||
@@ -191,23 +201,21 @@ class Sender
|
||||
|
||||
$body = new MimeMessage;
|
||||
$parts = array();
|
||||
|
||||
|
||||
|
||||
$bodyPart = new MimePart($email->getBodyPlainForSending());
|
||||
$bodyPart->type = 'text/plain';
|
||||
$bodyPart->charset = 'utf-8';
|
||||
$parts[] = $bodyPart;
|
||||
|
||||
|
||||
if ($email->get('isHtml')) {
|
||||
$bodyPart = new MimePart($email->getBodyForSending());
|
||||
$bodyPart->type = 'text/html';
|
||||
$bodyPart->charset = 'utf-8';
|
||||
} else {
|
||||
if ($email->get('bodyPlain')) {
|
||||
$bodyPart = new MimePart($email->get('bodyPlain'));
|
||||
} else {
|
||||
$bodyPart = new MimePart($email->get('body'));
|
||||
}
|
||||
$bodyPart->type = 'text/plain';
|
||||
$bodyPart->charset = 'utf-8';
|
||||
$parts[] = $bodyPart;
|
||||
}
|
||||
|
||||
$parts[] = $bodyPart;
|
||||
|
||||
|
||||
$aCollection = $email->get('attachments');
|
||||
if (!empty($aCollection)) {
|
||||
@@ -241,9 +249,19 @@ class Sender
|
||||
|
||||
$body->setParts($parts);
|
||||
$message->setBody($body);
|
||||
|
||||
if ($email->get('isHtml')) {
|
||||
$message->getHeaders()->get('content-type')->setType('multipart/alternative');
|
||||
}
|
||||
|
||||
try {
|
||||
$this->transport->send($message);
|
||||
|
||||
$headers = $message->getHeaders();
|
||||
if ($headers->has('messageId')) {
|
||||
$email->set('messageId', $headers->get('messageId')->getId());
|
||||
}
|
||||
|
||||
$email->set('status', 'Sent');
|
||||
$email->set('dateSent', date("Y-m-d H:i:s"));
|
||||
} catch (\Exception $e) {
|
||||
|
||||
19
application/Espo/Core/Mail/Storage/Imap.php
Normal file
19
application/Espo/Core/Mail/Storage/Imap.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace Espo\Core\Mail\Storage;
|
||||
|
||||
class Imap extends \Zend\Mail\Storage\Imap
|
||||
{
|
||||
public function getIdsFromUID($uid)
|
||||
{
|
||||
$uid = intval($uid) + 1;
|
||||
return $this->protocol->search(array('UID ' . $uid . ':*'));
|
||||
}
|
||||
|
||||
public function getIdsFromDate($date)
|
||||
{
|
||||
return $this->protocol->search(array('SINCE "' . $date . '"'));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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'])) {
|
||||
|
||||
@@ -40,6 +40,8 @@ class Base
|
||||
|
||||
protected $metadata;
|
||||
|
||||
const MIN_LENGTH_FOR_CONTENT_SEARCH = 4;
|
||||
|
||||
public function __construct($entityManager, \Espo\Entities\User $user, Acl $acl, $metadata)
|
||||
{
|
||||
$this->entityManager = $entityManager;
|
||||
@@ -82,7 +84,7 @@ class Base
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected function getTextFilterFields()
|
||||
{
|
||||
return $this->metadata->get("entityDefs.{$this->entityName}.collection.textFilterFields", array('name'));
|
||||
@@ -106,12 +108,21 @@ class Base
|
||||
if (empty($result['whereClause'])) {
|
||||
$result['whereClause'] = array();
|
||||
}
|
||||
$fieldDefs = $this->entityManager->getEntity($this->entityName)->getFields();
|
||||
$fieldList = $this->getTextFilterFields();
|
||||
$d = array();
|
||||
foreach ($fieldList as $field) {
|
||||
$d[$field . '*'] = $item['value'] . '%';
|
||||
if (
|
||||
strlen($item['value']) >= self::MIN_LENGTH_FOR_CONTENT_SEARCH
|
||||
&&
|
||||
!empty($fieldDefs[$field]['type']) && $fieldDefs[$field]['type'] == 'text'
|
||||
) {
|
||||
$d[$field . '*'] = '%' . $item['value'] . '%';
|
||||
} else {
|
||||
$d[$field . '*'] = $item['value'] . '%';
|
||||
}
|
||||
}
|
||||
$where['OR'] = $d;
|
||||
$where['OR'] = $d;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -163,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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -286,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',
|
||||
)
|
||||
);
|
||||
|
||||
}
|
||||
102
application/Espo/Core/Upgrades/ActionManager.php
Normal file
102
application/Espo/Core/Upgrades/ActionManager.php
Normal file
@@ -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];
|
||||
}
|
||||
}
|
||||
488
application/Espo/Core/Upgrades/Actions/Base.php
Normal file
488
application/Espo/Core/Upgrades/Actions/Base.php
Normal file
@@ -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()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
55
application/Espo/Core/Upgrades/Actions/Base/Delete.php
Normal file
55
application/Espo/Core/Upgrades/Actions/Base/Delete.php
Normal file
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
112
application/Espo/Core/Upgrades/Actions/Base/Install.php
Normal file
112
application/Espo/Core/Upgrades/Actions/Base/Install.php
Normal file
@@ -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);
|
||||
}
|
||||
}
|
||||
132
application/Espo/Core/Upgrades/Actions/Base/Uninstall.php
Normal file
132
application/Espo/Core/Upgrades/Actions/Base/Uninstall.php
Normal file
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
62
application/Espo/Core/Upgrades/Actions/Base/Upload.php
Normal file
62
application/Espo/Core/Upgrades/Actions/Base/Upload.php
Normal file
@@ -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;
|
||||
}
|
||||
}
|
||||
69
application/Espo/Core/Upgrades/Actions/Extension/Delete.php
Normal file
69
application/Espo/Core/Upgrades/Actions/Extension/Delete.php
Normal file
@@ -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);
|
||||
}
|
||||
}
|
||||
229
application/Espo/Core/Upgrades/Actions/Extension/Install.php
Normal file
229
application/Espo/Core/Upgrades/Actions/Extension/Install.php
Normal file
@@ -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);
|
||||
}
|
||||
}
|
||||
28
application/Espo/Core/Upgrades/Actions/Extension/Upload.php
Normal file
28
application/Espo/Core/Upgrades/Actions/Extension/Upload.php
Normal file
@@ -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
|
||||
{
|
||||
|
||||
}
|
||||
52
application/Espo/Core/Upgrades/Actions/Upgrade/Install.php
Normal file
52
application/Espo/Core/Upgrades/Actions/Upgrade/Install.php
Normal file
@@ -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;
|
||||
}
|
||||
}
|
||||
28
application/Espo/Core/Upgrades/Actions/Upgrade/Upload.php
Normal file
28
application/Espo/Core/Upgrades/Actions/Upgrade/Upload.php
Normal file
@@ -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 uprgade 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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,11 +51,12 @@ class Auth
|
||||
$entityManager = $this->container->get('entityManager');
|
||||
|
||||
$user = $entityManager->getRepository('User')->get('system');
|
||||
$user->set('isAdmin', $isAdmin);
|
||||
if (!$user) {
|
||||
throw new Error('System user is not found');
|
||||
}
|
||||
|
||||
$user->set('isAdmin', $isAdmin);
|
||||
|
||||
$entityManager->setUser($user);
|
||||
$this->container->setUser($user);
|
||||
}
|
||||
|
||||
@@ -56,6 +56,7 @@ class Config
|
||||
private $data;
|
||||
|
||||
private $changedData = array();
|
||||
private $removeData = array();
|
||||
|
||||
private $fileManager;
|
||||
|
||||
@@ -112,11 +113,33 @@ class Config
|
||||
}
|
||||
|
||||
foreach ($name as $key => $value) {
|
||||
|
||||
if (is_object($value)) {
|
||||
$value = (array) $value;
|
||||
}
|
||||
|
||||
$this->data[$key] = $value;
|
||||
$this->changedData[$key] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove an option in config
|
||||
*
|
||||
* @param string $name
|
||||
* @return bool | null - null if an option doesn't exist
|
||||
*/
|
||||
public function remove($name)
|
||||
{
|
||||
if (array_key_exists($name, $this->data)) {
|
||||
unset($this->data[$name]);
|
||||
$this->removeData[] = $name;
|
||||
return true;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public function save()
|
||||
{
|
||||
$values = $this->changedData;
|
||||
@@ -125,9 +148,12 @@ class Config
|
||||
$values = array_merge($this->updateCacheTimestamp(true), $values);
|
||||
}
|
||||
|
||||
$result = $this->getFileManager()->mergeContentsPHP($this->configPath, $values, true);
|
||||
$removeData = empty($this->removeData) ? null : $this->removeData;
|
||||
|
||||
$result = $this->getFileManager()->mergeContentsPHP($this->configPath, $values, $removeData);
|
||||
if ($result) {
|
||||
$this->changedData = array();
|
||||
$this->removeData = array();
|
||||
$this->loadConfig(true);
|
||||
}
|
||||
|
||||
|
||||
@@ -18,15 +18,13 @@
|
||||
*
|
||||
* 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;
|
||||
|
||||
use Doctrine\DBAL\Types\Type;
|
||||
use Doctrine\DBAL\Platforms\AbstractPlatform;
|
||||
use Doctrine\DBAL\Types\BooleanType;
|
||||
|
||||
|
||||
class Bool extends Type
|
||||
class Bool extends BooleanType
|
||||
{
|
||||
const BOOL = 'bool';
|
||||
|
||||
@@ -39,27 +37,4 @@ class Bool extends Type
|
||||
{
|
||||
return 'TINYINT';
|
||||
}
|
||||
|
||||
|
||||
public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform)
|
||||
{
|
||||
return $platform->getBooleanTypeDeclarationSQL($fieldDeclaration);
|
||||
}
|
||||
|
||||
|
||||
public function convertToDatabaseValue($value, AbstractPlatform $platform)
|
||||
{
|
||||
return $platform->convertBooleans($value);
|
||||
}
|
||||
|
||||
|
||||
public function convertToPHPValue($value, AbstractPlatform $platform)
|
||||
{
|
||||
return (null === $value) ? null : (bool) $value;
|
||||
}
|
||||
|
||||
public function getBindingType()
|
||||
{
|
||||
return \PDO::PARAM_BOOL;
|
||||
}
|
||||
}
|
||||
@@ -18,38 +18,18 @@
|
||||
*
|
||||
* 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;
|
||||
|
||||
use Doctrine\DBAL\Types\Type;
|
||||
use Doctrine\DBAL\Platforms\AbstractPlatform;
|
||||
use Doctrine\DBAL\Types\IntegerType;
|
||||
|
||||
|
||||
class Int extends Type
|
||||
class Int extends IntegerType
|
||||
{
|
||||
const INTtype = 'int';
|
||||
|
||||
|
||||
public function getName()
|
||||
{
|
||||
return self::INTtype;
|
||||
}
|
||||
|
||||
public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform)
|
||||
{
|
||||
return $platform->getIntegerTypeDeclarationSQL($fieldDeclaration);
|
||||
}
|
||||
|
||||
|
||||
public function convertToPHPValue($value, AbstractPlatform $platform)
|
||||
{
|
||||
return (null === $value) ? null : (int) $value;
|
||||
}
|
||||
|
||||
|
||||
public function getBindingType()
|
||||
{
|
||||
return \PDO::PARAM_INT;
|
||||
}
|
||||
}
|
||||
@@ -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';
|
||||
}
|
||||
|
||||
}
|
||||
@@ -18,14 +18,13 @@
|
||||
*
|
||||
* 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;
|
||||
|
||||
use Doctrine\DBAL\Types\Type;
|
||||
use Doctrine\DBAL\Platforms\AbstractPlatform;
|
||||
use Doctrine\DBAL\Types\StringType;
|
||||
|
||||
class Password extends Type
|
||||
class Password extends StringType
|
||||
{
|
||||
const PASSWORD = 'password';
|
||||
|
||||
@@ -38,23 +37,5 @@ class Password extends Type
|
||||
{
|
||||
return 'VARCHAR';
|
||||
}
|
||||
|
||||
public function getSqlDeclaration(array $fieldDeclaration, AbstractPlatform $platform)
|
||||
{
|
||||
return $platform->getVarcharTypeDeclarationSQL($fieldDeclaration);
|
||||
//return "MD5";
|
||||
}
|
||||
|
||||
/*public function convertToPHPValue($value, AbstractPlatform $platform)
|
||||
{
|
||||
return $value;
|
||||
}
|
||||
|
||||
public function convertToDatabaseValue($value, AbstractPlatform $platform)
|
||||
{
|
||||
return $value;
|
||||
} */
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -18,15 +18,13 @@
|
||||
*
|
||||
* 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;
|
||||
|
||||
use Doctrine\DBAL\Types\Type;
|
||||
use Doctrine\DBAL\Platforms\AbstractPlatform;
|
||||
use Doctrine\DBAL\Types\StringType;
|
||||
|
||||
|
||||
class Varchar extends Type
|
||||
class Varchar extends StringType
|
||||
{
|
||||
const VARCHAR = 'varchar';
|
||||
|
||||
@@ -34,16 +32,4 @@ class Varchar extends Type
|
||||
{
|
||||
return self::VARCHAR;
|
||||
}
|
||||
|
||||
public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform)
|
||||
{
|
||||
return $platform->getVarcharTypeDeclarationSQL($fieldDeclaration);
|
||||
//return 'varchar';
|
||||
}
|
||||
|
||||
|
||||
public function getDefaultLength(AbstractPlatform $platform)
|
||||
{
|
||||
return $platform->getVarcharDefaultLength();
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -244,17 +244,8 @@ class Base
|
||||
$foreignField = $this->getMetadata()->get('entityDefs.'.$entityName.'.fields.'.$name);
|
||||
|
||||
if ($foreignField['type'] != 'varchar') {
|
||||
$fieldDefs = $this->getMetadata()->get('fields.'.$foreignField['type']);
|
||||
$naming = isset($fieldDefs['naming']) ? $fieldDefs['naming'] : 'postfix';
|
||||
|
||||
if (isset($fieldDefs['actualFields']) && is_array($fieldDefs['actualFields'])) {
|
||||
$foreignFieldArray = array();
|
||||
foreach($fieldDefs['actualFields'] as $fieldName) {
|
||||
if ($fieldName != 'salutation') {
|
||||
$foreignFieldArray[] = Util::getNaming($name, $fieldName, $naming);
|
||||
}
|
||||
}
|
||||
return explode('|', implode('| |', $foreignFieldArray)); //add an empty string between items
|
||||
if ($foreignField['type'] == 'personName') {
|
||||
return array('first' . ucfirst($name), ' ', 'last' . ucfirst($name));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -57,6 +57,7 @@ class Converter
|
||||
'len' => 'len',
|
||||
'notNull' => 'notNull',
|
||||
'autoincrement' => 'autoincrement',
|
||||
'entity' => 'entity',
|
||||
'notStorable' => 'notStorable',
|
||||
'link' => 'relation',
|
||||
'field' => 'foreign', //todo change "foreign" to "field"
|
||||
@@ -163,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
|
||||
@@ -183,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,
|
||||
);
|
||||
@@ -301,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 */
|
||||
|
||||
@@ -352,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;
|
||||
|
||||
64
application/Espo/Core/Utils/Database/Orm/Fields/Currency.php
Normal file
64
application/Espo/Core/Utils/Database/Orm/Fields/Currency.php
Normal file
@@ -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}"
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -39,7 +39,7 @@ class Email extends \Espo\Core\Utils\Database\Orm\Base
|
||||
JOIN email_address ON email_address.id = entity_email_address.email_address_id
|
||||
WHERE
|
||||
entity_email_address.deleted = 0 AND entity_email_address.entity_type = '{$entityName}' AND
|
||||
email_address.deleted = 0 AND email_address.name LIKE '{text}'
|
||||
email_address.deleted = 0 AND email_address.name LIKE {value}
|
||||
)",
|
||||
'=' => \Espo\Core\Utils\Util::toUnderScore($entityName) . ".id IN (
|
||||
SELECT entity_id
|
||||
@@ -47,7 +47,15 @@ class Email extends \Espo\Core\Utils\Database\Orm\Base
|
||||
JOIN email_address ON email_address.id = entity_email_address.email_address_id
|
||||
WHERE
|
||||
entity_email_address.deleted = 0 AND entity_email_address.entity_type = '{$entityName}' AND
|
||||
email_address.deleted = 0 AND email_address.name = '{text}'
|
||||
email_address.deleted = 0 AND email_address.name = {value}
|
||||
)",
|
||||
'<>' => \Espo\Core\Utils\Util::toUnderScore($entityName) . ".id IN (
|
||||
SELECT entity_id
|
||||
FROM entity_email_address
|
||||
JOIN email_address ON email_address.id = entity_email_address.email_address_id
|
||||
WHERE
|
||||
entity_email_address.deleted = 0 AND entity_email_address.entity_type = '{$entityName}' AND
|
||||
email_address.deleted = 0 AND email_address.name <> {value}
|
||||
)"
|
||||
),
|
||||
'orderBy' => 'email_address.name {direction}',
|
||||
|
||||
@@ -28,7 +28,8 @@ class PersonName extends \Espo\Core\Utils\Database\Orm\Base
|
||||
{
|
||||
protected function load($fieldName, $entityName)
|
||||
{
|
||||
$foreignField = $this->getForeignField($fieldName, $entityName);
|
||||
$foreignField = array('first' . ucfirst($fieldName), ' ', 'last' . ucfirst($fieldName));
|
||||
|
||||
$tableName = Util::toUnderScore($entityName);
|
||||
|
||||
$fullList = array(); //contains empty string (" ") like delimiter
|
||||
@@ -44,8 +45,8 @@ class PersonName extends \Espo\Core\Utils\Database\Orm\Base
|
||||
$columnName = $tableName.'.'.Util::toUnderScore($fieldNameTrimmed);
|
||||
|
||||
$fullList[] = $fieldList[] = $columnName;
|
||||
$like[] = $columnName." LIKE '{text}'";
|
||||
$equal[] = $columnName." = '{text}'";
|
||||
$like[] = $columnName." LIKE {value}";
|
||||
$equal[] = $columnName." = {value}";
|
||||
} else {
|
||||
$fullList[] = "'".$foreignFieldName."'";
|
||||
}
|
||||
@@ -60,8 +61,8 @@ class PersonName extends \Espo\Core\Utils\Database\Orm\Base
|
||||
'type' => 'varchar',
|
||||
'select' => $this->getSelect($fullList),
|
||||
'where' => array(
|
||||
'LIKE' => "(".implode(" OR ", $like)." OR CONCAT(".implode(", ", $fullList).") LIKE '{text}' OR CONCAT(".implode(", ", $fullListReverse).") LIKE '{text}')",
|
||||
'=' => "(".implode(" OR ", $equal)." OR CONCAT(".implode(", ", $fullList).") = '{text}' OR CONCAT(".implode(", ", $fullListReverse).") = '{text}')",
|
||||
'LIKE' => "(".implode(" OR ", $like)." OR CONCAT(".implode(", ", $fullList).") LIKE {value} OR CONCAT(".implode(", ", $fullListReverse).") LIKE {value})",
|
||||
'=' => "(".implode(" OR ", $equal)." OR CONCAT(".implode(", ", $fullList).") = {value} OR CONCAT(".implode(", ", $fullListReverse).") = {value})",
|
||||
),
|
||||
'orderBy' => implode(", ", array_map(function ($item) {return $item . ' {direction}';}, $fieldList)),
|
||||
),
|
||||
@@ -86,4 +87,4 @@ class PersonName extends \Espo\Core\Utils\Database\Orm\Base
|
||||
return $select;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@ class Phone extends \Espo\Core\Utils\Database\Orm\Base
|
||||
JOIN phone_number ON phone_number.id = entity_phone_number.phone_number_id
|
||||
WHERE
|
||||
entity_phone_number.deleted = 0 AND entity_phone_number.entity_type = '{$entityName}' AND
|
||||
phone_number.deleted = 0 AND phone_number.name LIKE '{text}'
|
||||
phone_number.deleted = 0 AND phone_number.name LIKE {value}
|
||||
)",
|
||||
'=' => \Espo\Core\Utils\Util::toUnderScore($entityName) . ".id IN (
|
||||
SELECT entity_id
|
||||
@@ -47,7 +47,15 @@ class Phone extends \Espo\Core\Utils\Database\Orm\Base
|
||||
JOIN phone_number ON phone_number.id = entity_phone_number.phone_number_id
|
||||
WHERE
|
||||
entity_phone_number.deleted = 0 AND entity_phone_number.entity_type = '{$entityName}' AND
|
||||
phone_number.deleted = 0 AND phone_number.name = '{text}'
|
||||
phone_number.deleted = 0 AND phone_number.name = {value}
|
||||
)",
|
||||
'<>' => \Espo\Core\Utils\Util::toUnderScore($entityName) . ".id IN (
|
||||
SELECT entity_id
|
||||
FROM entity_phone_number
|
||||
JOIN phone_number ON phone_number.id = entity_phone_number.phone_number_id
|
||||
WHERE
|
||||
entity_phone_number.deleted = 0 AND entity_phone_number.entity_type = '{$entityName}' AND
|
||||
phone_number.deleted = 0 AND phone_number.name <> {value}
|
||||
)"
|
||||
),
|
||||
'orderBy' => 'phone_number.name {direction}',
|
||||
|
||||
@@ -31,7 +31,12 @@ class Base extends \Espo\Core\Utils\Database\Orm\Base
|
||||
protected $foreignLinkName = null;
|
||||
protected $foreignEntityName = null;
|
||||
|
||||
protected $allowParams = array();
|
||||
protected $allowedParams = array(
|
||||
'relationName',
|
||||
'conditions',
|
||||
'additionalColumns',
|
||||
'midKeys',
|
||||
);
|
||||
|
||||
protected function getParams()
|
||||
{
|
||||
@@ -106,10 +111,10 @@ class Base extends \Espo\Core\Utils\Database\Orm\Base
|
||||
$linkName = $this->getLinkName();
|
||||
$entityName = $this->getEntityName();
|
||||
|
||||
if (!empty($this->allowParams)) {
|
||||
if (!empty($this->allowedParams)) {
|
||||
$linkParams = &$loads[$entityName]['relations'][$linkName];
|
||||
|
||||
foreach ($this->allowParams as $name) {
|
||||
foreach ($this->allowedParams as $name) {
|
||||
|
||||
$additionalParrams = $this->getAllowedAdditionalParams($name);
|
||||
|
||||
|
||||
@@ -24,12 +24,6 @@ namespace Espo\Core\Utils\Database\Orm\Relations;
|
||||
|
||||
class HasMany extends Base
|
||||
{
|
||||
protected $allowParams = array(
|
||||
'relationName',
|
||||
'conditions',
|
||||
'additionalColumns',
|
||||
);
|
||||
|
||||
protected function load($linkName, $entityName)
|
||||
{
|
||||
$linkParams = $this->getLinkParams();
|
||||
|
||||
@@ -26,12 +26,6 @@ use Espo\Core\Utils\Util;
|
||||
|
||||
class ManyMany extends Base
|
||||
{
|
||||
protected $allowParams = array(
|
||||
'relationName',
|
||||
'conditions',
|
||||
'additionalColumns',
|
||||
);
|
||||
|
||||
protected function load($linkName, $entityName)
|
||||
{
|
||||
$foreignEntityName = $this->getForeignEntityName();
|
||||
|
||||
@@ -276,7 +276,8 @@ class Converter
|
||||
case 'array':
|
||||
case 'jsonArray':
|
||||
case 'text':
|
||||
$dbFieldParams['default'] = ''; //for db type TEXT can't be defined a default value
|
||||
case 'longtext':
|
||||
unset($dbFieldParams['default']); //for db type TEXT can't be defined a default value
|
||||
break;
|
||||
|
||||
case 'bool':
|
||||
|
||||
@@ -18,24 +18,32 @@
|
||||
*
|
||||
* 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\Schema\rebuildActions;
|
||||
|
||||
class Currency extends \Espo\Core\Utils\Database\Schema\BaseRebuildActions
|
||||
{
|
||||
|
||||
public function afterRebuild()
|
||||
{
|
||||
$currencyConfig = $this->getConfig()->get('currency');
|
||||
$currencyConfig['rate'][ $currencyConfig['base'] ] = '1.00';
|
||||
|
||||
$pdo = $this->getEntityManager()->getPDO();
|
||||
public function afterRebuild()
|
||||
{
|
||||
$defaultCurrency = $this->getConfig()->get('defaultCurrency');
|
||||
|
||||
$baseCurrency = $this->getConfig()->get('baseCurrency');
|
||||
$currencyRates = $this->getConfig()->get('currencyRates');
|
||||
|
||||
if ($defaultCurrency != $baseCurrency) {
|
||||
$currencyRates = $this->exchangeRates($baseCurrency, $defaultCurrency, $currencyRates);
|
||||
}
|
||||
|
||||
$currencyRates[$defaultCurrency] = '1.00';
|
||||
|
||||
$pdo = $this->getEntityManager()->getPDO();
|
||||
|
||||
$sql = "TRUNCATE `currency`";
|
||||
$pdo->prepare($sql)->execute();
|
||||
|
||||
foreach ($currencyConfig['rate'] as $currencyName => $rate) {
|
||||
foreach ($currencyRates as $currencyName => $rate) {
|
||||
|
||||
$sql = "
|
||||
INSERT INTO `currency`
|
||||
@@ -43,9 +51,34 @@ class Currency extends \Espo\Core\Utils\Database\Schema\BaseRebuildActions
|
||||
VALUES
|
||||
(".$pdo->quote($currencyName) . ", " . $pdo->quote($rate) . ")
|
||||
";
|
||||
$pdo->prepare($sql)->execute();
|
||||
}
|
||||
}
|
||||
|
||||
$pdo->prepare($sql)->execute();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate exchange rates if defaultCurrency doesn't equals baseCurrency
|
||||
*
|
||||
* @param string $baseCurrency
|
||||
* @param string $defaultCurrency
|
||||
* @param array $currencyRates [description]
|
||||
* @return array - List of new currency rates
|
||||
*/
|
||||
protected function exchangeRates($baseCurrency, $defaultCurrency, array $currencyRates)
|
||||
{
|
||||
$precision = 5;
|
||||
$defaultCurrencyRate = round(1 / $currencyRates[$defaultCurrency], $precision);
|
||||
|
||||
$exchangedRates = array();
|
||||
$exchangedRates[$baseCurrency] = $defaultCurrencyRate;
|
||||
|
||||
unset($currencyRates[$baseCurrency], $currencyRates[$defaultCurrency]);
|
||||
|
||||
foreach ($currencyRates as $currencyName => $rate) {
|
||||
$exchangedRates[$currencyName] = round($rate * $defaultCurrencyRate, $precision);
|
||||
}
|
||||
|
||||
return $exchangedRates;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -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,22 +225,32 @@ class Manager
|
||||
* @param string | array $path
|
||||
* @param string $content JSON string
|
||||
* @param bool $isJSON
|
||||
* @param array $mergeOptions
|
||||
* @param string | array $removeOptions - List of unset keys from content
|
||||
* @param bool $isReturn - Is result to be returned or stored
|
||||
*
|
||||
* @return bool
|
||||
* @return bool | array
|
||||
*/
|
||||
public function mergeContents($path, $content, $isJSON = false, $mergeOptions = null)
|
||||
public function mergeContents($path, $content, $isJSON = false, $removeOptions = null, $isReturn = false)
|
||||
{
|
||||
$fileContent = $this->getContents($path);
|
||||
|
||||
$savedDataArray = Utils\Json::getArrayData($fileContent);
|
||||
$newDataArray = Utils\Json::getArrayData($content);
|
||||
|
||||
$data = Utils\Util::merge($savedDataArray, $newDataArray, $mergeOptions);
|
||||
if (isset($removeOptions)) {
|
||||
$savedDataArray = Utils\Util::unsetInArray($savedDataArray, $removeOptions);
|
||||
$newDataArray = Utils\Util::unsetInArray($newDataArray, $removeOptions);
|
||||
}
|
||||
|
||||
$data = Utils\Util::merge($savedDataArray, $newDataArray);
|
||||
if ($isJSON) {
|
||||
$data = Utils\Json::encode($data, JSON_PRETTY_PRINT);
|
||||
}
|
||||
|
||||
if ($isReturn) {
|
||||
return $data;
|
||||
}
|
||||
|
||||
return $this->putContents($path, $data);
|
||||
}
|
||||
|
||||
@@ -248,26 +258,13 @@ class Manager
|
||||
* Merge PHP content and save it to a file
|
||||
*
|
||||
* @param string | array $path
|
||||
* @param string $content
|
||||
* @param bool $onlyFirstLevel - Merge only first level. Ex. current: array('test'=>array('item1', 'item2')). $content= array('test'=>array('item1'),). Result will be array('test'=>array('item1')).
|
||||
*
|
||||
* @param string $content JSON string
|
||||
* @param string | array $removeOptions - List of unset keys from content
|
||||
* @return bool
|
||||
*/
|
||||
public function mergeContentsPHP($path, $content, $onlyFirstLevel = false, $mergeOptions = null)
|
||||
public function mergeContentsPHP($path, $content, $removeOptions = null)
|
||||
{
|
||||
$fileContent = $this->getContents($path);
|
||||
|
||||
$savedDataArray = Utils\Json::getArrayData($fileContent);
|
||||
$newDataArray = Utils\Json::getArrayData($content);
|
||||
|
||||
if ($onlyFirstLevel) {
|
||||
foreach($newDataArray as $key => $val) {
|
||||
$setVal = is_array($val) ? array() : '';
|
||||
$savedDataArray[$key] = $setVal;
|
||||
}
|
||||
}
|
||||
|
||||
$data = Utils\Util::merge($savedDataArray, $newDataArray, $mergeOptions);
|
||||
$data = $this->mergeContents($path, $content, false, $removeOptions, true);
|
||||
|
||||
return $this->putContentsPHP($path, $data);
|
||||
}
|
||||
@@ -363,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.
|
||||
*
|
||||
@@ -472,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;
|
||||
@@ -567,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)) {
|
||||
@@ -480,11 +480,12 @@ class Permission
|
||||
if (file_exists($item)) {
|
||||
|
||||
try {
|
||||
$res = $this->chmod($item, $permission, true);
|
||||
$this->chmod($item, $permission, true);
|
||||
} catch (\Exception $e) {
|
||||
$res = false;
|
||||
}
|
||||
|
||||
$res = is_readable($item);
|
||||
|
||||
/** check is wtitable */
|
||||
if ($type == 'writable') {
|
||||
|
||||
@@ -534,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]
|
||||
*
|
||||
@@ -101,8 +96,8 @@ class Unifier
|
||||
$dirName = $this->getFileManager()->getDirName($dirPath, false);
|
||||
$defaultValues = $this->loadDefaultValues($dirName, $type);
|
||||
|
||||
$content= array();
|
||||
$unsets= array();
|
||||
$content = array();
|
||||
$unsets = array();
|
||||
foreach($fileList as $dirName => $fileName) {
|
||||
|
||||
if (is_array($fileName)) { /*get content from files in a sub directory*/
|
||||
@@ -125,7 +120,7 @@ class Unifier
|
||||
}
|
||||
|
||||
//unset content
|
||||
$content= Utils\Util::unsetInArray($content, $unsets);
|
||||
$content = Utils\Util::unsetInArray($content, $unsets);
|
||||
//END: unset content
|
||||
|
||||
return $content;
|
||||
@@ -141,27 +136,16 @@ class Unifier
|
||||
*/
|
||||
protected function unifyGetContents($paths, $defaults)
|
||||
{
|
||||
$fileContent= $this->getFileManager()->getContents($paths);
|
||||
$decoded= Utils\Json::getArrayData($fileContent);
|
||||
$fileContent = $this->getFileManager()->getContents($paths);
|
||||
|
||||
if (empty($decoded) && !is_array($decoded)) {
|
||||
$GLOBALS['log']->emergency('Syntax error or empty file - '.Utils\Util::concatPath($folderPath, $fileName));
|
||||
} else {
|
||||
//Default values
|
||||
if (is_string($defaults) && !empty($defaults)) {
|
||||
$defType= $defaults;
|
||||
unset($defaults);
|
||||
$name= $this->getFileManager()->getFileName($fileName, '.json');
|
||||
$decoded = Utils\Json::getArrayData($fileContent, null);
|
||||
|
||||
$defaults= $this->loadDefaultValues($name, $defType);
|
||||
}
|
||||
$mergedValues= Utils\Util::merge($defaults, $decoded);
|
||||
//END: Default values
|
||||
|
||||
return $mergedValues;
|
||||
if (!isset($decoded)) {
|
||||
$GLOBALS['log']->emergency('Syntax error in '.Utils\Util::concatPath($paths));
|
||||
return array();
|
||||
}
|
||||
|
||||
return array();
|
||||
return $decoded;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -172,12 +156,12 @@ class Unifier
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function loadDefaultValues($name, $type='metadata')
|
||||
protected function loadDefaultValues($name, $type = 'metadata')
|
||||
{
|
||||
$defaultPath= $this->params['defaultsPath'];
|
||||
$defaultPath = $this->params['defaultsPath'];
|
||||
|
||||
$defaultValue= $this->getFileManager()->getContents( array($defaultPath, $type, $name.'.json') );
|
||||
if ($defaultValue!==false) {
|
||||
$defaultValue = $this->getFileManager()->getContents( array($defaultPath, $type, $name.'.json') );
|
||||
if ($defaultValue !== false) {
|
||||
//return default array
|
||||
return Utils\Json::decode($defaultValue, true);
|
||||
}
|
||||
|
||||
@@ -118,7 +118,7 @@ class Json
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getArrayData($data)
|
||||
public static function getArrayData($data, $returns = array())
|
||||
{
|
||||
if (is_array($data)) {
|
||||
return $data;
|
||||
@@ -127,7 +127,7 @@ class Json
|
||||
return static::decode($data, true);
|
||||
}
|
||||
|
||||
return array();
|
||||
return $returns;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -154,10 +154,10 @@ class Language
|
||||
|
||||
return $translated;
|
||||
}
|
||||
|
||||
|
||||
public function translateOption($value, $field, $scope)
|
||||
{
|
||||
$options = $this->get($scope. '.options.' . $field);
|
||||
$options = $this->get($scope. '.options.' . $field);
|
||||
if (array_key_exists($value, $options)) {
|
||||
return $options[$value];
|
||||
}
|
||||
|
||||
@@ -142,13 +142,13 @@ class Metadata
|
||||
* Get Metadata
|
||||
*
|
||||
* @param string $key
|
||||
* @param mixed $return
|
||||
* @param mixed $default
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get($key = null, $returns = null)
|
||||
public function get($key = null, $default = null)
|
||||
{
|
||||
return Util::getValueByKey($this->getData(), $key, $returns);
|
||||
return Util::getValueByKey($this->getData(), $key, $default);
|
||||
}
|
||||
|
||||
|
||||
@@ -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.");
|
||||
}
|
||||
@@ -430,4 +430,4 @@ class Metadata
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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,100 +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 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)
|
||||
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);
|
||||
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)) {
|
||||
$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
|
||||
@@ -232,7 +183,6 @@ class Util
|
||||
return $folderPath . static::getSeparator() . $filePath;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Convert array to object format recursively
|
||||
*
|
||||
@@ -248,7 +198,6 @@ class Util
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Convert object to array format recursively
|
||||
*
|
||||
@@ -278,7 +227,6 @@ class Util
|
||||
return $name;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get Naming according to prefix or postfix type
|
||||
*
|
||||
@@ -299,7 +247,6 @@ class Util
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Replace $search in array recursively
|
||||
*
|
||||
@@ -336,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;
|
||||
}
|
||||
|
||||
@@ -359,11 +310,18 @@ class Util
|
||||
if (!empty($unsetSett)){
|
||||
$keyItems = explode('.', $unsetSett);
|
||||
$currVal = isset($content[$rootKey]) ? "\$content['{$rootKey}']" : "\$content";
|
||||
|
||||
$lastKey = array_pop($keyItems);
|
||||
foreach($keyItems as $keyItem){
|
||||
$currVal .= "['{$keyItem}']";
|
||||
}
|
||||
|
||||
$currVal = "if (isset({$currVal})) unset({$currVal});";
|
||||
$unsetElem = $currVal . "['{$lastKey}']";
|
||||
|
||||
$currVal = "
|
||||
if (isset({$unsetElem}) || ( is_array({$currVal}) && array_key_exists({$lastKey}, {$currVal}) )) {
|
||||
unset({$unsetElem});
|
||||
} ";
|
||||
eval($currVal);
|
||||
}
|
||||
}
|
||||
@@ -372,7 +330,6 @@ class Util
|
||||
return $content;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get class name from the file path
|
||||
*
|
||||
@@ -389,16 +346,15 @@ class Util
|
||||
return $className;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return values of defined $key.
|
||||
*
|
||||
* @param array $array
|
||||
* @param string $key Ex. of key is "entityDefs", "entityDefs.User"
|
||||
* @param mixed $returns
|
||||
* @param mixed $default
|
||||
* @return mixed
|
||||
*/
|
||||
public static function getValueByKey(array $array, $key = null, $returns = null)
|
||||
public static function getValueByKey(array $array, $key = null, $default = null)
|
||||
{
|
||||
if (!isset($key) || empty($key)) {
|
||||
return $array;
|
||||
@@ -411,13 +367,62 @@ class Util
|
||||
if (isset($lastItem[$keyName]) && is_array($lastItem)) {
|
||||
$lastItem = $lastItem[$keyName];
|
||||
} else {
|
||||
return $returns;
|
||||
return $default;
|
||||
}
|
||||
}
|
||||
|
||||
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,16 +41,13 @@ return array (
|
||||
'weekStart' => 0,
|
||||
'thousandSeparator' => ',',
|
||||
'decimalMark' => '.',
|
||||
'exportDelimiter' => ',',
|
||||
'exportDelimiter' => ';',
|
||||
'currencyList' =>
|
||||
array (
|
||||
),
|
||||
'defaultCurrency' => 'USD',
|
||||
'currency' =>
|
||||
array(
|
||||
'base' => 'USD',
|
||||
'rate' => array(
|
||||
),
|
||||
'baseCurrency' => 'USD',
|
||||
'currencyRates' => array(
|
||||
),
|
||||
'outboundEmailIsShared' => true,
|
||||
'outboundEmailFromName' => 'EspoCRM',
|
||||
@@ -62,12 +59,15 @@ return array (
|
||||
'smtpUsername' => '',
|
||||
'smtpPassword' => '',
|
||||
'languageList' => array(
|
||||
'en_US',
|
||||
'en_US',
|
||||
'de_DE',
|
||||
'es_ES',
|
||||
'fr_FR',
|
||||
'nl_NL',
|
||||
'tr_TR',
|
||||
'ro_RO',
|
||||
'ru_RU',
|
||||
'pl_PL',
|
||||
'pt_BR',
|
||||
'vi_VN'
|
||||
),
|
||||
@@ -93,6 +93,7 @@ return array (
|
||||
'disableExport' => false,
|
||||
'assignmentEmailNotifications' => false,
|
||||
'assignmentEmailNotificationsEntityList' => array('Lead', 'Opportunity', 'Task', 'Case'),
|
||||
'emailMessageMaxSize' => 10,
|
||||
'isInstalled' => false,
|
||||
);
|
||||
|
||||
|
||||
@@ -46,6 +46,21 @@ class Email extends \Espo\Core\ORM\Entity
|
||||
}
|
||||
}
|
||||
|
||||
public function getBodyPlainForSending()
|
||||
{
|
||||
$bodyPlain = $this->get('bodyPlain');
|
||||
if (!empty($bodyPlain)) {
|
||||
return $bodyPlain;
|
||||
}
|
||||
|
||||
$body = $this->get('body');
|
||||
|
||||
$breaks = array("<br />","<br>","<br/>","<br />","<br />","<br/>","<br>");
|
||||
$body = str_ireplace($breaks, "\r\n", $body);
|
||||
$body = strip_tags($body);
|
||||
return $body;
|
||||
}
|
||||
|
||||
public function getBodyForSending()
|
||||
{
|
||||
$body = $this->get('body');
|
||||
@@ -55,6 +70,7 @@ class Email extends \Espo\Core\ORM\Entity
|
||||
$body = str_replace("?entryPoint=attachment&id={$attachment->id}", "cid:{$attachment->id}", $body);
|
||||
}
|
||||
}
|
||||
|
||||
$body = str_replace("<table class=\"table table-bordered\">", "<table class=\"table table-bordered\" width=\"100%\">", $body);
|
||||
|
||||
return $body;
|
||||
|
||||
30
application/Espo/Entities/EmailAccount.php
Normal file
30
application/Espo/Entities/EmailAccount.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?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 EmailAccount extends \Espo\Core\ORM\Entity
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
|
||||
29
application/Espo/Entities/Extension.php
Normal file
29
application/Espo/Entities/Extension.php
Normal file
@@ -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
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
28
application/Espo/Entities/ExternalAccount.php
Normal file
28
application/Espo/Entities/ExternalAccount.php
Normal file
@@ -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\Entities;
|
||||
|
||||
class ExternalAccount extends Integration
|
||||
{
|
||||
}
|
||||
|
||||
175
application/Espo/Entities/Integration.php
Normal file
175
application/Espo/Entities/Integration.php
Normal file
@@ -0,0 +1,175 @@
|
||||
<?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 Integration extends \Espo\Core\ORM\Entity
|
||||
{
|
||||
public function get($name)
|
||||
{
|
||||
if ($name == 'id') {
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
if ($this->hasField($name)) {
|
||||
if (array_key_exists($name, $this->valuesContainer)) {
|
||||
return $this->valuesContainer[$name];
|
||||
}
|
||||
} else {
|
||||
if ($this->get('data')) {
|
||||
$data = $this->get('data');
|
||||
} else {
|
||||
$data = new \stdClass();
|
||||
}
|
||||
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)) {
|
||||
if ($p2 === null) {
|
||||
$p2 = false;
|
||||
}
|
||||
$this->populateFromArray($p1, $p2);
|
||||
return;
|
||||
}
|
||||
|
||||
$name = $p1;
|
||||
$value = $p2;
|
||||
|
||||
if ($name == 'id') {
|
||||
$this->id = $value;
|
||||
return;
|
||||
}
|
||||
|
||||
if ($this->hasField($name)) {
|
||||
$this->valuesContainer[$name] = $value;
|
||||
} else {
|
||||
if (!$this->get('enabled')) {
|
||||
return;
|
||||
}
|
||||
$data = $this->get('data');
|
||||
if (empty($data)) {
|
||||
$data = new \stdClass();
|
||||
}
|
||||
$data->$name = $value;
|
||||
$this->set('data', $data);
|
||||
}
|
||||
}
|
||||
|
||||
public function populateFromArray(array $arr, $onlyAccessible = true, $reset = false)
|
||||
{
|
||||
if ($reset) {
|
||||
$this->reset();
|
||||
}
|
||||
|
||||
foreach ($arr as $field => $value) {
|
||||
if (is_string($field)) {
|
||||
if (is_array($value) || ($value instanceof \stdClass)) {
|
||||
$value = json_encode($value);
|
||||
}
|
||||
|
||||
if ($this->hasField($field)) {
|
||||
$fields = $this->getFields();
|
||||
$fieldDefs = $fields[$field];
|
||||
|
||||
if (!is_null($value)) {
|
||||
switch ($fieldDefs['type']) {
|
||||
case self::VARCHAR:
|
||||
break;
|
||||
case self::BOOL:
|
||||
$value = ($value === 'true' || $value === '1' || $value === true);
|
||||
break;
|
||||
case self::INT:
|
||||
$value = intval($value);
|
||||
break;
|
||||
case self::FLOAT:
|
||||
$value = floatval($value);
|
||||
break;
|
||||
case self::JSON_ARRAY:
|
||||
$value = is_string($value) ? json_decode($value) : $value;
|
||||
if (!is_array($value)) {
|
||||
$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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$this->set($field, $value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function toArray()
|
||||
{
|
||||
$arr = array();
|
||||
if (isset($this->id)) {
|
||||
$arr['id'] = $this->id;
|
||||
}
|
||||
foreach ($this->fields as $field => $defs) {
|
||||
if ($field == 'id') {
|
||||
continue;
|
||||
}
|
||||
if ($this->has($field)) {
|
||||
$arr[$field] = $this->get($field);
|
||||
}
|
||||
}
|
||||
|
||||
$data = $this->get('data');
|
||||
if (empty($data)) {
|
||||
$data = new \stdClass();
|
||||
}
|
||||
|
||||
$dataArr = get_object_vars($data);
|
||||
|
||||
$arr = array_merge($arr, $dataArr);
|
||||
return $arr;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -30,6 +30,10 @@ class Download extends \Espo\Core\EntryPoints\Base
|
||||
{
|
||||
public static $authRequired = true;
|
||||
|
||||
protected $fileTypesToShowInline = array(
|
||||
'application/pdf',
|
||||
);
|
||||
|
||||
public function run()
|
||||
{
|
||||
$id = $_GET['id'];
|
||||
@@ -54,13 +58,21 @@ class Download extends \Espo\Core\EntryPoints\Base
|
||||
|
||||
if (!file_exists($fileName)) {
|
||||
throw new NotFound();
|
||||
}
|
||||
}
|
||||
|
||||
$type = $attachment->get('type');
|
||||
|
||||
$disposition = 'attachment';
|
||||
if (in_array($type, $this->fileTypesToShowInline)) {
|
||||
$disposition = 'inline';
|
||||
}
|
||||
|
||||
|
||||
header('Content-Description: File Transfer');
|
||||
if ($attachment->get('type')) {
|
||||
header('Content-Type: ' . $attachment->get('type'));
|
||||
if ($type) {
|
||||
header('Content-Type: ' . $type);
|
||||
}
|
||||
header('Content-Disposition: attachment; filename=' . $attachment->get('name'));
|
||||
header('Content-Disposition: ' . $disposition . '; filename=' . $attachment->get('name'));
|
||||
header('Expires: 0');
|
||||
header('Cache-Control: must-revalidate');
|
||||
header('Pragma: public');
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -69,26 +69,29 @@ class Stream extends \Espo\Core\Hooks\Base
|
||||
{
|
||||
$linkDefs = $this->getMetadata()->get("entityDefs." . $entity->getEntityName() . ".links", array());
|
||||
|
||||
$scopeNotifiedList = array();
|
||||
foreach ($linkDefs as $link => $defs) {
|
||||
if ($defs['type'] == 'belongsTo') {
|
||||
$foreign = $defs['foreign'];
|
||||
$scope = $defs['entity'];
|
||||
$entityId = $entity->get($link . 'Id');
|
||||
if (!empty($scope) && !empty($entityId)) {
|
||||
if (!$this->isLinkObservableInStream($scope, $foreign)) {
|
||||
if (in_array($scope, $scopeNotifiedList) || !$this->isLinkObservableInStream($scope, $foreign)) {
|
||||
continue;
|
||||
}
|
||||
$this->getStreamService()->noteCreateRelated($entity, $scope, $entityId);
|
||||
$scopeNotifiedList[] = $scope;
|
||||
}
|
||||
} else if ($defs['type'] == 'belongsToParent') {
|
||||
$foreign = $defs['foreign'];
|
||||
$scope = $entity->get($link . 'Type');
|
||||
$entityId = $entity->get($link . 'Id');
|
||||
if (!empty($scope) && !empty($entityId)) {
|
||||
if (!$this->isLinkObservableInStream($scope, $foreign)) {
|
||||
if (in_array($scope, $scopeNotifiedList) || !$this->isLinkObservableInStream($scope, $foreign)) {
|
||||
continue;
|
||||
}
|
||||
$this->getStreamService()->noteCreateRelated($entity, $scope, $entityId);
|
||||
$scopeNotifiedList[] = $scope;
|
||||
|
||||
}
|
||||
} else if ($defs['type'] == 'hasMany') {
|
||||
@@ -96,11 +99,12 @@ class Stream extends \Espo\Core\Hooks\Base
|
||||
$scope = $defs['entity'];
|
||||
$entityIds = $entity->get($link . 'Ids');
|
||||
if (!empty($scope) && is_array($entityIds) && !empty($entityIds)) {
|
||||
if (!$this->isLinkObservableInStream($scope, $foreign)) {
|
||||
if (in_array($scope, $scopeNotifiedList) || !$this->isLinkObservableInStream($scope, $foreign)) {
|
||||
continue;
|
||||
}
|
||||
$entityId = $entityIds[0];
|
||||
$this->getStreamService()->noteCreateRelated($entity, $scope, $entityId);
|
||||
$this->getStreamService()->noteCreateRelated($entity, $scope, $entityId);
|
||||
$scopeNotifiedList[] = $scope;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
109
application/Espo/Hooks/Note/Mentions.php
Normal file
109
application/Espo/Hooks/Note/Mentions.php
Normal file
@@ -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);
|
||||
|
||||
28
application/Espo/Modules/Crm/Controllers/Contract.php
Normal file
28
application/Espo/Modules/Crm/Controllers/Contract.php
Normal file
@@ -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
|
||||
{
|
||||
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user