Compare commits

...

709 Commits
1.2.1 ... 2.7.0

Author SHA1 Message Date
Yuri Kuznetsov
14d83c3a19 Merge branch 'master' into stable 2014-11-12 16:58:35 +02:00
Taras Machyshyn
0ec182727a Merge branch 'master' of ssh://172.20.0.1/var/git/espo/backend 2014-11-12 15:15:28 +02:00
Taras Machyshyn
bd4057ed05 improved russian language 2014-11-12 15:15:08 +02:00
Yuri Kuznetsov
dcee02aed4 lang 2014-11-12 10:59:03 +02:00
Yuri Kuznetsov
94b59404a7 lang 2014-11-12 10:56:44 +02:00
Taras Machyshyn
77a3b5ee77 ORM converter fixes 2014-11-11 16:35:28 +02:00
Taras Machyshyn
251e100e65 Improve english language 2014-11-11 16:33:53 +02:00
Yuri Kuznetsov
e87a69e6a3 clearup 2014-11-11 16:07:13 +02:00
Yuri Kuznetsov
e45b98d684 team roles 2014-11-11 13:03:35 +02:00
Yuri Kuznetsov
affc40959b decrease list menu-column width 2014-11-11 11:00:20 +02:00
Yuri Kuznetsov
e301514ec6 cases changes 2014-11-11 10:57:40 +02:00
Yuri Kuznetsov
0c4c93487d fix acl check 2014-11-10 17:34:46 +02:00
Yuri Kuznetsov
7dc6622dd2 change pie chart 2014-11-10 17:33:51 +02:00
Yuri Kuznetsov
d7fea15f59 fix roles 2014-11-10 17:31:40 +02:00
Yuri Kuznetsov
e73eb1ccc1 cleanup 2014-11-10 17:26:28 +02:00
Yuri Kuznetsov
3f2cf25ef5 clearnup 2014-11-10 17:25:46 +02:00
Yuri Kuznetsov
76f48900c3 ru_RU lang changes 2014-11-10 10:36:40 +02:00
Yuri Kuznetsov
a4d76666ac de_DE language changes 2014-11-10 10:35:31 +02:00
Yuri Kuznetsov
8a4ffb4d58 team layout changes 2014-11-07 16:05:09 +02:00
Yuri Kuznetsov
a9abfb41c7 cleanup 2014-11-07 15:46:01 +02:00
Yuri Kuznetsov
cee6f58631 ORM: isFetched and isNew changes 2014-11-07 15:21:50 +02:00
Yuri Kuznetsov
4075771a12 remove spare file 2014-11-07 12:42:04 +02:00
Taras Machyshyn
93d596fc95 Merge branch 'master' of ssh://172.20.0.1/var/git/espo/backend 2014-11-07 11:48:47 +02:00
Taras Machyshyn
9559e23e58 Util, tests fixes by elibyy 2014-11-07 11:48:33 +02:00
Yuri Kuznetsov
dc6c984b42 remove 0 duration from meeting 2014-11-07 11:38:21 +02:00
Yuri Kuznetsov
143cf3f8a1 fix list record 2014-11-07 11:01:10 +02:00
Yuri Kuznetsov
f62436b19c cleanup 2014-11-07 10:55:56 +02:00
Yuri Kuznetsov
7ca524e4ff change in diff.js 2014-11-07 10:52:49 +02:00
Yuri Kuznetsov
ed4d5d5083 fix parent field validation 2014-11-07 10:47:05 +02:00
Yuri Kuznetsov
3bea0a130d fix validation 2014-11-06 18:50:01 +02:00
Yuri Kuznetsov
8ac26402a2 cleanup 2014-11-06 18:01:31 +02:00
Yuri Kuznetsov
4ff19c5910 ORM: use complexExporession in getWhere 2014-11-06 17:34:41 +02:00
Yuri Kuznetsov
eb08ca638e fix validation 2014-11-06 14:43:35 +02:00
Yuri Kuznetsov
c373b97af1 Merge pull request #24 from alasdaircr/reply_to_all
Fix: use semi-colon instead of commas to seperate email addresses in to,...
2014-11-06 10:09:53 +02:00
Alasdair Campbell
6ea461faeb Fix: use semi-colon instead of commas to seperate email addresses in to, cc fields 2014-11-06 01:40:16 +00:00
Yuri Kuznetsov
414576cade Merge pull request #23 from alasdaircr/fix_22_part2
Not showing correct emailaddress
2014-11-05 17:10:27 +02:00
Alasdair Campbell
e35655b8a7 Not showing correct emailaddress 2014-11-05 14:58:52 +00:00
Yuri Kuznetsov
d8f3b24e31 fix PR 22 2014-11-05 15:10:25 +02:00
Yuri Kuznetsov
771212a9a3 Merge pull request #22 from alasdaircr/emails_and_events
Emails and events
2014-11-05 15:04:30 +02:00
Alasdair Campbell
0d35ba8fe0 Use User SMTP if available to send Event Invitations 2014-11-05 11:59:44 +00:00
Alasdair Campbell
fd39508bc5 Rename event invitiation attachments to match the event type 2014-11-05 11:59:44 +00:00
Alasdair Campbell
0299f30055 Generate Message-Id, as this was never returned by SMTP transport 2014-11-05 11:52:09 +00:00
Yuri Kuznetsov
1cdef2245a Merge branch 'master' of https://github.com/espocrm/espocrm 2014-11-05 13:32:48 +02:00
Yuri Kuznetsov
059fdcfd14 Merge pull request #21 from alasdaircr/reply_all
Reply-To-All should include any recipients which are not current user
2014-11-05 13:32:34 +02:00
Yuri Kuznetsov
4d6bb307ba fix link field 2014-11-05 13:30:35 +02:00
Alasdair Campbell
c9fb16b8d7 Reply-To-All should include any recipients which are not current user 2014-11-05 11:23:24 +00:00
Yuri Kuznetsov
15b2b3ea8e es_ES language update 2014-11-05 12:30:31 +02:00
Yuri Kuznetsov
f442dbd54a b2c support 2014-11-05 11:34:16 +02:00
Yuri Kuznetsov
aef3b0acf2 fix dashlet css 2014-11-05 10:49:25 +02:00
Yuri Kuznetsov
b0d2d22ab5 calendar acl 2014-11-04 15:08:53 +02:00
Yuri Kuznetsov
44c4ae7d28 ability to edit translated options 2014-11-04 12:24:52 +02:00
Yuri Kuznetsov
426dc4592e change field type 2014-11-04 11:22:52 +02:00
Yuri Kuznetsov
db52fb3f0e acl report dashlets 2014-11-04 10:34:38 +02:00
Yuri Kuznetsov
16963fdc58 sort fixes 2014-11-03 16:09:38 +02:00
Yuri Kuznetsov
a0b5138216 orders by translated values 2014-11-03 15:45:25 +02:00
Yuri Kuznetsov
515511a0d1 translatedOptions for enum 2014-11-03 12:34:35 +02:00
Yuri Kuznetsov
defa668138 fix opporunity dashlet access 2014-11-03 12:08:06 +02:00
Yuri Kuznetsov
526739a798 improve calendar ui 2014-11-03 11:54:36 +02:00
Yuri Kuznetsov
1655153b0a some acl fixes 2014-11-03 11:16:31 +02:00
Yuri Kuznetsov
7cf931897e acl improvements 2014-11-03 11:06:08 +02:00
Yuri Kuznetsov
76f5bcb345 fixes for multi-enum field 2014-10-31 16:24:43 +02:00
Yuri Kuznetsov
c112397003 date fields search type order 2014-10-31 15:36:05 +02:00
Yuri Kuznetsov
2edb4d42f9 break long links in text field 2014-10-31 12:30:40 +02:00
Yuri Kuznetsov
3e6ec34c91 email-to-case: attachments to note 2014-10-31 11:39:13 +02:00
Yuri Kuznetsov
ec417106cd ability to get container from container 2014-10-31 11:17:07 +02:00
Yuri Kuznetsov
d81af3dbed email to case improvements 2014-10-30 17:54:27 +02:00
Yuri Kuznetsov
1d79c0b92b email to case changes 2014-10-30 17:20:20 +02:00
Yuri Kuznetsov
06fa7e99d4 Merge branch 'master' of ssh://172.20.0.1/var/git/espo/backend 2014-10-30 16:44:26 +02:00
Yuri Kuznetsov
5087adf12a stream css fixes 2014-10-30 16:43:03 +02:00
Yuri Kuznetsov
a3e37fc1c0 improve entity getters and settiers 2014-10-30 16:36:37 +02:00
Yuri Kuznetsov
833ef820aa stream service fix 2014-10-30 16:34:59 +02:00
Taras Machyshyn
d333d0f3c1 Merge branch 'master' of ssh://172.20.0.1/var/git/espo/backend 2014-10-30 16:24:57 +02:00
Taras Machyshyn
fcead3379b Util impovements 2014-10-30 16:24:43 +02:00
Yuri Kuznetsov
7fa5b30ae9 email to case little change 2014-10-30 16:22:26 +02:00
Yuri Kuznetsov
4f0a1a3fe1 some css for stream 2014-10-30 16:14:48 +02:00
Yuri Kuznetsov
d0fd77734c fix sorting 2014-10-30 13:53:19 +02:00
Yuri Kuznetsov
e19aca0649 Merge branch 'master' of ssh://172.20.0.1/var/git/espo/backend 2014-10-30 13:37:44 +02:00
Yuri Kuznetsov
1776972c34 store sort order 2014-10-30 13:31:58 +02:00
Yuri Kuznetsov
e3e269cdaa cleanup 2014-10-30 13:29:40 +02:00
Taras Machyshyn
c8bfa823e5 Extension Manager improvements 2014-10-30 13:04:49 +02:00
Yuri Kuznetsov
1efc8fe976 dashlet fix 2014-10-30 12:46:15 +02:00
Yuri Kuznetsov
d711cbb524 Merge branch 'master' of https://github.com/espocrm/espocrm 2014-10-30 12:26:01 +02:00
Yuri Kuznetsov
c485da5b75 Merge pull request #18 from elibyy/master
fixed duplicate keys in JSON
2014-10-30 12:24:57 +02:00
elibyy
32bd385772 fixed duplicate keys in JSON 2014-10-30 11:54:08 +02:00
Yuri Kuznetsov
944e9e5e0b refactor dashlet options 2014-10-29 13:35:06 +02:00
Yuri Kuznetsov
47a9515a15 changed in README 2014-10-29 11:13:10 +02:00
Yuri Kuznetsov
fce8bb1acb Update README.md 2014-10-29 09:39:20 +02:00
Yuri Kuznetsov
de31441922 populate modifiedAt field on create 2014-10-28 17:25:43 +02:00
Yuri Kuznetsov
706bbf2117 remove compiled css 2014-10-28 17:15:13 +02:00
Yuri Kuznetsov
3d28b46483 add compiled css to gitignore 2014-10-28 17:13:59 +02:00
Yuri Kuznetsov
c272f25e07 build bootstrap.css 2014-10-28 17:10:14 +02:00
Yuri Kuznetsov
ccbe9e8c31 Merge branch 'master' of https://github.com/espocrm/espocrm 2014-10-28 17:09:16 +02:00
Yuri Kuznetsov
bf9f443f86 Merge pull request #15 from alasdaircr/preset_title
Use ellipsis for preset title in dropdown menu fix #14
2014-10-28 17:08:57 +02:00
Alasdair Campbell
532b9cfc7a Use ellipsis for preset title in dropdown menu fix #14 2014-10-28 15:02:02 +00:00
Yuri Kuznetsov
b638a22964 space between salutation and name 2014-10-28 15:39:37 +02:00
Yuri Kuznetsov
fb5eb60b95 code style fix 2014-10-28 10:28:02 +02:00
Yuri Kuznetsov
9f42fcdc4d disable login button while submitting 2014-10-28 10:19:56 +02:00
Yuri Kuznetsov
d48e0a6cfe Merge pull request #12 from alasdaircr/typo
Little typo
2014-10-27 17:38:21 +02:00
Yuri Kuznetsov
8a157729a6 Tasks panel: if no access to tasks then no show error 2014-10-27 17:11:45 +02:00
Yuri Kuznetsov
01fcb13a12 Merge branch 'master' of ssh://172.20.0.1/var/git/espo/backend 2014-10-27 16:40:44 +02:00
Yuri Kuznetsov
7ddff0b631 login form changes 2014-10-27 16:40:25 +02:00
Yuri Kuznetsov
e5e35a872f make multiEnum better sortable 2014-10-27 16:40:02 +02:00
Taras Machyshyn
c76b61e65b improved Dutch language 2014-10-27 16:06:32 +02:00
Yuri Kuznetsov
305e9fb74a fix login layout 2014-10-27 16:01:31 +02:00
Yuri Kuznetsov
7d300d1e79 user token field disablef 2014-10-27 15:55:19 +02:00
Yuri Kuznetsov
93f7cbb4e6 fix tpls 2014-10-27 15:52:12 +02:00
Yuri Kuznetsov
70ef83ac54 Merge branch 'master' of https://github.com/espocrm/espocrm 2014-10-27 14:51:09 +02:00
Yuri Kuznetsov
961e709843 fix invitation error 500 if empty email 2014-10-27 11:37:40 +02:00
Yuri Kuznetsov
3bd6e364ca meeting invitation improvements 2014-10-27 11:21:08 +02:00
Yuri Kuznetsov
17cf8da0d3 Update README.md 2014-10-24 22:09:15 +03:00
Yuri Kuznetsov
75c81ccdcf Update README.md 2014-10-24 22:08:09 +03:00
Yuri Kuznetsov
df0a958359 fix validate msg 2014-10-24 15:45:45 +03:00
Yuri Kuznetsov
2e69169c9c fix array required 2014-10-24 12:40:16 +03:00
Alasdair Campbell
fb7d313393 Little typo 2014-10-23 21:40:09 +01:00
Yuri Kuznetsov
2ab50c2dcc MassRemove and remove fixes 2014-10-23 16:52:51 +03:00
Yuri Kuznetsov
873c683ffb translate links 2014-10-23 15:22:53 +03:00
Yuri Kuznetsov
6e911dcc41 Merge branch 'master' of ssh://172.20.0.1/var/git/espo/backend 2014-10-23 14:49:58 +03:00
Yuri Kuznetsov
d04133ac68 remove outbonud email scope 2014-10-23 12:44:09 +03:00
Yuri Kuznetsov
6ca27cb255 fix Controller.Record 2014-10-23 12:22:22 +03:00
Taras Machyshyn
867aa72038 DataManager improvements 2014-10-23 12:18:17 +03:00
Yuri Kuznetsov
ca4c69570d autocomplete off for search filters 2014-10-23 12:16:33 +03:00
Yuri Kuznetsov
66c5d92bc6 navbar resize fix 2014-10-23 11:55:29 +03:00
Yuri Kuznetsov
0f9c32869c Merge branch 'master' of https://github.com/espocrm/espocrm 2014-10-23 11:40:43 +03:00
Yuri Kuznetsov
8cea6559c1 Merge pull request #10 from espocrm/revert-8-dropdown_zindex
Revert "Fix z-index issue with navbar menus on iPads / media query = 768...
2014-10-23 11:40:24 +03:00
Yuri Kuznetsov
3c6d383e08 Revert "Fix z-index issue with navbar menus on iPads / media query = 768px" 2014-10-23 11:39:57 +03:00
Yuri Kuznetsov
cdffb85df0 Merge branch 'master' of ssh://172.20.0.1/var/git/espo/backend 2014-10-23 11:06:33 +03:00
Yuri Kuznetsov
884499ee58 fix ru_RU 2014-10-23 10:46:15 +03:00
Taras Machyshyn
8462632969 'Loaders' improving 2014-10-22 11:11:47 +03:00
Yuri Kuznetsov
84e5fd762d Merge pull request #8 from alasdaircr/dropdown_zindex
Fix z-index issue with navbar menus on iPads / media query = 768px
2014-10-22 09:59:36 +03:00
Alasdair Campbell
eecda0d839 Fix z-index issue with navbar menus on iPads / media query = 768px 2014-10-21 21:33:03 +01:00
Yuri Kuznetsov
0829425aa4 Merge pull request #7 from alasdaircr/float_fix
Fix zero floats being treated as false, fixes #6
2014-10-21 15:54:04 +03:00
Alasdair Campbell
be6c21e28c Fix zero floats being treated as false, fixes #6 2014-10-21 13:00:42 +01:00
Yuri Kuznetsov
32a2df544f send email test 2014-10-20 16:48:47 +03:00
Yuri Kuznetsov
459b6eccb6 add change label 2014-10-20 12:40:05 +03:00
Yuri Kuznetsov
bfd611d6fe no smtp sutup message 2014-10-20 12:38:25 +03:00
Yuri Kuznetsov
dadd8c8474 chanve version 2014-10-20 11:15:24 +03:00
Yuri Kuznetsov
dc3f6080c9 replace tabs with spaces 2014-10-20 11:13:16 +03:00
Yuri Kuznetsov
f062c08b31 import email with empty subjects 2014-10-17 15:12:41 +03:00
Yuri Kuznetsov
90a287af64 Merge branch 'hotfix/2.6.1' 2014-10-17 14:51:36 +03:00
Yuri Kuznetsov
fd9d6d2220 email search: fix duplicates 2014-10-17 14:50:08 +03:00
Yuri Kuznetsov
1bb877c9b7 Merge branch 'hotfix/2.6.1' 2014-10-17 11:54:34 +03:00
Yuri Kuznetsov
2199f0d483 fix activities 2014-10-17 11:53:59 +03:00
Yuri Kuznetsov
b839c76a1e task and call complete actions 2014-10-15 16:57:51 +03:00
Yuri Kuznetsov
9ced6d7427 Merge branch 'master' of ssh://172.20.0.1/var/git/espo/backend 2014-10-15 15:28:12 +03:00
Yuri Kuznetsov
260d74882e change layouts 2014-10-15 15:21:12 +03:00
Taras Machyshyn
7835d74efe Merge branch 'master' of ssh://172.20.0.1/var/git/espo/backend 2014-10-15 15:13:53 +03:00
Taras Machyshyn
66108324be password hash minor changes 2014-10-15 15:13:38 +03:00
Yuri Kuznetsov
b1b9dde29f Merge branch 'master' of ssh://172.20.0.1/var/git/espo/backend 2014-10-15 15:03:25 +03:00
Yuri Kuznetsov
c67f2b20d4 layout manager: ability to make call full width wide 2014-10-15 15:01:17 +03:00
Taras Machyshyn
d78dd9cedb Merge branch 'master' of ssh://172.20.0.1/var/git/espo/backend 2014-10-15 14:59:53 +03:00
Taras Machyshyn
8330bb12f1 changed hash algorithm of user's password 2014-10-15 14:59:34 +03:00
Yuri Kuznetsov
ceef826893 translate bool as boolean 2014-10-15 12:06:03 +03:00
Yuri Kuznetsov
675975f763 reset preferences to defaults 2014-10-15 11:55:40 +03:00
Yuri Kuznetsov
3fd2382741 unlink method 2014-10-15 11:46:44 +03:00
Yuri Kuznetsov
c70ab7c127 convert lead layout in manager 2014-10-15 11:17:44 +03:00
Yuri Kuznetsov
3cd9d49b4c crypt passwords 2014-10-14 17:50:33 +03:00
Yuri Kuznetsov
8fafe2c47f add User variable to Email Template 2014-10-14 15:23:39 +03:00
Yuri Kuznetsov
b12cf2e21b probabilityMap move to metadata 2014-10-14 15:15:43 +03:00
Yuri Kuznetsov
6f22452cd9 change default dashboard layout 2014-10-14 12:04:31 +03:00
Yuri Kuznetsov
3e0eaf1fa5 avoid 403 for list dashlets 2014-10-14 11:18:09 +03:00
Yuri Kuznetsov
4f7946fe25 notRemovable option for Search.Filter 2014-10-14 10:57:22 +03:00
Yuri Kuznetsov
d1fd916be0 fix select2 css 2014-10-14 10:50:59 +03:00
Yuri Kuznetsov
b3ccabcde0 fix css 2014-10-13 17:43:11 +03:00
Yuri Kuznetsov
c0e6d1191c multiEnum field 2014-10-13 17:30:27 +03:00
Yuri Kuznetsov
b561c94ad1 de_DE change 2014-10-13 15:18:38 +03:00
Yuri Kuznetsov
ee1f71fff3 Merge branch 'hotfix/2.6.1' 2014-10-13 12:03:17 +03:00
Yuri Kuznetsov
b39aa01ac9 add labels to german language 2014-10-13 12:01:36 +03:00
Yuri Kuznetsov
b8263295c2 fix readme 2014-10-10 17:23:06 +03:00
Yuri Kuznetsov
56ae7e5d3c change readme 2014-10-10 17:08:49 +03:00
Yuri Kuznetsov
156e69517f fix send invitations for calls 2014-10-10 16:12:54 +03:00
Yuri Kuznetsov
359a4ecc45 Merge branch 'master' into stable 2014-10-10 15:38:05 +03:00
Yuri Kuznetsov
2538f8befc fix send password to new user 2014-10-10 12:08:17 +03:00
Yuri Kuznetsov
3bb0fdbf91 Merge branch 'master' of ssh://172.20.0.1/var/git/espo/backend 2014-10-10 11:40:46 +03:00
Taras Machyshyn
caec038c2c Merge branch 'master' of ssh://172.20.0.1/var/git/espo/backend 2014-10-10 11:19:24 +03:00
Taras Machyshyn
331602e32b fixed notices 2014-10-10 11:19:08 +03:00
Yuri Kuznetsov
cdbc91afcd phone number to export 2014-10-10 11:08:02 +03:00
Yuri Kuznetsov
b2fb451620 Merge branch 'master' of ssh://172.20.0.1/var/git/espo/backend 2014-10-10 10:50:23 +03:00
Yuri Kuznetsov
a548245fca import improvements 2014-10-10 10:50:07 +03:00
Taras Machyshyn
d12ae68bf4 array merge fixes 2014-10-10 10:33:04 +03:00
Yuri Kuznetsov
bfb0fcba0c leading zero for dates 2014-10-09 19:11:11 +03:00
Yuri Kuznetsov
40e639f4ba change diff.js 2014-10-09 17:29:50 +03:00
Yuri Kuznetsov
831b240f99 Merge branch 'master' of ssh://172.20.0.1/var/git/espo/backend 2014-10-09 17:25:10 +03:00
Taras Machyshyn
363aea4c96 fileManager fixes 2014-10-09 17:24:48 +03:00
Yuri Kuznetsov
8bbd918c51 remove isOverdue from task dashlet 2014-10-09 16:03:30 +03:00
Yuri Kuznetsov
304078420c Merge branch 'master' of ssh://172.20.0.1/var/git/espo/backend 2014-10-09 15:45:03 +03:00
Yuri Kuznetsov
6a7a7d9f04 userfriendly date and datetime 2014-10-09 15:43:35 +03:00
Taras Machyshyn
fbeb19e69f Merge branch 'master' of ssh://172.20.0.1/var/git/espo/backend 2014-10-09 13:11:46 +03:00
Taras Machyshyn
7cfc539ce9 installer: security improvements 2014-10-09 13:11:25 +03:00
Yuri Kuznetsov
b65e23edfe change main.html 2014-10-09 12:12:57 +03:00
Yuri Kuznetsov
3ba308e513 weighted amount 2014-10-09 11:33:26 +03:00
Yuri Kuznetsov
6379198019 export delimited ; 2014-10-09 11:32:22 +03:00
Yuri Kuznetsov
016992573f change version 2014-10-08 17:55:12 +03:00
Yuri Kuznetsov
96e827d64d Merge branch 'master' of ssh://172.20.0.1/var/git/espo/backend 2014-10-08 16:45:13 +03:00
Yuri Kuznetsov
cae40465f5 query aggregation and distrinct 2014-10-08 16:44:58 +03:00
Taras Machyshyn
d2669dba5e installer: added possibility to install EspoCRM for unbuilt version 2014-10-08 12:58:00 +03:00
Taras Machyshyn
e3aa0a40fe tests improvements 2014-10-08 12:12:53 +03:00
Taras Machyshyn
8dd9fb089a tests: remove unnecessary cache files 2014-10-08 11:38:39 +03:00
Taras Machyshyn
e2e384dd76 Merge branch 'master' of ssh://172.20.0.1/var/git/espo/backend 2014-10-08 11:11:35 +03:00
Taras Machyshyn
8a4e36a02d merge: fixed 'null' values 2014-10-08 11:11:21 +03:00
Yuri Kuznetsov
c4037c0333 Merge branch 'master' of ssh://172.20.0.1/var/git/espo/backend 2014-10-08 11:04:39 +03:00
Yuri Kuznetsov
cb3200f5dd fix logo issue 2014-10-08 10:47:42 +03:00
Taras Machyshyn
e6def8bd4b Merge branch 'master' of ssh://172.20.0.1/var/git/espo/backend 2014-10-07 17:45:39 +03:00
Taras Machyshyn
218ce00930 Extension Manager improvements 2014-10-07 17:45:20 +03:00
Yuri Kuznetsov
ad12f78668 change date ranges order 2014-10-07 10:42:51 +03:00
Yuri Kuznetsov
ea07895f02 Merge branch 'master' of ssh://172.20.0.1/var/git/espo/backend 2014-10-06 17:51:38 +03:00
Yuri Kuznetsov
023ab86684 added new date ranges 2014-10-06 17:51:24 +03:00
Taras Machyshyn
dc6ba1128d tests corrections 2014-10-06 16:04:24 +03:00
Taras Machyshyn
40e6c6a648 fix get server type 2014-10-06 13:27:48 +03:00
Taras Machyshyn
982e3bd9b7 .gitignore changes 2014-10-06 13:19:28 +03:00
Taras Machyshyn
efefd8864c installer improvements 2014-10-06 10:25:07 +03:00
Taras Machyshyn
ca40ed79ee added a new item to .gitignore 2014-10-06 10:20:26 +03:00
Taras Machyshyn
07866a266f added metadata merge with '__APPEND__' 2014-10-03 17:16:47 +03:00
Yuri Kuznetsov
5007b090fd fix typo 2014-10-03 10:26:17 +03:00
Yuri Kuznetsov
95f6b8cd5c dashlet 2x height 2014-10-02 19:17:29 +03:00
Yuri Kuznetsov
93f5da1a62 cleanup 2014-10-02 12:30:15 +03:00
Yuri Kuznetsov
8632064bf7 mardown support 2014-10-02 12:25:22 +03:00
Yuri Kuznetsov
544ad898a3 Merge branch 'master' of ssh://172.20.0.1/var/git/espo/backend 2014-10-01 16:22:43 +03:00
Yuri Kuznetsov
ea17b967c2 fix query 2014-10-01 16:22:32 +03:00
Taras Machyshyn
8db78f61d6 IIS: added unknown file extensions 2014-10-01 13:02:02 +03:00
Yuri Kuznetsov
161673b88a fix typo 2014-10-01 12:00:53 +03:00
Yuri Kuznetsov
6d81d9f6b2 Merge branch 'hotfix/2.5.3' 2014-10-01 11:58:30 +03:00
Yuri Kuznetsov
f3ed8a67bc fix typo 2014-10-01 11:04:05 +03:00
Yuri Kuznetsov
06702345da fix readme 2014-10-01 11:02:47 +03:00
Yuri Kuznetsov
a5cb57dcfd update readme 2014-10-01 11:00:09 +03:00
Yuri Kuznetsov
36a4e48a2b Merge branch 'master' of ssh://172.20.0.1/var/git/espo/backend 2014-10-01 10:38:04 +03:00
Yuri Kuznetsov
074bd5a724 remove vendors 2014-10-01 10:36:23 +03:00
Taras Machyshyn
36b1fbff36 merge: Extension Manager improvements and fixes 2014-09-30 18:04:34 +03:00
Taras Machyshyn
620e695d7e Extension Manager improvements and fixes 2014-09-30 17:59:17 +03:00
Yuri Kuznetsov
74dc2c07ea remove extension 2014-09-30 17:44:03 +03:00
Yuri Kuznetsov
3b17d0ade3 show uninstall error 2014-09-30 15:22:29 +03:00
Yuri Kuznetsov
07cf316c9c fix readme 2014-09-30 12:40:58 +03:00
Yuri Kuznetsov
fa17104d13 readme changes 2014-09-30 12:39:41 +03:00
Yuri Kuznetsov
274663e426 readmy 2014-09-30 12:33:39 +03:00
Yuri Kuznetsov
ec338fb0fd extension client 3 2014-09-30 11:37:31 +03:00
Yuri Kuznetsov
0093fb6670 fix json 2014-09-30 11:21:14 +03:00
Yuri Kuznetsov
8d36142ad1 extension uninstall 2014-09-30 11:20:37 +03:00
Yuri Kuznetsov
8bcbec1e11 Merge branch 'master' of ssh://172.20.0.1/var/git/espo/backend 2014-09-30 11:15:03 +03:00
Yuri Kuznetsov
a1a8c157a0 extension clientside 2014-09-30 11:14:49 +03:00
Taras Machyshyn
7349edcb0c Merge branch 'master' of ssh://172.20.0.1/var/git/espo/backend 2014-09-30 10:26:10 +03:00
Taras Machyshyn
594eec29ce Extension: remove required acceptableVersions option 2014-09-30 10:25:47 +03:00
Yuri Kuznetsov
ff9db53f4f Merge branch 'master' of ssh://172.20.0.1/var/git/espo/backend 2014-09-29 18:13:54 +03:00
Yuri Kuznetsov
2f3fe50aff remove spare query object 2014-09-29 18:13:37 +03:00
Yuri Kuznetsov
1e1a8c0ad0 Merge pull request #3 from alasdaircr/log_spew
Fix log pollution
2014-09-29 18:12:42 +03:00
Alasdair Campbell
03196e5728 Fix log spew 2014-09-29 16:03:00 +01:00
Taras Machyshyn
c3bbdb2722 added deletePackage action for Extension controller 2014-09-29 17:19:43 +03:00
Taras Machyshyn
9e0e743dc5 Added Extension Manager 2014-09-29 17:14:55 +03:00
Yuri Kuznetsov
a565b9c981 fix pt_PR language 2014-09-29 16:04:51 +03:00
Yuri Kuznetsov
d85135dd69 ru_RU lang fixes 2014-09-29 16:04:06 +03:00
Yuri Kuznetsov
380304dca1 Merge branch 'master' of https://github.com/espocrm/espocrm 2014-09-29 16:02:09 +03:00
Yuri Kuznetsov
c95c564961 Merge pull request #1 from paladin80/master
Russian localization
2014-09-29 16:00:45 +03:00
Serghei Burtsev
9022aebc7e Russian localization 2014-09-29 16:34:37 +04:00
Yuri Kuznetsov
b91d6dc2cf favicon 2014-09-29 15:04:00 +03:00
Yuri Kuznetsov
1a2a8e6b9e query functions 2014-09-29 12:51:39 +03:00
Yuri Kuznetsov
6bf1de18e7 multiple order by 2014-09-29 12:25:43 +03:00
Yuri Kuznetsov
77fba6eb88 query builder: foreign fields 2014-09-29 12:11:03 +03:00
Yuri Kuznetsov
2e5cef2abb change currency converted 2014-09-26 17:54:39 +03:00
Yuri Kuznetsov
2dbb44eb16 currency type improvement 2014-09-26 17:17:35 +03:00
Yuri Kuznetsov
6dc23517cc fix date format in email template 2014-09-26 13:13:38 +03:00
Yuri Kuznetsov
6c74281190 add headers 2014-09-25 18:16:41 +03:00
Yuri Kuznetsov
fa993957a1 remove spaces 2014-09-25 18:13:59 +03:00
Yuri Kuznetsov
bfa16ecabe add readme 2014-09-25 16:18:48 +03:00
Yuri Kuznetsov
c359b450f8 revert prev 2014-09-25 15:04:10 +03:00
Yuri Kuznetsov
a638713e80 dashlet chart color 2014-09-25 15:03:18 +03:00
Yuri Kuznetsov
86715684e1 query 3 2014-09-24 17:25:43 +03:00
Yuri Kuznetsov
b79ea12b44 query 2 2014-09-24 16:18:36 +03:00
Yuri Kuznetsov
9f24998184 query 1 2014-09-24 13:55:39 +03:00
Yuri Kuznetsov
88018bf500 foreign field metadata 2014-09-24 09:41:59 +03:00
Yuri Kuznetsov
f95436f513 footer link title 2014-09-23 17:56:31 +03:00
Yuri Kuznetsov
fa8c5adc25 calendar task w/o date end 2014-09-23 16:10:01 +03:00
Taras Machyshyn
0ee966eddd installer: added recommended settings, other impovements 2014-09-23 16:06:29 +03:00
Yuri Kuznetsov
f723882f60 ORM change alias logic 2014-09-23 16:00:07 +03:00
Yuri Kuznetsov
8333c51e42 actual tasks 2014-09-23 10:41:34 +03:00
Yuri Kuznetsov
6abc64fcb2 fix mapper json type 2014-09-19 18:45:03 +03:00
Yuri Kuznetsov
837b324fe8 oauth fix 2014-09-19 18:12:44 +03:00
Yuri Kuznetsov
6c56269f18 remove contract 2014-09-19 11:25:11 +03:00
Yuri Kuznetsov
1101d717f2 extensions 2 2014-09-18 15:10:39 +03:00
Yuri Kuznetsov
8e177749ef extensions 1 2014-09-18 12:22:42 +03:00
Yuri Kuznetsov
ce30c759a3 layout change 2014-09-18 10:46:28 +03:00
Yuri Kuznetsov
56abf49301 layout change 2014-09-18 10:44:44 +03:00
Yuri Kuznetsov
f726881f48 contracts 2014-09-17 17:43:17 +03:00
Taras Machyshyn
d908da46cb add helper about RewriteBase into .htaccess 2014-09-17 17:31:49 +03:00
Yuri Kuznetsov
230428456a documents 2014-09-17 15:14:00 +03:00
Yuri Kuznetsov
fda8de500c sales pipeline tick position 2014-09-16 18:47:19 +03:00
Yuri Kuznetsov
583f3d33e8 sales pipeline impove 2014-09-16 18:45:24 +03:00
Yuri Kuznetsov
d0abed98d1 jsonObject more 2014-09-16 16:09:20 +03:00
Yuri Kuznetsov
38b820739d cron data jsonObject 2014-09-16 15:56:33 +03:00
Taras Machyshyn
0ccda10de8 installer: fixed issues on os windows 2014-09-16 15:52:46 +03:00
Yuri Kuznetsov
5358984b2d do not notify if mentioned 2014-09-16 15:34:17 +03:00
Yuri Kuznetsov
e972276487 mention users 3 2014-09-16 15:15:00 +03:00
Taras Machyshyn
91d4d9bcf9 installer improvements 2014-09-16 12:53:10 +03:00
Yuri Kuznetsov
7f3b489832 mention users 2 2014-09-16 12:38:11 +03:00
Taras Machyshyn
107584e0f9 DBAL: column length can be increased only 2014-09-16 11:35:38 +03:00
Yuri Kuznetsov
0bf33e6110 cleanup 2014-09-16 10:36:21 +03:00
Yuri Kuznetsov
9aaedea764 fix dashlet 2014-09-15 17:53:32 +03:00
Yuri Kuznetsov
33c3594273 jsonObject 2014-09-15 17:47:22 +03:00
Yuri Kuznetsov
72824c2796 textcomplete cursor 2014-09-15 16:34:44 +03:00
Yuri Kuznetsov
bf56c5fe60 fix textcomplete 2014-09-15 16:27:44 +03:00
Yuri Kuznetsov
5c93b49f6a userName restrictions 2014-09-15 16:18:17 +03:00
Yuri Kuznetsov
f60fd168e6 mention user 1 2014-09-15 15:59:46 +03:00
Taras Machyshyn
1399913606 fixed htaccess RedirectMatch 403 rule 2014-09-15 12:35:32 +03:00
Yuri Kuznetsov
b233ab506d merge with 2.5.3 2014-09-15 11:52:50 +03:00
Yuri Kuznetsov
053793be9c upgrade message 2014-09-15 10:58:15 +03:00
Yuri Kuznetsov
53503fa615 -21px margin 2014-09-15 10:48:08 +03:00
Yuri Kuznetsov
ed4081596b q search by testFilter fields 2014-09-15 10:45:32 +03:00
Yuri Kuznetsov
6bdfb30c33 fix invitation email 2014-09-15 10:33:44 +03:00
Yuri Kuznetsov
322d4cffcf fix graphs colors 2014-09-12 17:26:19 +03:00
Yuri Kuznetsov
1a9e03d540 Merge branch 'hotfix/2.5.3' 2014-09-12 17:07:13 +03:00
Yuri Kuznetsov
cff5e0f688 Merge branch 'hotfix/2.5.3' of ssh://172.20.0.1/var/git/espo/backend into hotfix/2.5.3 2014-09-12 17:04:56 +03:00
Yuri Kuznetsov
85fb55c999 load team for entity in checkTeam 2014-09-12 17:04:44 +03:00
Taras Machyshyn
b944a98cf6 FieldManager: no rebuild when changing a label 2014-09-12 16:44:42 +03:00
Yuri Kuznetsov
9c73f83353 fix post note acl 2014-09-12 16:10:12 +03:00
Yuri Kuznetsov
5caa29b948 css 2014-09-12 16:06:17 +03:00
Yuri Kuznetsov
71efbe8eea dashlet colors 2014-09-12 14:32:36 +03:00
Yuri Kuznetsov
81077a1c38 dashlet colors 2014-09-12 12:53:22 +03:00
Yuri Kuznetsov
32e882780e oauth 2014-09-12 12:46:18 +03:00
Yuri Kuznetsov
23a373f2cf Merge branch 'stable' 2014-09-11 18:26:46 +03:00
Yuri Kuznetsov
0a2c79ba81 version 2014-09-11 18:17:15 +03:00
Yuri Kuznetsov
5360ba0147 fix dutch 2014-09-11 18:14:30 +03:00
Yuri Kuznetsov
6620254d00 fix lang 2014-09-11 18:12:27 +03:00
Yuri Kuznetsov
f6eb0bcce8 Merge branch 'hotfix/2.5.2' of ssh://172.20.0.1/var/git/espo/backend into hotfix/2.5.2 2014-09-11 18:06:10 +03:00
Yuri Kuznetsov
c1116ff5dc fix email account 2014-09-11 18:05:58 +03:00
Yuri Kuznetsov
330fef673a oauth d 2014-09-11 17:36:58 +03:00
Taras Machyshyn
7dcdfcd231 DBAL fixed changing column length 2014-09-11 15:20:18 +03:00
Taras Machyshyn
0eadb9af69 log filename if invalid json file 2014-09-11 14:07:12 +03:00
Yuri Kuznetsov
a269c0c96c oauth dev 2014-09-11 10:20:46 +03:00
Yuri Kuznetsov
ed37380d8e oauth 2014-09-10 18:27:15 +03:00
Yuri Kuznetsov
fdef9838d1 Merge branch 'hotfix/2.5.2' 2014-09-10 11:20:06 +03:00
Yuri Kuznetsov
3c3518b857 fix global search panel 2014-09-10 11:19:14 +03:00
Yuri Kuznetsov
e85f21da92 oauth c 2014-09-10 10:55:23 +03:00
Yuri Kuznetsov
f3ab0a734c css 2014-09-09 15:11:01 +03:00
Yuri Kuznetsov
33adc67dee version 2014-09-09 15:06:12 +03:00
Yuri Kuznetsov
18e475e1b6 fix clear cache 2014-09-09 15:05:18 +03:00
Yuri Kuznetsov
438c0f7edd upgrade full calendar 2014-09-09 12:20:56 +03:00
Yuri Kuznetsov
3159c9d288 libs to metadata 2014-09-09 11:50:11 +03:00
Yuri Kuznetsov
fe0f93784b fix lib loader 2014-09-09 11:21:54 +03:00
Yuri Kuznetsov
2d237eae29 remove isHtml dependency 2014-09-09 11:14:29 +03:00
Yuri Kuznetsov
747aa2d882 dashlet ch 2014-09-09 11:07:24 +03:00
Yuri Kuznetsov
46a7119ce1 month names in sales by month dashlet 2014-09-09 11:00:19 +03:00
Yuri Kuznetsov
c18342694f change max resolution 2014-09-09 10:54:02 +03:00
Yuri Kuznetsov
bb47b70f31 fix tooltip 2014-09-09 10:48:02 +03:00
Yuri Kuznetsov
07767b2dae fix ref 2014-09-05 17:26:21 +03:00
Yuri Kuznetsov
88037c8291 Merge branch 'release/2.5' into stable 2014-09-05 17:05:40 +03:00
Taras Machyshyn
ee03c686ca cron job chnages: remove duplicate jobs, check if ruuning 2014-09-05 15:27:17 +03:00
Yuri Kuznetsov
78140f7d5e change default dashlet layout 2014-09-05 14:59:33 +03:00
Yuri Kuznetsov
549acfd032 copy billing address 2014-09-05 14:52:43 +03:00
Yuri Kuznetsov
e4dab33792 acceptance status 2014-09-05 12:41:28 +03:00
Yuri Kuznetsov
287f95a8ac sort entity list in field/layout manager 2014-09-05 11:30:20 +03:00
Yuri Kuznetsov
4951f8464e role acl table 2014-09-05 11:27:28 +03:00
Yuri Kuznetsov
8ed9b9ebd2 fix get user Acl 2014-09-05 11:20:12 +03:00
Yuri Kuznetsov
96ed9612d4 email address lookup minChar 1 2014-09-05 11:11:35 +03:00
Yuri Kuznetsov
1fd77a4c13 link field can be w/o link 2014-09-05 10:58:04 +03:00
Yuri Kuznetsov
2390ac10a8 dont rerender if edit inline edit 2014-09-05 10:46:58 +03:00
Yuri Kuznetsov
03572ecaad footer padding 2014-09-05 10:28:43 +03:00
Yuri Kuznetsov
c1ac692304 version 2014-09-05 10:21:23 +03:00
Yuri Kuznetsov
f371090bde Merge branch 'master' of ssh://172.20.0.1/var/git/espo/backend 2014-09-05 10:20:45 +03:00
Yuri Kuznetsov
e28341f154 pl_PL 2014-09-05 10:20:27 +03:00
Taras Machyshyn
870f871ceb changed allowed params of 'link' metadata 2014-09-04 15:55:54 +03:00
Yuri Kuznetsov
c18d892a4e bottom panel label 2014-09-04 13:05:27 +03:00
Yuri Kuznetsov
c8bfd1c6dd fix side field label 2014-09-04 13:01:49 +03:00
Yuri Kuznetsov
c582860d5c fix notification about link appears twice 2014-09-04 13:00:11 +03:00
Yuri Kuznetsov
1796db30fa external account 1 2014-09-02 18:26:48 +03:00
Yuri Kuznetsov
25aa0ec564 show/hide integration fields 2014-09-01 18:17:35 +03:00
Yuri Kuznetsov
f3dc904c65 helpText 2014-09-01 17:36:54 +03:00
Yuri Kuznetsov
343d33e741 integrations 1 2014-09-01 16:59:59 +03:00
Yuri Kuznetsov
276480dcfa opp reports 2014-08-29 11:40:28 +03:00
Yuri Kuznetsov
b00b725af5 text earch 2014-08-29 11:26:50 +03:00
Yuri Kuznetsov
ab71ced531 full form keeps attributes 2014-08-29 11:06:09 +03:00
Yuri Kuznetsov
ba7988a842 ssl-port dependance 2014-08-29 10:51:46 +03:00
Yuri Kuznetsov
e1355acda1 email account 5 2014-08-28 17:15:44 +03:00
Yuri Kuznetsov
1853f4f113 fix 2014-08-27 18:00:14 +03:00
Yuri Kuznetsov
da677cfae8 fix 2014-08-27 17:56:37 +03:00
Yuri Kuznetsov
272bccc2fd fix 2014-08-27 17:41:29 +03:00
Yuri Kuznetsov
5372155773 email account 3 2014-08-27 17:34:32 +03:00
Yuri Kuznetsov
e1579295da email account 2014-08-27 17:01:31 +03:00
Yuri Kuznetsov
cc708e03d1 email account 1 2014-08-27 12:07:59 +03:00
Yuri Kuznetsov
34e91958d6 hide preferences password 2014-08-27 10:55:08 +03:00
Yuri Kuznetsov
928e4c2fb5 allowQuickEdit 2014-08-26 17:19:14 +03:00
Yuri Kuznetsov
cf86fcda85 email resrict fields 2014-08-26 15:39:56 +03:00
Yuri Kuznetsov
db3b36a639 fix email fields view 2014-08-26 13:35:33 +03:00
Yuri Kuznetsov
a4a731437e fix email fields 2014-08-26 13:19:35 +03:00
Yuri Kuznetsov
51f4c7fa09 fix field re-render 2014-08-26 13:19:25 +03:00
Yuri Kuznetsov
cbce4fc327 fix datetime short 2014-08-26 12:06:02 +03:00
Yuri Kuznetsov
4e953f6fa8 add user to address seek 2014-08-26 11:26:56 +03:00
Yuri Kuznetsov
0ed0420a4b fix email 2014-08-26 11:20:49 +03:00
Yuri Kuznetsov
16961795af email address field 2014-08-25 17:00:55 +03:00
Yuri Kuznetsov
c52c7fed59 acl check 2014-08-22 18:23:57 +03:00
Yuri Kuznetsov
95c00fc49d reply action 2014-08-22 18:22:52 +03:00
Yuri Kuznetsov
9f8606dd06 fix datetime 2014-08-22 18:05:03 +03:00
Yuri Kuznetsov
b33dc9baae link multiple select 2014-08-22 17:38:04 +03:00
Yuri Kuznetsov
8cb95f1b0e user filter by teams 2014-08-22 17:32:59 +03:00
Yuri Kuznetsov
86cd1ab864 blockquote size 2014-08-22 17:14:29 +03:00
Yuri Kuznetsov
df842f3e3e forward attachments 2014-08-22 17:10:04 +03:00
Yuri Kuznetsov
572455ecf6 attachment roles 2014-08-22 16:45:01 +03:00
Yuri Kuznetsov
7692f9e3ad align list 2014-08-22 16:16:00 +03:00
Yuri Kuznetsov
be0c1d8ab1 stream date 2014-08-22 15:53:00 +03:00
Yuri Kuznetsov
4a6c3d9e18 date time short fix and side 2014-08-22 15:50:11 +03:00
Yuri Kuznetsov
e0fdbd90fd datetime short 2014-08-22 15:37:22 +03:00
Yuri Kuznetsov
18a3f2658a email improve 2014-08-22 14:45:49 +03:00
Yuri Kuznetsov
80ee06ec1d email reply 2014-08-22 12:34:26 +03:00
Yuri Kuznetsov
f16adeed99 fornawesome 2014-08-22 11:33:08 +03:00
Yuri Kuznetsov
9ca39f3559 email create in menu 2014-08-22 11:06:00 +03:00
Yuri Kuznetsov
19285372d6 default search data 2014-08-22 11:02:21 +03:00
Yuri Kuznetsov
61df6bec45 cleanup 2014-08-22 10:41:34 +03:00
Yuri Kuznetsov
8904d4ddaf acl solid in metadata 2014-08-22 10:20:24 +03:00
Yuri Kuznetsov
ca5fba97df Merge branch 'hotfix/2.4.1' 2014-08-21 18:14:30 +03:00
Yuri Kuznetsov
fa755efefb email layouts 2014-08-21 18:14:21 +03:00
Yuri Kuznetsov
d6085f4985 plain text email 2014-08-21 16:02:57 +03:00
Yuri Kuznetsov
4c01e9329d timeout 0 2014-08-21 12:37:28 +03:00
Yuri Kuznetsov
9813eeb5bc nl lang 2014-08-21 11:32:11 +03:00
Yuri Kuznetsov
09d571a639 de lang 2014-08-21 11:30:09 +03:00
Yuri Kuznetsov
fffd44316e Merge branch 'hotfix/2.4.1' 2014-08-20 16:55:24 +03:00
Yuri Kuznetsov
a704830b86 fix inline edit for hidden fields 2014-08-20 16:55:05 +03:00
Yuri Kuznetsov
7910f71428 Merge branch 'hotfix/2.4.1' 2014-08-20 15:51:37 +03:00
Yuri Kuznetsov
52dcc51f4f version 2014-08-20 14:20:44 +03:00
Yuri Kuznetsov
f870ded9e0 rename default and class properties 2014-08-20 11:45:02 +03:00
Yuri Kuznetsov
224c72c875 remove upload timeout 2014-08-20 10:51:51 +03:00
Yuri Kuznetsov
ed50802073 Merge branch 'master' of ssh://172.20.0.1/var/git/espo/backend 2014-08-19 17:34:10 +03:00
Yuri Kuznetsov
1f5036eb5f small refactor utils/database 2014-08-19 16:19:54 +03:00
Yuri Kuznetsov
701a60a07f autocomlate off 2014-08-19 12:38:24 +03:00
Yuri Kuznetsov
c760f7364c some refactor 2014-08-19 12:25:41 +03:00
Yuri Kuznetsov
4c28409a36 showNewRecords for stream 2014-08-19 11:59:30 +03:00
Taras Machyshyn
e932681166 install improvements (fix 'pdo_mysql' checking, turkish lang file) 2014-08-18 16:09:35 +03:00
Taras Machyshyn
a8209488ee install improvements (fix 'pdo_mysql' checking, turkish lang file) 2014-08-18 16:07:46 +03:00
Taras Machyshyn
d48642ca81 Merge branch 'master' of ssh://172.20.0.1/var/git/espo/backend 2014-08-18 16:03:14 +03:00
Taras Machyshyn
6561c4b6c2 fix PATCH method 2014-08-18 16:02:58 +03:00
Yuri Kuznetsov
4f5f84c8f7 add phone/email button manage 2014-08-18 15:42:06 +03:00
Yuri Kuznetsov
56a04336fe Merge branch 'master' into stable 2014-08-15 17:43:02 +03:00
Yuri Kuznetsov
1814529d3e Merge branch 'master' of ssh://172.20.0.1/var/git/espo/backend 2014-08-15 17:13:52 +03:00
Taras Machyshyn
1dbe2d9eac installer: missing files 2014-08-15 17:12:26 +03:00
Taras Machyshyn
4ca099afc4 fix installation problem 2014-08-15 16:57:13 +03:00
Yuri Kuznetsov
7ca09bc893 grunt change 2014-08-15 16:22:44 +03:00
Yuri Kuznetsov
0a4a8c956a Merge branch 'master' of ssh://172.20.0.1/var/git/espo/backend 2014-08-15 16:17:28 +03:00
Yuri Kuznetsov
6f2a7ae08f fix Show More 2014-08-15 16:17:23 +03:00
Taras Machyshyn
45a9dd1226 Merge branch 'master' of ssh://172.20.0.1/var/git/espo/backend 2014-08-15 16:10:52 +03:00
Taras Machyshyn
9d904171c9 added block rules for IIS 2014-08-15 16:10:23 +03:00
Yuri Kuznetsov
53abea7cdd fix reports 2014-08-15 16:01:35 +03:00
Yuri Kuznetsov
6427604724 Merge branch 'master' of ssh://172.20.0.1/var/git/espo/backend 2014-08-15 15:33:07 +03:00
Taras Machyshyn
0d72dc7c2f changes rules for nginx server 2014-08-15 15:32:33 +03:00
Yuri Kuznetsov
9ee5a98ff4 fix label 2014-08-15 15:06:01 +03:00
Taras Machyshyn
3f0c92744c install improvements 2014-08-15 13:27:19 +03:00
Taras Machyshyn
7a87749c4c fix problem with MySQL 'int' 2014-08-15 13:18:44 +03:00
Yuri Kuznetsov
0eaab6b7ee userName unique fix 2014-08-15 11:22:57 +03:00
Yuri Kuznetsov
b52722565a Merge branch 'master' of ssh://172.20.0.1/var/git/espo/backend 2014-08-14 17:13:12 +03:00
Yuri Kuznetsov
80fd2a2006 fix tooltips 2014-08-14 17:13:08 +03:00
Yuri Kuznetsov
1c1fdffb7d some padding 2014-08-14 16:29:50 +03:00
Yuri Kuznetsov
53481890db pdf shown 2014-08-14 16:25:54 +03:00
Yuri Kuznetsov
b82a3d0f31 stream post padding 2014-08-14 16:17:39 +03:00
Yuri Kuznetsov
1700b27501 fix revert 2014-08-14 15:30:14 +03:00
Yuri Kuznetsov
635064e116 revert import imporve 2014-08-14 14:46:54 +03:00
Yuri Kuznetsov
f6e45d8a68 fix import id 2014-08-14 13:40:41 +03:00
Yuri Kuznetsov
ee0cf4bca5 fix see more 2014-08-14 13:31:04 +03:00
Taras Machyshyn
ae98290721 Merge branch 'master' of ssh://172.20.0.1/var/git/espo/backend 2014-08-14 13:20:40 +03:00
Taras Machyshyn
24bbcf0e0a installer minor fixes 2014-08-14 13:20:06 +03:00
Yuri Kuznetsov
23b1945a3e change label 2014-08-14 13:19:42 +03:00
Yuri Kuznetsov
e1fe3c03dd Merge branch 'master' of ssh://172.20.0.1/var/git/espo/backend 2014-08-14 13:17:05 +03:00
Yuri Kuznetsov
7e0034f674 see more 2014-08-14 13:13:05 +03:00
Yuri Kuznetsov
d73cfbca53 strem post 2014-08-14 12:40:53 +03:00
Taras Machyshyn
3eec2b2a33 fixed wrong default TLS port 2014-08-14 11:58:43 +03:00
Yuri Kuznetsov
d60dc744e6 no clean js 2014-08-14 11:29:54 +03:00
Yuri Kuznetsov
bd66211c3c grunt fix 2014-08-14 11:27:58 +03:00
Yuri Kuznetsov
2f341c8967 fix grunt 2014-08-14 11:21:01 +03:00
Yuri Kuznetsov
5c7612c9cf version and grunt 2014-08-14 11:19:46 +03:00
Taras Machyshyn
b41c0f34aa Merge branch 'master' of ssh://172.20.0.1/var/git/espo/backend 2014-08-14 11:17:26 +03:00
Taras Machyshyn
14eebc7392 added indexes for EmailAddress.lower and PhoneNumber.name 2014-08-14 11:17:09 +03:00
Yuri Kuznetsov
5a86d0e396 Merge branch 'master' of ssh://172.20.0.1/var/git/espo/backend 2014-08-13 17:08:44 +03:00
Yuri Kuznetsov
a4e0c8107d fix modals 2014-08-13 17:08:26 +03:00
Yuri Kuznetsov
1652de16a7 muted tooltip text 2014-08-13 15:36:29 +03:00
Yuri Kuznetsov
ad539e19a2 fix lang 2014-08-13 15:34:31 +03:00
Yuri Kuznetsov
592f073bf9 tooltips 2014-08-13 15:32:11 +03:00
Taras Machyshyn
d5c1d1b86e added no-suPHP support 2014-08-13 15:27:37 +03:00
Yuri Kuznetsov
bd70e2424c isRequired fix 2014-08-13 14:21:03 +03:00
Taras Machyshyn
06d6299d7f fixed language merge issue 2014-08-13 12:52:38 +03:00
Yuri Kuznetsov
d00d2bdb0f login css 2014-08-13 12:20:22 +03:00
Yuri Kuznetsov
9f481f6887 Merge branch 'master' of ssh://172.20.0.1/var/git/espo/backend 2014-08-13 11:37:55 +03:00
Yuri Kuznetsov
47d0501828 rowactions 2014-08-13 11:37:31 +03:00
Yuri Kuznetsov
a4cd8dccfe fix dutch 2014-08-12 18:28:39 +03:00
Taras Machyshyn
eee0f0eb13 Merge branch 'master' of ssh://172.20.0.1/var/git/espo/backend 2014-08-12 18:23:45 +03:00
Taras Machyshyn
67b9600341 added getRequestMethod() method for Controller 2014-08-12 18:22:14 +03:00
Yuri Kuznetsov
4c0329e6be Merge branch 'master' of ssh://172.20.0.1/var/git/espo/backend 2014-08-12 17:14:58 +03:00
Yuri Kuznetsov
ff6cd18411 nl_NL lang 2014-08-12 17:10:27 +03:00
Taras Machyshyn
8d4219802b added rebuild for Currency Settings 2014-08-12 13:44:23 +03:00
Taras Machyshyn
07e7374a18 added 'remove' possibility to config 2014-08-12 13:04:08 +03:00
Taras Machyshyn
060f517591 Merge branch 'master' of ssh://172.20.0.1/var/git/espo/backend 2014-08-12 12:56:36 +03:00
Taras Machyshyn
1af5e93bd3 added test file to ignore list 2014-08-12 12:56:17 +03:00
Yuri Kuznetsov
38df3162b3 fix xss 2014-08-12 12:12:27 +03:00
Yuri Kuznetsov
e03298b041 opportunity currency converted 2014-08-12 11:54:09 +03:00
Yuri Kuznetsov
80278b7213 quote {value} and lead currency converted 2014-08-12 11:47:37 +03:00
Yuri Kuznetsov
a701905e9c required inbound \email template 2014-08-11 18:06:34 +03:00
Yuri Kuznetsov
59b896e594 Merge branch 'master' of ssh://172.20.0.1/var/git/espo/backend 2014-08-11 17:36:16 +03:00
Taras Machyshyn
ba4c8e0afd config: possibility to save StdClass 2014-08-11 17:35:49 +03:00
Yuri Kuznetsov
9175d8c7ce change layout 2014-08-11 17:26:00 +03:00
Yuri Kuznetsov
052fee6ba2 fix css input group 2014-08-11 17:24:17 +03:00
Yuri Kuznetsov
aae3afc895 currency 1 2014-08-11 17:11:30 +03:00
Yuri Kuznetsov
1892ff6cae Merge branch 'hotfix/2.3.1' 2014-08-11 15:49:34 +03:00
Yuri Kuznetsov
aa3e9fd8b0 Merge branch 'hotfix/2.3.1' of ssh://172.20.0.1/var/git/espo/backend into hotfix/2.3.1 2014-08-11 14:14:33 +03:00
Yuri Kuznetsov
2863092911 compose email from case 2014-08-11 14:13:52 +03:00
Taras Machyshyn
1c36421157 chnaged currencyRate in config 2014-08-11 13:58:33 +03:00
Yuri Kuznetsov
77f7da0ba5 case and email improvoments 2014-08-11 12:45:04 +03:00
Yuri Kuznetsov
a5f858dda2 fix detail view false field 2014-08-11 11:44:04 +03:00
Taras Machyshyn
a5b7bfc00e fixed access LOGs issue 2014-08-11 11:30:28 +03:00
Yuri Kuznetsov
4d2cb6c38e varchar search 2014-08-11 10:53:40 +03:00
Yuri Kuznetsov
b6bd70d47c currency symbol 2014-08-11 10:49:34 +03:00
Yuri Kuznetsov
ef3ed38b97 Merge branch 'master' into stable 2014-08-08 16:58:08 +03:00
Yuri Kuznetsov
a38b86b2c6 dashlet sorting 2014-08-08 14:13:24 +03:00
Yuri Kuznetsov
a87044623c diff fix 2014-08-08 11:45:13 +03:00
Yuri Kuznetsov
44a96ddece isFieldChanged 2014-08-07 18:30:52 +03:00
Yuri Kuznetsov
b0e911870b git fix lang 2014-08-07 16:19:55 +03:00
Yuri Kuznetsov
96bb421b0a Delete label 2014-08-07 15:24:32 +03:00
Yuri Kuznetsov
c281d7b2d9 fix lang 2014-08-07 12:08:51 +03:00
Yuri Kuznetsov
dc5766088f confirm messages 2014-08-07 12:03:54 +03:00
Yuri Kuznetsov
fe69f97b1e fix acl issue and mappen IN issue 2014-08-07 11:28:52 +03:00
Yuri Kuznetsov
b7bc1e3622 services changes 2014-08-06 16:07:04 +03:00
Yuri Kuznetsov
b3c4123669 email notifications 2014-08-06 15:57:30 +03:00
Yuri Kuznetsov
0795f6f6f2 clear cache messag in role 2014-08-06 10:50:26 +03:00
Yuri Kuznetsov
c3cd909063 version 2014-08-05 17:34:39 +03:00
Yuri Kuznetsov
0e37c26b9f fix issue with this 2014-08-05 17:12:15 +03:00
Yuri Kuznetsov
80937f8d09 convert lead fix 2014-08-05 15:57:37 +03:00
Yuri Kuznetsov
380cdeba35 use cache false 2014-08-05 15:27:47 +03:00
Yuri Kuznetsov
1eabce0d2e change record detail #build 2014-08-05 15:27:34 +03:00
Yuri Kuznetsov
3cd5f801a5 use cache false 2014-08-05 14:42:01 +03:00
Yuri Kuznetsov
c1cfd75bd6 fix notice 2014-08-05 14:38:47 +03:00
Yuri Kuznetsov
dd5fabdfa4 contacts select in meetings 2014-08-05 11:44:10 +03:00
Yuri Kuznetsov
3e9c7056b0 improve mark all read 2014-08-05 10:54:19 +03:00
Yuri Kuznetsov
26188879b6 fix client acl 2014-08-05 10:49:29 +03:00
Yuri Kuznetsov
488717c6a1 dashlet changes 2014-08-04 17:05:24 +03:00
Yuri Kuznetsov
b8476d7335 fix import 2014-08-04 15:23:41 +03:00
Yuri Kuznetsov
1cfad615c0 not team restricion for admin 2014-08-04 13:35:35 +03:00
Yuri Kuznetsov
e3a3547a54 prevent error if field name is empty in layout 2014-08-04 12:36:51 +03:00
Yuri Kuznetsov
e6948aba2e mark all read 2014-08-04 12:19:09 +03:00
Yuri Kuznetsov
d4943e4d1c Merge branch 'stable' 2014-08-01 11:06:01 +03:00
Yuri Kuznetsov
af5e7d99b2 Merge branch 'release/2.2' into stable 2014-08-01 11:05:46 +03:00
Yuri Kuznetsov
667a46f141 text field search 2014-07-31 17:36:48 +03:00
Yuri Kuznetsov
67f65492de version 2014-07-31 12:21:58 +03:00
Yuri Kuznetsov
b6a98e7121 change show more count 2014-07-30 17:33:59 +03:00
Yuri Kuznetsov
9669ff91bb footer fix 2014-07-30 12:20:16 +03:00
Yuri Kuznetsov
acb6e245a2 show total 2014-07-30 11:43:14 +03:00
Yuri Kuznetsov
b5e015e9c9 vi_VN to config 2014-07-30 10:49:36 +03:00
Yuri Kuznetsov
70d2e311e5 vi_VN lang 2014-07-30 10:46:36 +03:00
Yuri Kuznetsov
6c7e5c0d02 update ro lang 2014-07-30 10:45:12 +03:00
Yuri Kuznetsov
d4558d73b3 lang 2014-07-30 10:35:59 +03:00
Yuri Kuznetsov
e2257f6cfd footer 2014-07-29 18:06:08 +03:00
Yuri Kuznetsov
149fa41e2b textFilter 2014-07-29 17:19:00 +03:00
Yuri Kuznetsov
71e4c2fca0 Merge branch 'hotfix/2.1.1' 2014-07-29 16:37:15 +03:00
Yuri Kuznetsov
5a4613617c fix diff 2014-07-29 16:07:25 +03:00
Yuri Kuznetsov
cbf9dd458e diff change 2014-07-29 13:06:15 +03:00
Yuri Kuznetsov
08553bdf9d diff changes 2014-07-28 15:37:46 +03:00
Yuri Kuznetsov
d0b61b42e0 fix diff 2014-07-28 12:54:33 +03:00
Yuri Kuznetsov
3e3348c4a7 version 2014-07-28 12:51:17 +03:00
Yuri Kuznetsov
c32b0f365b diff.js 2014-07-28 12:50:25 +03:00
Yuri Kuznetsov
8fd0554714 fix null filter issue 2014-07-28 11:17:21 +03:00
Yuri Kuznetsov
982f0e1f62 change filter defs 2014-07-28 10:54:01 +03:00
Yuri Kuznetsov
c87f5dfab3 bool filter change 2014-07-28 10:34:39 +03:00
Yuri Kuznetsov
b335462aa4 Merge branch 'release/2.1' into stable 2014-07-25 15:21:50 +03:00
Yuri Kuznetsov
97c951484d fix add dashlet 2014-07-25 15:18:37 +03:00
Yuri Kuznetsov
2215f15aaf lang 2014-07-25 12:58:26 +03:00
Yuri Kuznetsov
65f38a4906 Merge branch 'release/2.1' into stable 2014-07-25 12:27:30 +03:00
Yuri Kuznetsov
6429823cc3 version 2014-07-25 11:28:50 +03:00
Yuri Kuznetsov
2a71bb2ea1 duplicate 2014-07-25 11:24:20 +03:00
Yuri Kuznetsov
1674c2221e disableExport 2014-07-24 18:48:03 +03:00
Yuri Kuznetsov
e3b448f520 style preset 2014-07-24 17:48:49 +03:00
Yuri Kuznetsov
a04c973817 css 2014-07-24 16:21:17 +03:00
Yuri Kuznetsov
01c9939215 fix css 2014-07-24 16:08:32 +03:00
Yuri Kuznetsov
2d57824cb0 fix css 2014-07-24 15:33:23 +03:00
Yuri Kuznetsov
878385f14b fix import UI 2014-07-24 15:27:27 +03:00
Yuri Kuznetsov
8b82058d06 fix import 2014-07-24 15:20:17 +03:00
Yuri Kuznetsov
68e05f0935 datetime edit more nice 2014-07-24 15:00:49 +03:00
Yuri Kuznetsov
cb7492c042 email to case: dont copy email body 2014-07-24 14:41:05 +03:00
Yuri Kuznetsov
beb811755f improve bool filters ui 2014-07-24 11:21:21 +03:00
Yuri Kuznetsov
7c7fc4ee0f impreove preset search 2014-07-24 11:01:47 +03:00
Yuri Kuznetsov
aeef25f7ec fix preset ok 2014-07-23 17:19:35 +03:00
Yuri Kuznetsov
6856ff97b1 fix previous commit 2014-07-23 17:11:09 +03:00
Yuri Kuznetsov
10f6f7600c create notifications via cron 2014-07-23 17:04:03 +03:00
Yuri Kuznetsov
a0b678a3d9 remove some files from grunt uglify 2014-07-23 16:17:30 +03:00
Yuri Kuznetsov
f78e558a33 fix search 2014-07-23 15:56:06 +03:00
Yuri Kuznetsov
e205ef3370 improve fields tpls 2014-07-23 15:38:38 +03:00
Yuri Kuznetsov
8b6e4d469e onlyMy for meetings and calls 2014-07-23 12:49:10 +03:00
Yuri Kuznetsov
a63ec2710b fix filter 2014-07-23 12:20:16 +03:00
Yuri Kuznetsov
6895fac58c date filters 2014-07-23 11:57:48 +03:00
Yuri Kuznetsov
ea3c8f2d35 fix preset 2014-07-23 09:56:42 +03:00
Yuri Kuznetsov
0f2c050537 lang 2014-07-22 18:22:38 +03:00
Yuri Kuznetsov
2cd8866c73 Merge branch 'stable' 2014-07-22 18:07:44 +03:00
Yuri Kuznetsov
86a5e19b55 version 2014-07-22 17:46:38 +03:00
Yuri Kuznetsov
61f435812d fix timezones 2014-07-22 17:42:55 +03:00
Yuri Kuznetsov
217d0f6540 preset filters 4 2014-07-22 17:37:21 +03:00
Yuri Kuznetsov
f0e7a8f029 preset filters 2 2014-07-22 16:25:56 +03:00
Yuri Kuznetsov
d2954483d9 preset filters 2014-07-21 16:45:18 +03:00
Yuri Kuznetsov
999b88cba1 Merge branch 'stable' 2014-07-18 17:04:59 +03:00
Yuri Kuznetsov
717df30063 Merge branch 'release/2.0' into stable 2014-07-18 17:04:35 +03:00
Yuri Kuznetsov
d889c78f0c fix query 2014-07-18 10:31:01 +03:00
Yuri Kuznetsov
4737c506f2 do not pass phone to new contact 2014-07-17 15:50:45 +03:00
Yuri Kuznetsov
78cb1a8052 label css 2014-07-15 14:46:38 +03:00
Yuri Kuznetsov
dac8ca5a6d search by email and phone fix 2014-07-15 12:55:22 +03:00
Yuri Kuznetsov
e04ac6778a fix email phone fields 2014-07-15 12:34:12 +03:00
Yuri Kuznetsov
5f34d4f2fd change duplication where clause 2014-07-15 12:24:30 +03:00
Yuri Kuznetsov
ca7c0f07e9 fix fields 2014-07-15 12:20:26 +03:00
Yuri Kuznetsov
af26f29bec status 2014-07-15 11:11:09 +03:00
Taras Machyshyn
0c44f78ea1 Merge branch 'master' of ssh://172.20.0.1/var/git/espo/backend 2014-07-15 11:01:00 +03:00
Taras Machyshyn
bed62e2e71 orm convertation chnages 2014-07-15 11:00:38 +03:00
Yuri Kuznetsov
6d61db86df fix url field 2014-07-14 14:59:40 +03:00
Yuri Kuznetsov
4feb055256 fr_FR lang 2014-07-14 11:29:31 +03:00
Yuri Kuznetsov
10a44239ed fix tpls 2014-07-14 11:18:17 +03:00
Yuri Kuznetsov
8a78eda520 Merge branch 'master' of ssh://172.20.0.1/var/git/espo/backend 2014-07-11 14:36:48 +03:00
Yuri Kuznetsov
891b159b30 view parameter for fields 2014-07-11 14:36:34 +03:00
Taras Machyshyn
0d06770e80 LDAP changes 2014-07-11 13:57:03 +03:00
Yuri Kuznetsov
f8675bd45c languages 2014-07-11 12:24:10 +03:00
Yuri Kuznetsov
c35136b524 pt_BR lang 2014-07-11 12:21:31 +03:00
Yuri Kuznetsov
a0384deb00 ro_RO lang 2014-07-11 12:19:37 +03:00
Yuri Kuznetsov
e35fb15a31 de_DE lang 2014-07-11 12:13:43 +03:00
Yuri Kuznetsov
fe86807091 fix email template 2014-07-10 18:08:14 +03:00
Yuri Kuznetsov
e12a15ecdb fix notice 2014-07-10 17:53:40 +03:00
Yuri Kuznetsov
24dcd46d6f change currency field look 2014-07-10 17:22:51 +03:00
Yuri Kuznetsov
15196f2062 fix linkMultiple fields 2014-07-10 17:00:09 +03:00
Yuri Kuznetsov
1ae1b20111 phone and email fields change 2014-07-10 16:35:31 +03:00
Yuri Kuznetsov
84de477be0 ldap password 2014-07-10 14:49:42 +03:00
Yuri Kuznetsov
97407de17d remove SAML 2014-07-10 13:22:49 +03:00
Yuri Kuznetsov
84bc5beed2 preferences dynamic form 2014-07-10 13:20:22 +03:00
Yuri Kuznetsov
6974b1637d ldap form 2014-07-10 13:08:16 +03:00
Yuri Kuznetsov
dc89aff7b1 dynamic forms 2014-07-10 13:08:10 +03:00
Yuri Kuznetsov
2bfea69fe3 calendar remove event 2014-07-09 14:52:30 +03:00
Yuri Kuznetsov
0e1e481546 calendar timezone 2014-07-09 14:42:16 +03:00
Yuri Kuznetsov
52e938888d Merge branch 'master' of ssh://172.20.0.1/var/git/espo/backend 2014-07-09 14:30:08 +03:00
Yuri Kuznetsov
a2ef1656fb fix email template 2014-07-09 14:27:52 +03:00
Yuri Kuznetsov
c168c3ff9b fix field-manager 2014-07-09 14:27:45 +03:00
Yuri Kuznetsov
56af0baea2 entityFactory changhe 2014-07-09 14:15:27 +03:00
Taras Machyshyn
35ecf2e144 update tests 2014-07-09 13:33:42 +03:00
Taras Machyshyn
d25692b15e added manifest.json checking for upgrade process 2014-07-09 12:13:34 +03:00
Taras Machyshyn
59a66cb8fa LDAP authorization 2014-07-09 11:53:30 +03:00
Yuri Kuznetsov
75ce454b2a tr_TR language 2014-07-09 11:39:03 +03:00
Yuri Kuznetsov
b94134a35a data-panel-name 2014-07-08 16:59:41 +03:00
Yuri Kuznetsov
4b09f055e4 snap duration 2014-07-08 15:40:04 +03:00
Yuri Kuznetsov
d743eca6a3 calendar 2014-07-08 15:33:07 +03:00
Yuri Kuznetsov
0e3c872310 calendar 2 2014-07-08 15:30:17 +03:00
Yuri Kuznetsov
f8b56cba24 get rid of form on edit view 2014-07-08 11:45:15 +03:00
Yuri Kuznetsov
b506cd726c fix modal close 2014-07-08 11:31:47 +03:00
Yuri Kuznetsov
998aaec170 upgrade bootstrap to 3.2 2014-07-08 11:20:53 +03:00
Yuri Kuznetsov
4c30507a85 link role css 2014-07-08 11:05:57 +03:00
Yuri Kuznetsov
a55f1aca58 Merge branch 'master' of ssh://172.20.0.1/var/git/espo/backend 2014-07-07 17:49:57 +03:00
Yuri Kuznetsov
868cf4e22c fix inline edit 2014-07-07 17:47:45 +03:00
Taras Machyshyn
2decd9016e fixed rebuild.php issue 2014-07-07 17:45:31 +03:00
Yuri Kuznetsov
9cba465473 fix prev commit 2014-07-07 17:24:12 +03:00
Yuri Kuznetsov
b9344afb27 linkMultipleWithRole css fix 2014-07-07 17:11:06 +03:00
Yuri Kuznetsov
7074991771 email and phone fields remove button 2014-07-07 16:30:36 +03:00
Yuri Kuznetsov
b43d37ac79 change layout 2014-07-07 16:21:11 +03:00
Yuri Kuznetsov
18b393b286 activities new logic 2014-07-07 16:17:44 +03:00
Yuri Kuznetsov
728fce75d7 fix linkMultiple css 2014-07-07 14:09:52 +03:00
Yuri Kuznetsov
50d441aea0 account - contact - 5 2014-07-07 11:32:01 +03:00
Yuri Kuznetsov
d75f9e5acd fix handleSelectParams 2014-07-04 18:26:52 +03:00
Yuri Kuznetsov
3c96cf240e account - contact 4 2014-07-04 18:13:54 +03:00
Yuri Kuznetsov
2583c77108 accoun - contact 3 2014-07-04 17:37:01 +03:00
Yuri Kuznetsov
a3ad210ec2 account - contact 2 2014-07-04 14:55:02 +03:00
Yuri Kuznetsov
6bd7d2398d account - contact 1 2014-07-03 19:12:34 +03:00
Yuri Kuznetsov
017cd3d978 fix rerender fields 2014-07-03 19:12:22 +03:00
Yuri Kuznetsov
a3af86d248 fix primary button 2014-07-03 11:19:16 +03:00
Yuri Kuznetsov
99e9cbde84 email and phone fields: hide primary button 2014-07-03 10:44:47 +03:00
Yuri Kuznetsov
85d60d2555 Merge branch 'master' of ssh://172.20.0.1/var/git/espo/backend 2014-07-02 17:31:31 +03:00
Yuri Kuznetsov
1fe4555209 phone number 3 2014-07-02 17:19:14 +03:00
Yuri Kuznetsov
8b80df2f91 phone number 2 2014-07-02 16:33:02 +03:00
Yuri Kuznetsov
3d7d4eb7db clone deep in model 2014-07-02 15:53:31 +03:00
Taras Machyshyn
4215621eb7 FieldManager fixes 2014-07-02 13:01:16 +03:00
Yuri Kuznetsov
d138a5d0b7 phone number 1 2014-07-02 12:24:42 +03:00
Yuri Kuznetsov
b3023192d0 fix search field view and lead source 2014-07-01 18:18:16 +03:00
Yuri Kuznetsov
7cc0c527e0 merge manual with stable 2014-07-01 18:09:52 +03:00
Yuri Kuznetsov
f3f36e87a4 Merge branch 'hotfix/1.2.1' into stable 2014-07-01 18:06:29 +03:00
Yuri Kuznetsov
b55b133ddf lead source 2 2014-07-01 18:05:38 +03:00
Yuri Kuznetsov
a60378a9bd lead source 1 2014-07-01 17:42:25 +03:00
Yuri Kuznetsov
3a23b28657 convert layout 2014-07-01 16:29:34 +03:00
Yuri Kuznetsov
42e21d585f bug with follow button and lead convert 2014-07-01 16:18:27 +03:00
Yuri Kuznetsov
a30ab9a1a0 fix notification in admin panel 2014-07-01 15:33:40 +03:00
Yuri Kuznetsov
4510295792 change opp layout 2014-07-01 15:09:22 +03:00
Yuri Kuznetsov
ed5de64cd3 roles dev 2014-07-01 15:04:59 +03:00
Yuri Kuznetsov
1c89187c49 update Role 2014-07-01 12:55:43 +03:00
Yuri Kuznetsov
169a3f6e6d -20px for panel 2014-07-01 11:36:27 +03:00
Yuri Kuznetsov
7e2ead7949 clonedeep role 2014-07-01 11:24:58 +03:00
Yuri Kuznetsov
8413067194 role field dev 2014-07-01 10:45:42 +03:00
Yuri Kuznetsov
81c7dcaa63 roles dev 2014-06-30 18:10:13 +03:00
Yuri Kuznetsov
3b12c7f1cf role field dev 2014-06-30 17:17:06 +03:00
Yuri Kuznetsov
cdab200898 fix linkMultiple 2014-06-30 16:46:21 +03:00
Yuri Kuznetsov
0f9c3e1c1c getSelectFilters 2014-06-30 16:42:47 +03:00
Yuri Kuznetsov
fe5a5b76ca fix linkMultiple fields 2014-06-30 16:23:03 +03:00
Yuri Kuznetsov
0e3720c038 columns for linkMultiple 2014-06-30 16:01:57 +03:00
Yuri Kuznetsov
99f1ba8987 fix layout manager 2014-06-30 12:06:49 +03:00
Yuri Kuznetsov
8ff5d79788 fix array fiel tpl 2014-06-30 11:52:28 +03:00
Yuri Kuznetsov
9d6485194f table header font weight 2014-06-30 11:28:11 +03:00
Yuri Kuznetsov
21e306774e link multiple li padding 2014-06-30 11:25:45 +03:00
Yuri Kuznetsov
ffa340f255 contacts field in opportunity 2014-06-30 11:21:31 +03:00
Yuri Kuznetsov
d6b65edfb1 fix select related 2014-06-30 11:12:08 +03:00
Yuri Kuznetsov
a3ed33a443 filters for select related 2014-06-30 11:09:21 +03:00
Yuri Kuznetsov
38ff477cef stick stream panel 2014-06-27 18:21:40 +03:00
Yuri Kuznetsov
c5c638b007 Merge branch 'master' of ssh://172.20.0.1/var/git/espo/backend 2014-06-27 18:06:12 +03:00
Yuri Kuznetsov
181fd8dc73 record panel margin 2014-06-27 17:59:46 +03:00
Taras Machyshyn
e57f58bec3 fixed label string for .po file 2014-06-27 16:47:10 +03:00
Taras Machyshyn
5c2067f61a chnaged 'php version' label 2014-06-27 16:36:55 +03:00
Yuri Kuznetsov
3ec5cf259b refactor auth 2014-06-27 12:15:54 +03:00
Yuri Kuznetsov
e5e898222b Authentification refactor 2014-06-27 12:01:30 +03:00
Yuri Kuznetsov
18b2876853 ability to remove entity in calendar 2014-06-26 17:51:50 +03:00
Yuri Kuznetsov
cec4ffcb6c Merge branch 'hotfix/1.2.1' 2014-06-26 17:13:14 +03:00
Yuri Kuznetsov
b59dba0e6d fix lang 2014-06-26 16:47:36 +03:00
Yuri Kuznetsov
0d9a182833 change version 2014-06-26 16:45:50 +03:00
Yuri Kuznetsov
8674f66b4d Merge branch 'hotfix/1.2.1' 2014-06-26 16:44:35 +03:00
Yuri Kuznetsov
605a720694 auth tokens page title 2014-06-26 16:44:21 +03:00
Yuri Kuznetsov
aa761d5ef7 auth tokens in admin 2014-06-26 16:32:18 +03:00
Yuri Kuznetsov
3d4d8aa7d3 prepareEntityForOutput 2014-06-26 15:19:43 +03:00
Yuri Kuznetsov
556b72edb2 fix install lang 2014-06-24 18:31:10 +03:00
Yuri Kuznetsov
be372b90f9 Merge branch 'master' of ssh://172.20.0.1/var/git/espo/backend 2014-06-24 18:19:41 +03:00
Yuri Kuznetsov
846e93741f disable targets 2014-06-24 18:15:40 +03:00
Yuri Kuznetsov
b82af3a0c6 prospects to targets 2014-06-24 18:13:35 +03:00
Taras Machyshyn
02b429cb32 installer: design changes 2014-06-24 11:43:37 +03:00
Taras Machyshyn
3332469c35 chnaged Config.php . Now use ->save() to save the configuration 2014-06-19 12:42:57 +03:00
Yuri Kuznetsov
371f243a6d Merge branch 'stable' 2014-06-13 12:35:28 +03:00
3119 changed files with 78436 additions and 270356 deletions

11
.gitignore vendored
View File

@@ -2,16 +2,15 @@
/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
/frontend/client/css/bootstrap.css
/tests/testData/cache/*
composer.phar
vendor/

View File

@@ -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>

View File

@@ -1,247 +1,245 @@
module.exports = function (grunt) {
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
mkdir: {
tmp: {
options: {
mode: 0775,
create: [
'build/tmp',
]
},
}
},
clean: {
start: ['build/*'],
final: ['build/tmp'],
},
less: {
bootstrap: {
options: {
yuicompress: true,
},
files: {
'frontend/client/css/bootstrap.css': 'frontend/less/espo/main.less',
},
},
},
cssmin: {
minify: {
files: {
'build/tmp/client/css/espo.min.css': [
'frontend/client/css/bootstrap.css',
'frontend/client/css/datepicker.css',
'frontend/client/css/jquery.timepicker.css',
]
}
},
},
uglify: {
options: {
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.min.js',
'frontend/client/lib/moment-timezone-data.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/controllers/record.js',
'frontend/client/src/controllers/role.js',
'frontend/client/src/controllers/admin.js',
'frontend/client/src/view.js',
'frontend/client/src/views/base.js',
'frontend/client/src/views/login.js',
]
},
copy: {
frontendFolders: {
expand: true,
cwd: 'frontend/client',
src: [
'src/**',
'res/**',
'fonts/**',
'cfg/**',
'modules/**',
'img/**',
'css/**',
],
dest: 'build/tmp/client',
},
frontendHtml: {
src: 'frontend/html/reset.html',
dest: 'build/tmp/reset.html'
},
frontendLib: {
expand: true,
dot: true,
cwd: 'frontend/client/lib',
src: '**',
dest: 'build/tmp/client/lib/',
},
backend: {
expand: true,
dot: true,
src: [
'api/**',
'application/**',
'custom/**',
'data/.data',
'install/**',
'vendor/**',
'bootstrap.php',
'cron.php',
'rebuild.php',
'index.php',
'LICENSE.txt',
'.htaccess',
'Web.config',
],
dest: 'build/tmp/',
},
final: {
expand: true,
dot: true,
src: '**',
cwd: 'build/tmp',
dest: 'build/EspoCRM-<%= pkg.version %>/',
},
},
chmod: {
options: {
mode: '755'
},
php: {
options: {
mode: '644'
},
src: [
'build/EspoCRM-<%= pkg.version %>/**/*.php',
'build/EspoCRM-<%= pkg.version %>/**/*.json',
'build/EspoCRM-<%= pkg.version %>/**/*.config',
'build/EspoCRM-<%= pkg.version %>/**/.htaccess',
'build/EspoCRM-<%= pkg.version %>/client/**/*.js',
'build/EspoCRM-<%= pkg.version %>/client/**/*.css',
'build/EspoCRM-<%= pkg.version %>/client/**/*.tpl',
'build/EspoCRM-<%= pkg.version %>/**/*.html',
'build/EspoCRM-<%= pkg.version %>/**/*.txt',
]
}
},
replace: {
timestamp: {
options: {
patterns: [
{
match: 'timestamp',
replacement: '<%= new Date().getTime() %>'
}
]
},
files: [
{
src: 'frontend/html/main.html',
dest: 'build/tmp/main.html'
}
]
},
version: {
options: {
patterns: [
{
match: 'version',
replacement: '<%= pkg.version %>'
}
]
},
files: [
{
src: 'build/tmp/application/Espo/Core/defaults/config.php',
dest: 'build/tmp/application/Espo/Core/defaults/config.php'
}
]
}
},
compress: {
final: {
options: {
archive: 'build/EspoCRM-<%= pkg.version %>.zip',
mode: 'zip'
},
src: ['**'],
cwd: 'build/EspoCRM-<%= pkg.version %>',
dest: 'EspoCRM-<%= pkg.version %>'
}
}
});
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'),
mkdir: {
tmp: {
options: {
mode: 0775,
create: [
'build/tmp',
]
},
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-mkdir');
grunt.loadNpmTasks('grunt-contrib-less');
grunt.loadNpmTasks('grunt-contrib-cssmin');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-replace');
grunt.loadNpmTasks('grunt-contrib-compress');
grunt.loadNpmTasks('grunt-chmod');
}
},
clean: {
start: ['build/*'],
final: ['build/tmp'],
},
less: {
bootstrap: {
options: {
yuicompress: true,
},
files: {
'frontend/client/css/bootstrap.css': 'frontend/less/espo/main.less',
},
},
},
cssmin: {
minify: {
files: {
'build/tmp/client/css/espo.min.css': [
'frontend/client/css/bootstrap.css',
'frontend/client/css/datepicker.css',
'frontend/client/css/jquery.timepicker.css',
]
}
},
},
uglify: {
options: {
mangle: false,
banner: '/*! <%= pkg.name %> <%= grunt.template.today("yyyy-mm-dd") %> */\n',
},
'build/tmp/client/espo.min.js': jsFilesToMinify.map(function (item) {
return 'frontend/' + item;
})
},
copy: {
frontendFolders: {
expand: true,
cwd: 'frontend/client',
src: [
'src/**',
'res/**',
'fonts/**',
'cfg/**',
'modules/**',
'img/**',
'css/**',
],
dest: 'build/tmp/client',
},
frontendHtml: {
src: 'frontend/html/reset.html',
dest: 'build/tmp/reset.html'
},
frontendLib: {
expand: true,
dot: true,
cwd: 'frontend/client/lib',
src: '**',
dest: 'build/tmp/client/lib/',
},
backend: {
expand: true,
dot: true,
src: [
'api/**',
'application/**',
'custom/**',
'data/.data',
'install/**',
'vendor/**',
'bootstrap.php',
'cron.php',
'rebuild.php',
'index.php',
'LICENSE.txt',
'.htaccess',
'web.config',
],
dest: 'build/tmp/',
},
final: {
expand: true,
dot: true,
src: '**',
cwd: 'build/tmp',
dest: 'build/EspoCRM-<%= pkg.version %>/',
},
},
chmod: {
options: {
mode: '755'
},
php: {
options: {
mode: '644'
},
src: [
'build/EspoCRM-<%= pkg.version %>/**/*.php',
'build/EspoCRM-<%= pkg.version %>/**/*.json',
'build/EspoCRM-<%= pkg.version %>/**/*.config',
'build/EspoCRM-<%= pkg.version %>/**/.htaccess',
'build/EspoCRM-<%= pkg.version %>/client/**/*.js',
'build/EspoCRM-<%= pkg.version %>/client/**/*.css',
'build/EspoCRM-<%= pkg.version %>/client/**/*.tpl',
'build/EspoCRM-<%= pkg.version %>/**/*.html',
'build/EspoCRM-<%= pkg.version %>/**/*.txt',
]
}
},
replace: {
timestamp: {
options: {
patterns: [
{
match: 'timestamp',
replacement: '<%= new Date().getTime() %>'
}
]
},
files: [
{
src: 'frontend/html/main.html',
dest: 'build/tmp/main.html'
}
]
},
version: {
options: {
patterns: [
{
match: 'version',
replacement: '<%= pkg.version %>'
}
]
},
files: [
{
src: 'build/tmp/application/Espo/Core/defaults/config.php',
dest: 'build/tmp/application/Espo/Core/defaults/config.php'
}
]
}
},
compress: {
final: {
options: {
archive: 'build/EspoCRM-<%= pkg.version %>.zip',
mode: 'zip'
},
src: ['**'],
cwd: 'build/EspoCRM-<%= pkg.version %>',
dest: 'EspoCRM-<%= pkg.version %>'
}
}
});
grunt.registerTask('default', [
'clean:start',
'mkdir:tmp',
'less',
'cssmin',
'uglify',
'copy:frontendFolders',
'copy:frontendHtml',
'copy:frontendLib',
'copy:backend',
'replace',
'copy:final',
'chmod',
'clean:final',
]);
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-mkdir');
grunt.loadNpmTasks('grunt-contrib-less');
grunt.loadNpmTasks('grunt-contrib-cssmin');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-replace');
grunt.loadNpmTasks('grunt-contrib-compress');
grunt.loadNpmTasks('grunt-chmod');
grunt.registerTask('default', [
'clean:start',
'mkdir:tmp',
'less',
'cssmin',
'uglify',
'copy:frontendFolders',
'copy:frontendHtml',
'copy:frontendLib',
'copy:backend',
'replace',
'copy:final',
'chmod',
'clean:final',
]);
};

39
README.md Normal file
View File

@@ -0,0 +1,39 @@
## EspoCRM
<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.
It's a web application with a frontend designed as a single page application based on backbone.js and a RESTful backend written in PHP.
Download the latest release from our [website](http://www.espocrm.com).
### How to report bug
Create an issue [here](https://github.com/espocrm/espocrm/issues) or post on our [forum](http://forum.espocrm.com/bug-reports?routestring=forum/bug-reports).
### How to get started (for developers)
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`. To compose a proper config.php and populate database you can run install by opening `http(s)://{YOUR_CRM_URL}/install` location in a browser. Also you need to run build before to have compiled css.
### 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).

View File

@@ -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>

View File

@@ -1,2 +0,0 @@
Order Deny,Allow
Deny from all

View File

@@ -27,60 +27,60 @@ use \Espo\Core\Exceptions\Error,
class Admin extends \Espo\Core\Controllers\Base
{
protected function checkControllerAccess()
{
if (!$this->getUser()->isAdmin()) {
throw new Forbidden();
}
}
protected function checkControllerAccess()
{
if (!$this->getUser()->isAdmin()) {
throw new Forbidden();
}
}
public function actionRebuild($params, $data)
{
$result = $this->getContainer()->get('dataManager')->rebuild();
public function actionRebuild($params, $data)
{
$result = $this->getContainer()->get('dataManager')->rebuild();
return $result;
}
return $result;
}
public function actionClearCache($params, $data)
{
$result = $this->getContainer()->get('dataManager')->clearCache();
public function actionClearCache($params, $data)
{
$result = $this->getContainer()->get('dataManager')->clearCache();
return $result;
}
return $result;
}
public function actionJobs()
{
$scheduledJob = $this->getContainer()->get('scheduledJob');
public function actionJobs()
{
$scheduledJob = $this->getContainer()->get('scheduledJob');
return $scheduledJob->getAllNamesOnly();
}
return $scheduledJob->getAllNamesOnly();
}
public function actionUploadUpgradePackage($params, $data)
{
$upgradeManager = new \Espo\Core\UpgradeManager($this->getContainer());
public function actionUploadUpgradePackage($params, $data)
{
$upgradeManager = new \Espo\Core\UpgradeManager($this->getContainer());
$upgradeId = $upgradeManager->upload($data);
$manifest = $upgradeManager->getManifest();
$upgradeId = $upgradeManager->upload($data);
$manifest = $upgradeManager->getManifest();
return array(
'id' => $upgradeId,
'version' => $manifest['version'],
);
}
return array(
'id' => $upgradeId,
'version' => $manifest['version'],
);
}
public function actionRunUpgrade($params, $data)
{
$upgradeManager = new \Espo\Core\UpgradeManager($this->getContainer());
public function actionRunUpgrade($params, $data)
{
$upgradeManager = new \Espo\Core\UpgradeManager($this->getContainer());
$upgradeManager->run($data['id']);
$upgradeManager->install($data['id']);
return true;
}
return true;
}
public function actionCronMessage($params, $data)
{
return $this->getContainer()->get('scheduledJob')->getSetupMessage();
}
public function actionCronMessage($params, $data)
{
return $this->getContainer()->get('scheduledJob')->getSetupMessage();
}
}

View File

@@ -26,25 +26,25 @@ use \Espo\Core\Exceptions\BadRequest;
class App extends \Espo\Core\Controllers\Record
{
public function actionUser()
{
return array(
'user' => $this->getUser()->toArray(),
'acl' => $this->getAcl()->toArray(),
'preferences' => $this->getPreferences()->toArray(),
'token' => $this->getUser()->get('token')
);
}
public function actionDestroyAuthToken($params, $data)
{
$token = $data['token'];
if (empty($token)) {
throw new BadRequest();
}
public function actionUser()
{
return array(
'user' => $this->getUser()->toArray(),
'acl' => $this->getAcl()->toArray(),
'preferences' => $this->getPreferences()->toArray(),
'token' => $this->getUser()->get('token')
);
}
public function actionDestroyAuthToken($params, $data)
{
$token = $data['token'];
if (empty($token)) {
throw new BadRequest();
}
$auth = new \Espo\Core\Utils\Auth($this->getContainer());
return $auth->destroyAuthToken($token);
}
$auth = new \Espo\Core\Utils\Auth($this->getContainer());
return $auth->destroyAuthToken($token);
}
}

View File

@@ -25,19 +25,19 @@ namespace Espo\Controllers;
class Attachment extends \Espo\Core\Controllers\Record
{
public function actionUpload($params, $data)
{
list($prefix, $contents) = explode(',', $data);
$contents = base64_decode($contents);
$attachment = $this->getEntityManager()->getEntity('Attachment');
$this->getEntityManager()->saveEntity($attachment);
$this->getContainer()->get('fileManager')->putContents('data/upload/' . $attachment->id, $contents);
return array(
'attachmentId' => $attachment->id
);
}
public function actionUpload($params, $data)
{
list($prefix, $contents) = explode(',', $data);
$contents = base64_decode($contents);
$attachment = $this->getEntityManager()->getEntity('Attachment');
$this->getEntityManager()->saveEntity($attachment);
$this->getContainer()->get('fileManager')->putContents('data/upload/' . $attachment->id, $contents);
return array(
'attachmentId' => $attachment->id
);
}
}

View File

@@ -0,0 +1,66 @@
<?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\Forbidden;
class AuthToken extends \Espo\Core\Controllers\Record
{
protected function checkControllerAccess()
{
if (!$this->getUser()->isAdmin()) {
throw new Forbidden();
}
}
public function actionUpdate($params, $data)
{
throw new Forbidden();
}
public function actionCreate($params, $data)
{
throw new Forbidden();
}
public function actionListLinked($params, $data)
{
throw new Forbidden();
}
public function actionMassUpdate($params, $data)
{
throw new Forbidden();
}
public function actionCreateLink($params, $data)
{
throw new Forbidden();
}
public function actionRemoveLink($params, $data)
{
throw new Forbidden();
}
}

View File

@@ -22,7 +22,45 @@
namespace Espo\Controllers;
use \Espo\Core\Exceptions\BadRequest;
use \Espo\Core\Exceptions\Forbidden;
use \Espo\Core\Exceptions\Error;
class Email extends \Espo\Core\Controllers\Record
{
public function actionGetCopiedAttachments($params, $data, $request)
{
$id = $request->get('id');
return $this->getRecordService()->getCopiedAttachments($id);
}
public function actionSendTestEmail($params, $data, $request)
{
if (!$request->isPost()) {
throw new BadRequest();
}
if (empty($data['password'])) {
if ($data['type'] == 'preferences') {
if (!$this->getUser()->isAdmin() && $data['id'] != $this->getUser()->id) {
throw new Forbidden();
}
$preferences = $this->getEntityManager()->getEntity('Preferences', $data['id']);
if (!$preferences) {
throw new Error();
}
$data['password'] = $this->getContainer()->get('crypt')->decrypt($preferences->get('smtpPassword'));
} else {
if (!$this->getUser()->isAdmin()) {
throw new Forbidden();
}
$data['password'] = $this->getConfig()->get('smtpPassword');
}
}
return $this->getRecordService()->sendTestEmail($data);
}
}

View File

@@ -0,0 +1,48 @@
<?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\Forbidden;
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')
));
}
protected function checkControllerAccess()
{
if (!$this->getAcl()->check('EmailAccountScope')) {
throw new Forbidden();
}
}
}

View File

@@ -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);
}
}

View File

@@ -26,20 +26,20 @@ use \Espo\Core\Exceptions\Error;
class EmailTemplate extends \Espo\Core\Controllers\Record
{
public function actionParse($params, $data, $request)
{
$id = $request->get('id');
$emailAddress = $request->get('emailAddress');
if (empty($id)) {
throw new Error();
}
return $this->getRecordService()->parse($id, array(
'emailAddress' => $request->get('emailAddress'),
'parentType' => $request->get('parentType'),
'parentId' => $request->get('parentId'),
), true);
}
public function actionParse($params, $data, $request)
{
$id = $request->get('id');
$emailAddress = $request->get('emailAddress');
if (empty($id)) {
throw new Error();
}
return $this->getRecordService()->parse($id, array(
'emailAddress' => $request->get('emailAddress'),
'parentType' => $request->get('parentType'),
'parentId' => $request->get('parentId'),
), true);
}
}

View 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();
}
}

View 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);
}
}

View File

@@ -23,66 +23,70 @@
namespace Espo\Controllers;
use \Espo\Core\Exceptions\Error,
\Espo\Core\Exceptions\Forbidden,
\Espo\Core\Exceptions\NotFound;
\Espo\Core\Exceptions\Forbidden,
\Espo\Core\Exceptions\NotFound;
class FieldManager extends \Espo\Core\Controllers\Base
{
protected function checkControllerAccess()
{
if (!$this->getUser()->isAdmin()) {
throw new Forbidden();
}
}
protected function checkControllerAccess()
{
if (!$this->getUser()->isAdmin()) {
throw new Forbidden();
}
}
public function actionRead($params, $data)
{
$data = $this->getContainer()->get('fieldManager')->read($params['name'], $params['scope']);
public function actionRead($params, $data)
{
$data = $this->getContainer()->get('fieldManager')->read($params['name'], $params['scope']);
if (!isset($data)) {
throw new NotFound();
}
if (!isset($data)) {
throw new NotFound();
}
return $data;
}
return $data;
}
public function actionCreate($params, $data)
{
if (empty($data['name'])) {
throw new Error("Field 'name' cannnot be empty");
}
public function actionCreate($params, $data)
{
if (empty($data['name'])) {
throw new Error("Field 'name' cannnot be empty");
}
$fieldManager = $this->getContainer()->get('fieldManager');
$fieldManager->create($data['name'], $data, $params['scope']);
$fieldManager = $this->getContainer()->get('fieldManager');
$fieldManager->create($data['name'], $data, $params['scope']);
try {
$this->getContainer()->get('dataManager')->rebuild($params['scope']);
} catch (Error $e) {
$fieldManager->delete($data['name'], $params['scope']);
throw new Error($e->getMessage());
}
try {
$this->getContainer()->get('dataManager')->rebuild($params['scope']);
} catch (Error $e) {
$fieldManager->delete($data['name'], $params['scope']);
throw new Error($e->getMessage());
}
return $fieldManager->read($data['name'], $params['scope']);
}
return $fieldManager->read($data['name'], $params['scope']);
}
public function actionUpdate($params, $data)
{
$fieldManager = $this->getContainer()->get('fieldManager');
$fieldManager->update($params['name'], $data, $params['scope']);
public function actionUpdate($params, $data)
{
$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']);
}
return $fieldManager->read($params['name'], $params['scope']);
}
public function actionDelete($params, $data)
{
$res = $this->getContainer()->get('fieldManager')->delete($params['name'], $params['scope']);
public function actionDelete($params, $data)
{
$res = $this->getContainer()->get('fieldManager')->delete($params['name'], $params['scope']);
$this->getContainer()->get('dataManager')->rebuildMetadata();
$this->getContainer()->get('dataManager')->rebuildMetadata();
return $res;
}
return $res;
}
}

View File

@@ -23,18 +23,18 @@
namespace Espo\Controllers;
use \Espo\Core\Exceptions\Error,
\Espo\Core\Exceptions\Forbidden;
\Espo\Core\Exceptions\Forbidden;
class GlobalSearch extends \Espo\Core\Controllers\Base
{
public function actionSearch($params, $data, $request)
{
$query = $params['query'];
$offset = $request->get('offset');
$maxSize = $request->get('maxSize');
return $this->getService('GlobalSearch')->find($query, $offset);
}
{
$query = $params['query'];
$offset = $request->get('offset');
$maxSize = $request->get('maxSize');
return $this->getService('GlobalSearch')->find($query, $offset, $maxSize);
}
}

View File

@@ -26,7 +26,7 @@ class I18n extends \Espo\Core\Controllers\Base
{
public function actionRead($params, $data)
{
return $this->getContainer()->get('language')->getAll();
}
{
return $this->getContainer()->get('language')->getAll();
}
}

View File

@@ -27,60 +27,61 @@ use \Espo\Core\Exceptions\Error;
use \Espo\Core\Exceptions\Forbidden;
class Import extends \Espo\Core\Controllers\Base
{
protected function getFileManager()
{
return $this->getContainer()->get('fileManager');
}
protected function getEntityManager()
{
return $this->getContainer()->get('entityManager');
}
public function actionUploadFile($params, $data)
{
$contents = $data;
$attachment = $this->getEntityManager()->getEntity('Attachment');
$attachment->set('type', 'text/csv');
$this->getEntityManager()->saveEntity($attachment);
$this->getFileManager()->putContents('data/upload/' . $attachment->id, $contents);
return array(
'attachmentId' => $attachment->id
);
}
public function actionRevert($params, $data)
{
return $this->getService('Import')->revert($data['entityType'], $data['idsToRemove']);
}
public function actionCreate($params, $data)
{
{
protected function getFileManager()
{
return $this->getContainer()->get('fileManager');
}
protected function getEntityManager()
{
return $this->getContainer()->get('entityManager');
}
public function actionUploadFile($params, $data)
{
$contents = $data;
$attachment = $this->getEntityManager()->getEntity('Attachment');
$attachment->set('type', 'text/csv');
$attachment->set('role', 'Import File');
$this->getEntityManager()->saveEntity($attachment);
$this->getFileManager()->putContents('data/upload/' . $attachment->id, $contents);
return array(
'attachmentId' => $attachment->id
);
}
public function actionRevert($params, $data)
{
return $this->getService('Import')->revert($data['entityType'], $data['idsToRemove']);
}
public function actionCreate($params, $data)
{
$importParams = array(
'headerRow' => $data['headerRow'],
'fieldDelimiter' => $data['fieldDelimiter'],
'textQualifier' => $data['textQualifier'],
'dateFormat' => $data['dateFormat'],
'timeFormat' => $data['timeFormat'],
'personNameFormat' => $data['personNameFormat'],
'decimalMark' => $data['decimalMark'],
'currency' => $data['currency'],
'defaultValues' => $data['defaultValues'],
'action' => $data['action'],
'headerRow' => $data['headerRow'],
'fieldDelimiter' => $data['fieldDelimiter'],
'textQualifier' => $data['textQualifier'],
'dateFormat' => $data['dateFormat'],
'timeFormat' => $data['timeFormat'],
'personNameFormat' => $data['personNameFormat'],
'decimalMark' => $data['decimalMark'],
'currency' => $data['currency'],
'defaultValues' => $data['defaultValues'],
'action' => $data['action'],
);
$attachmentId = $data['attachmentId'];
if (!$this->getAcl()->check($data['entityType'], 'edit')) {
throw new Forbidden();
throw new Forbidden();
}
return $this->getService('Import')->import($data['entityType'], $data['fields'], $attachmentId, $importParams);
}
return $this->getService('Import')->import($data['entityType'], $data['fields'], $attachmentId, $importParams);
}
}

View 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();
}
}

View File

@@ -25,33 +25,38 @@ namespace Espo\Controllers;
use Espo\Core\Utils as Utils;
use \Espo\Core\Exceptions\NotFound;
use \Espo\Core\Exceptions\Error;
use \Espo\Core\Exceptions\Forbidden;
class Layout extends \Espo\Core\Controllers\Base
{
public function actionRead($params, $data)
{
$data = $this->getContainer()->get('layout')->get($params['scope'], $params['name']);
if (empty($data)) {
throw new NotFound("Layout " . $params['scope'] . ":" . $params['name'] . ' is not found');
}
return $data;
}
{
$data = $this->getContainer()->get('layout')->get($params['scope'], $params['name']);
if (empty($data)) {
throw new NotFound("Layout " . $params['scope'] . ":" . $params['name'] . ' is not found');
}
return $data;
}
public function actionUpdate($params, $data)
{
public function actionUpdate($params, $data)
{
if (!$this->getUser()->isAdmin()) {
throw new Forbidden();
}
$result = $this->getContainer()->get('layout')->set($data, $params['scope'], $params['name']);
if ($result === false) {
throw new Error("Error while saving layout");
}
if ($result === false) {
throw new Error("Error while saving layout");
}
$this->getContainer()->get('dataManager')->updateCacheTimestamp();
$this->getContainer()->get('dataManager')->updateCacheTimestamp();
return $this->getContainer()->get('layout')->get($params['scope'], $params['name']);
}
return $this->getContainer()->get('layout')->get($params['scope'], $params['name']);
}
public function actionPatch($params, $data)
{
public function actionPatch($params, $data)
{
return $this->actionUpdate($params, $data);
}
}
}

View File

@@ -26,7 +26,7 @@ class Metadata extends \Espo\Core\Controllers\Base
{
public function actionRead($params, $data)
{
return $this->getMetadata()->getAll(true);
}
{
return $this->getMetadata()->getAll(true);
}
}

View File

@@ -26,35 +26,41 @@ use \Espo\Core\Exceptions\Error;
class Notification extends \Espo\Core\Controllers\Base
{
public static $defaultAction = 'list';
public static $defaultAction = 'list';
public function actionList($params, $data, $request)
{
$scope = $params['scope'];
$id = $params['id'];
$userId = $this->getUser()->id;
$offset = intval($request->get('offset'));
$maxSize = intval($request->get('maxSize'));
$params = array(
'offset' => $offset,
'maxSize' => $maxSize,
);
$result = $this->getService('Notification')->getList($userId, $params);
return array(
'total' => $result['total'],
'list' => $result['collection']->toArray()
);
}
public function actionNotReadCount()
{
$userId = $this->getUser()->id;
return $this->getService('Notification')->getNotReadCount($userId);
}
public function actionList($params, $data, $request)
{
$scope = $params['scope'];
$id = $params['id'];
$userId = $this->getUser()->id;
$offset = intval($request->get('offset'));
$maxSize = intval($request->get('maxSize'));
$params = array(
'offset' => $offset,
'maxSize' => $maxSize,
);
$result = $this->getService('Notification')->getList($userId, $params);
return array(
'total' => $result['total'],
'list' => $result['collection']->toArray()
);
}
public function actionNotReadCount()
{
$userId = $this->getUser()->id;
return $this->getService('Notification')->getNotReadCount($userId);
}
public function actionMarkAllRead($params, $data, $request)
{
$userId = $this->getUser()->id;
return $this->getService('Notification')->markAllRead($userId);
}
}

View File

@@ -24,69 +24,95 @@ namespace Espo\Controllers;
use \Espo\Core\Exceptions\Error;
use \Espo\Core\Exceptions\Forbidden;
use \Espo\Core\Exceptions\BadRequest;
use \Espo\Core\Exceptions\NotFound;
class Preferences extends \Espo\Core\Controllers\Base
{
protected function getPreferences()
{
return $this->getContainer()->get('preferences');
}
protected function getEntityManager()
{
return $this->getContainer()->get('entityManager');
}
protected function handleUserAccess($userId)
{
if (!$this->getUser()->isAdmin()) {
if ($this->getUser()->id != $userId) {
throw new Forbidden();
}
}
}
public function actionPatch($params, $data)
{
return $this->actionUpdate($params, $data);
}
{
protected function getPreferences()
{
return $this->getContainer()->get('preferences');
}
protected function getEntityManager()
{
return $this->getContainer()->get('entityManager');
}
protected function getCrypt()
{
return $this->getContainer()->get('crypt');
}
protected function handleUserAccess($userId)
{
if (!$this->getUser()->isAdmin()) {
if ($this->getUser()->id != $userId) {
throw new Forbidden();
}
}
}
public function actionDelete($params, $data)
{
$userId = $params['id'];
if (empty($userId)) {
throw new BadRequest();
}
$this->handleUserAccess($userId);
return $this->getEntityManager()->getRepository('Preferences')->resetToDefaults($userId);
}
public function actionPatch($params, $data)
{
return $this->actionUpdate($params, $data);
}
public function actionUpdate($params, $data)
{
$userId = $params['id'];
$this->handleUserAccess($userId);
$user = $this->getEntityManager()->getEntity('User', $userId);
public function actionUpdate($params, $data)
{
$userId = $params['id'];
$this->handleUserAccess($userId);
if (array_key_exists('smtpPassword', $data)) {
$data['smtpPassword'] = $this->getCrypt()->encrypt($data['smtpPassword']);
}
$user = $this->getEntityManager()->getEntity('User', $userId);
$entity = $this->getEntityManager()->getEntity('Preferences', $userId);
if ($entity) {
$entity->set($data);
$this->getEntityManager()->saveEntity($entity);
$entity->set('smtpEmailAddress', $user->get('emailAddress'));
$entity->set('name', $user->get('name'));
return $entity->toArray();
}
throw new Error();
}
$entity = $this->getEntityManager()->getEntity('Preferences', $userId);
if ($entity) {
$entity->set($data);
$this->getEntityManager()->saveEntity($entity);
$entity->set('smtpEmailAddress', $user->get('emailAddress'));
$entity->set('name', $user->get('name'));
$entity->clear('smtpPassword');
return $entity->toArray();
}
throw new Error();
}
public function actionRead($params)
{
$userId = $params['id'];
$this->handleUserAccess($userId);
{
$userId = $params['id'];
$this->handleUserAccess($userId);
$entity = $this->getEntityManager()->getEntity('Preferences', $userId);
$user = $this->getEntityManager()->getEntity('User', $userId);
$entity->set('smtpEmailAddress', $user->get('emailAddress'));
$entity->set('name', $user->get('name'));
if ($entity) {
return $entity->toArray();
}
throw new NotFound();
}
$entity = $this->getEntityManager()->getEntity('Preferences', $userId);
$user = $this->getEntityManager()->getEntity('User', $userId);
$entity->set('smtpEmailAddress', $user->get('emailAddress'));
$entity->set('name', $user->get('name'));
$entity->clear('smtpPassword');
if ($entity) {
return $entity->toArray();
}
throw new NotFound();
}
}

View File

@@ -24,11 +24,11 @@ namespace Espo\Controllers;
class ScheduledJob extends \Espo\Core\Controllers\Record
{
protected function checkControllerAccess()
{
if (!$this->getUser()->isAdmin()) {
throw new Forbidden();
}
}
protected function checkControllerAccess()
{
if (!$this->getUser()->isAdmin()) {
throw new Forbidden();
}
}
}

View File

@@ -24,11 +24,11 @@ namespace Espo\Controllers;
class ScheduledJobLogRecord extends \Espo\Core\Controllers\Record
{
protected function checkControllerAccess()
{
if (!$this->getUser()->isAdmin()) {
throw new Forbidden();
}
}
protected function checkControllerAccess()
{
if (!$this->getUser()->isAdmin()) {
throw new Forbidden();
}
}
}

View File

@@ -27,41 +27,48 @@ use \Espo\Core\Exceptions\Forbidden;
class Settings extends \Espo\Core\Controllers\Base
{
protected function getConfigData()
{
$data = $this->getConfig()->getData($this->getUser()->isAdmin());
$fieldDefs = $this->getMetadata()->get('entityDefs.Settings.fields');
foreach ($fieldDefs as $field => $d) {
if ($d['type'] == 'password') {
unset($data[$field]);
}
}
return $data;
}
public function actionRead($params, $data)
{
return $this->getConfigData();
}
protected function getConfigData()
{
$data = $this->getConfig()->getData($this->getUser()->isAdmin());
public function actionUpdate($params, $data)
{
return $this->actionPatch($params, $data);
}
$fieldDefs = $this->getMetadata()->get('entityDefs.Settings.fields');
public function actionPatch($params, $data)
{
if (!$this->getUser()->isAdmin()) {
throw new Forbidden();
}
$result = $this->getConfig()->setData($data, $this->getUser()->isAdmin());
if ($result === false) {
throw new Error('Cannot save settings');
}
foreach ($fieldDefs as $field => $d) {
if ($d['type'] == 'password') {
unset($data[$field]);
}
}
return $data;
}
return $this->getConfigData();
}
public function actionRead($params, $data)
{
return $this->getConfigData();
}
public function actionUpdate($params, $data)
{
return $this->actionPatch($params, $data);
}
public function actionPatch($params, $data)
{
if (!$this->getUser()->isAdmin()) {
throw new Forbidden();
}
$this->getConfig()->setData($data, $this->getUser()->isAdmin());
$result = $this->getConfig()->save();
if ($result === false) {
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();
}
}

View File

@@ -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\Controllers;
@@ -26,38 +26,38 @@ use \Espo\Core\Exceptions\Error;
class Stream extends \Espo\Core\Controllers\Base
{
const MAX_SIZE_LIMIT = 400;
public static $defaultAction = 'list';
const MAX_SIZE_LIMIT = 400;
public static $defaultAction = 'list';
public function actionList($params, $data, $request)
{
$scope = $params['scope'];
$id = $params['id'];
$offset = intval($request->get('offset'));
$maxSize = intval($request->get('maxSize'));
$after = $request->get('after');
$service = $this->getService('Stream');
if (empty($maxSize)) {
$maxSize = self::MAX_SIZE_LIMIT;
}
if (!empty($maxSize) && $maxSize > self::MAX_SIZE_LIMIT) {
throw new Forbidden();
}
$result = $service->find($scope, $id, array(
'offset' => $offset,
'maxSize' => $maxSize,
'after' => $after,
));
return array(
'total' => $result['total'],
'list' => $result['collection']->toArray()
);
}
{
$scope = $params['scope'];
$id = isset($params['id']) ? $params['id'] : null;
$offset = intval($request->get('offset'));
$maxSize = intval($request->get('maxSize'));
$after = $request->get('after');
$service = $this->getService('Stream');
if (empty($maxSize)) {
$maxSize = self::MAX_SIZE_LIMIT;
}
if (!empty($maxSize) && $maxSize > self::MAX_SIZE_LIMIT) {
throw new Forbidden();
}
$result = $service->find($scope, $id, array(
'offset' => $offset,
'maxSize' => $maxSize,
'after' => $after,
));
return array(
'total' => $result['total'],
'list' => $result['collection']->toArray()
);
}
}

View File

@@ -24,6 +24,6 @@ namespace Espo\Controllers;
class Team extends \Espo\Core\Controllers\Record
{
}

View File

@@ -27,31 +27,31 @@ use \Espo\Core\Exceptions\NotFound;
use \Espo\Core\Exceptions\Forbidden;
class User extends \Espo\Core\Controllers\Record
{
public function actionAcl($params, $data, $request)
{
$userId = $request->get('id');
if (empty($userId)) {
throw new Error();
}
if (!$this->getUser()->isAdmin() && $this->getUser()->id != $userId) {
throw new Forbidden();
}
$user = $this->getEntityManager()->getEntity('User', $userId);
if (empty($user)) {
throw new NotFound();
}
$acl = new \Espo\Core\Acl($user);
return $acl->toArray();
}
public function actionChangeOwnPassword($params, $data)
{
return $this->getService('User')->changePassword($this->getUser()->id, $data['password']);
}
{
public function actionAcl($params, $data, $request)
{
$userId = $request->get('id');
if (empty($userId)) {
throw new Error();
}
if (!$this->getUser()->isAdmin() && $this->getUser()->id != $userId) {
throw new Forbidden();
}
$user = $this->getEntityManager()->getEntity('User', $userId);
if (empty($user)) {
throw new NotFound();
}
$acl = new \Espo\Core\Acl($user, $this->getConfig(), $this->getContainer()->get('fileManager'), $this->getMetadata());
return $acl->toArray();
}
public function actionChangeOwnPassword($params, $data)
{
return $this->getService('User')->changePassword($this->getUser()->id, $data['password']);
}
}

View File

@@ -18,248 +18,264 @@
*
* 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;
use \Espo\Core\Exceptions\Error;
use \Espo\ORM\Entity;
class Acl
{
private $data = array();
private $data = array();
private $cacheFile;
private $cacheFile;
private $actionList = array('read', 'edit', 'delete');
private $actionList = array('read', 'edit', 'delete');
private $levelList = array('all', 'team', 'own', 'no');
private $fileManager;
private $levelList = array('all', 'team', 'own', 'no');
public function __construct(\Espo\Entities\User $user, $config = null, $fileManager = null)
{
$this->user = $user;
if (!$this->user->isFetched()) {
throw new Error();
}
$this->user->loadLinkMultipleField('teams');
if ($fileManager) {
$this->fileManager = $fileManager;
}
$this->cacheFile = 'data/cache/application/acl/' . $user->id . '.php';
if ($config && $config->get('useCache') && file_exists($this->cacheFile)) {
$cached = include $this->cacheFile;
$this->data = $cached;
$this->initSolid();
} else {
$this->load();
$this->initSolid();
if ($config && $fileManager && $config->get('useCache')) {
$this->buildCache();
}
}
protected $fileManager;
}
public function checkScope($scope, $action = null, $isOwner = null, $inTeam = null)
{
if (array_key_exists($scope, $this->data)) {
if ($this->data[$scope] === false) {
return false;
}
if ($this->data[$scope] === true) {
return true;
}
if (!is_null($action)) {
if (array_key_exists($action, $this->data[$scope])) {
$value = $this->data[$scope][$action];
if ($value === 'all' || $value === true) {
return true;
}
if (!$value || $value === 'no') {
return false;
}
if (is_null($isOwner)) {
return true;
}
if ($isOwner) {
if ($value === 'own' || $value === 'team') {
return true;
}
}
if ($inTeam) {
if ($value === 'team') {
return true;
}
}
return false;
}
}
return true;
}
return true;
}
public function toArray()
{
return $this->data;
}
protected $metadata;
public function check($subject, $action = null, $isOwner = null, $inTeam = null)
{
if ($this->user->isAdmin()) {
return true;
}
if (is_string($subject)) {
return $this->checkScope($subject, $action, $isOwner, $inTeam);
} else {
$entity = $subject;
$entityName = $entity->getEntityName();
return $this->checkScope($entityName, $action, $this->checkIsOwner($entity), $this->checkInTeam($entity));
}
}
public function checkReadOnlyTeam($scope)
{
if (isset($this->data[$scope]) && isset($this->data[$scope]['read'])) {
return $this->data[$scope]['read'] === 'team';
}
return false;
}
public function checkReadOnlyOwn($scope)
{
if ($this->user->isAdmin()) {
return false;
}
if (isset($this->data[$scope]) && isset($this->data[$scope]['read'])) {
return $this->data[$scope]['read'] === 'own';
}
return false;
}
public function checkIsOwner($entity)
{
if ($this->user->isAdmin()) {
return false;
}
$userId = $this->user->id;
if ($userId === $entity->get('assignedUserId') || $userId === $entity->get('createdById')) {
return true;
}
return false;
}
public function checkInTeam($entity)
{
$userTeamIds = $this->user->get('teamsIds');
$teamIds = $entity->get('teamsIds');
foreach ($userTeamIds as $id) {
if (in_array($id, $teamIds)) {
return true;
}
}
return false;
}
public function __construct(\Espo\Entities\User $user, $config = null, $fileManager = null, $metadata = null)
{
$this->user = $user;
private function load()
{
$aclTables = array();
$this->metadata = $metadata;
$userRoles = $this->user->get('roles');
foreach ($userRoles as $role) {
$aclTables[] = json_decode($role->get('data'));
}
if (!$this->user->isFetched()) {
throw new Error();
}
$teams = $this->user->get('teams');
foreach ($teams as $team) {
$teamRoles = $team->get('roles');
foreach ($teamRoles as $role) {
$aclTables[] = json_decode($role->get('data'));
}
}
$this->user->loadLinkMultipleField('teams');
$this->data = $this->merge($aclTables);
}
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',
);
}
if ($fileManager) {
$this->fileManager = $fileManager;
}
private function merge($tables)
{
$data = array();
foreach ($tables as $table) {
foreach ($table as $scope => $row) {
if ($row == false) {
if (!isset($data[$scope])) {
$data[$scope] = false;
}
} else {
if (!isset($data[$scope])) {
$data[$scope] = array();
}
if ($data[$scope] == false) {
$data[$scope] = array();
}
foreach ($row as $action => $level) {
if (!isset($data[$scope][$action])) {
$data[$scope][$action] = $level;
} else {
if (array_search($data[$scope][$action], $this->levelList) > array_search($level, $this->levelList)) {
$data[$scope][$action] = $level;
}
}
}
}
}
}
return $data;
}
$this->cacheFile = 'data/cache/application/acl/' . $user->id . '.php';
private function buildCache()
{
$contents = '<' . '?'. 'php return ' . var_export($this->data, true) . ';';
$this->fileManager->putContents($this->cacheFile, $contents);
}
if ($config && $config->get('useCache') && file_exists($this->cacheFile)) {
$cached = include $this->cacheFile;
$this->data = $cached;
$this->initSolid();
} else {
$this->load();
$this->initSolid();
if ($config && $fileManager && $config->get('useCache')) {
$this->buildCache();
}
}
}
public function checkScope($scope, $action = null, $isOwner = null, $inTeam = null, $entity = null)
{
if (array_key_exists($scope, $this->data)) {
if ($this->data[$scope] === false) {
return false;
}
if ($this->data[$scope] === true) {
return true;
}
if (!is_null($action)) {
if (array_key_exists($action, $this->data[$scope])) {
$value = $this->data[$scope][$action];
if ($value === 'all' || $value === true) {
return true;
}
if (!$value || $value === 'no') {
return false;
}
if (is_null($isOwner)) {
return true;
}
if ($isOwner) {
if ($value === 'own' || $value === 'team') {
return true;
}
}
if ($inTeam === null && $entity) {
$inTeam = $this->checkInTeam($entity);
}
if ($inTeam) {
if ($value === 'team') {
return true;
}
}
return false;
}
}
return true;
}
return true;
}
public function toArray()
{
return $this->data;
}
public function getLevel($scope, $action)
{
if ($this->user->isAdmin()) {
return 'all';
}
if (array_key_exists($scope, $this->data)) {
if (array_key_exists($action, $this->data[$scope])) {
return $this->data[$scope][$action];
}
}
return false;
}
public function check($subject, $action = null, $isOwner = null, $inTeam = null)
{
if ($this->user->isAdmin()) {
return true;
}
if (is_string($subject)) {
return $this->checkScope($subject, $action, $isOwner, $inTeam);
} else {
$entity = $subject;
if ($entity instanceof Entity) {
$entityName = $entity->getEntityName();
return $this->checkScope($entityName, $action, $this->checkIsOwner($entity), $inTeam, $entity);
}
}
}
public function checkReadOnlyTeam($scope)
{
if (isset($this->data[$scope]) && isset($this->data[$scope]['read'])) {
return $this->data[$scope]['read'] === 'team';
}
return false;
}
public function checkReadOnlyOwn($scope)
{
if ($this->user->isAdmin()) {
return false;
}
if (isset($this->data[$scope]) && isset($this->data[$scope]['read'])) {
return $this->data[$scope]['read'] === 'own';
}
return false;
}
public function checkIsOwner($entity)
{
if ($this->user->isAdmin()) {
return false;
}
$userId = $this->user->id;
if ($userId === $entity->get('assignedUserId') || $userId === $entity->get('createdById')) {
return true;
}
return false;
}
public function checkInTeam($entity)
{
$userTeamIds = $this->user->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)) {
return true;
}
}
return false;
}
private function load()
{
$aclTables = array();
$userRoles = $this->user->get('roles');
foreach ($userRoles as $role) {
$aclTables[] = json_decode($role->get('data'));
}
$teams = $this->user->get('teams');
foreach ($teams as $team) {
$teamRoles = $team->get('roles');
foreach ($teamRoles as $role) {
$aclTables[] = json_decode($role->get('data'));
}
}
$this->data = $this->merge($aclTables);
}
private function initSolid()
{
$data = $this->metadata->get('app.acl.solid', array());
foreach ($data as $entityName => $item) {
$this->data[$entityName] = $item;
}
}
private function merge($tables)
{
$data = array();
foreach ($tables as $table) {
foreach ($table as $scope => $row) {
if ($row == false) {
if (!isset($data[$scope])) {
$data[$scope] = false;
}
} else {
if (!isset($data[$scope])) {
$data[$scope] = array();
}
if ($data[$scope] == false) {
$data[$scope] = array();
}
foreach ($row as $action => $level) {
if (!isset($data[$scope][$action])) {
$data[$scope][$action] = $level;
} else {
if (array_search($data[$scope][$action], $this->levelList) > array_search($level, $this->levelList)) {
$data[$scope][$action] = $level;
}
}
}
}
}
}
return $data;
}
private function buildCache()
{
$contents = '<' . '?'. 'php return ' . var_export($this->data, true) . ';';
$this->fileManager->putContents($this->cacheFile, $contents);
}
}

View File

@@ -25,54 +25,54 @@ namespace Espo\Core;
class Application
{
private $metadata;
private $metadata;
private $container;
private $container;
private $slim;
private $slim;
private $auth;
private $auth;
/**
/**
* Constructor
*/
public function __construct()
{
$this->container = new Container();
$this->container = new Container();
date_default_timezone_set('UTC');
date_default_timezone_set('UTC');
$GLOBALS['log'] = $this->container->get('log');
$GLOBALS['log'] = $this->container->get('log');
}
public function getSlim()
{
if (empty($this->slim)) {
$this->slim = $this->container->get('slim');
}
return $this->slim;
}
public function getSlim()
{
if (empty($this->slim)) {
$this->slim = $this->container->get('slim');
}
return $this->slim;
}
public function getMetadata()
{
if (empty($this->metadata)) {
$this->metadata = $this->container->get('metadata');
}
return $this->metadata;
}
public function getMetadata()
{
if (empty($this->metadata)) {
$this->metadata = $this->container->get('metadata');
}
return $this->metadata;
}
protected function getAuth()
{
if (empty($this->auth)) {
$this->auth = new \Espo\Core\Utils\Auth($this->container);
}
return $this->auth;
if (empty($this->auth)) {
$this->auth = new \Espo\Core\Utils\Auth($this->container);
}
return $this->auth;
}
public function getContainer()
{
return $this->container;
}
public function getContainer()
{
return $this->container;
}
public function run($name = 'default')
{
@@ -83,163 +83,160 @@ class Application
public function runClient()
{
$config = $this->getContainer()->get('config');
$config = $this->getContainer()->get('config');
$html = file_get_contents('main.html');
$html = str_replace('{{cacheTimestamp}}', $config->get('cacheTimestamp', 0), $html);
$html = str_replace('{{useCache}}', $config->get('useCache') ? 'true' : 'false' , $html);
echo $html;
exit;
$html = file_get_contents('main.html');
$html = str_replace('{{cacheTimestamp}}', $config->get('cacheTimestamp', 0), $html);
$html = str_replace('{{useCache}}', $config->get('useCache') ? 'true' : 'false' , $html);
echo $html;
exit;
}
public function runEntryPoint($entryPoint)
{
if (empty($entryPoint)) {
throw new \Error();
}
if (empty($entryPoint)) {
throw new \Error();
}
$slim = $this->getSlim();
$container = $this->getContainer();
$slim = $this->getSlim();
$container = $this->getContainer();
$slim->get('/', function() {});
$slim->get('/', function() {});
$entryPointManager = new \Espo\Core\EntryPointManager($container);
$entryPointManager = new \Espo\Core\EntryPointManager($container);
$auth = $this->getAuth();
$apiAuth = new \Espo\Core\Utils\Api\Auth($auth, $entryPointManager->checkAuthRequired($entryPoint), true);
$slim->add($apiAuth);
$auth = $this->getAuth();
$apiAuth = new \Espo\Core\Utils\Api\Auth($auth, $entryPointManager->checkAuthRequired($entryPoint), true);
$slim->add($apiAuth);
$slim->hook('slim.before.dispatch', function () use ($entryPoint, $entryPointManager, $container) {
try {
$entryPointManager->run($entryPoint);
} catch (\Exception $e) {
$container->get('output')->processError($e->getMessage(), $e->getCode(), true);
}
});
$slim->hook('slim.before.dispatch', function () use ($entryPoint, $entryPointManager, $container) {
try {
$entryPointManager->run($entryPoint);
} catch (\Exception $e) {
$container->get('output')->processError($e->getMessage(), $e->getCode(), true);
}
});
$slim->run();
$slim->run();
}
public function runCron()
{
$auth = $this->getAuth();
$auth->useNoAuth(true);
$auth = $this->getAuth();
$auth->useNoAuth(true);
$cronManager = new \Espo\Core\CronManager($this->container);
$cronManager->run();
$cronManager = new \Espo\Core\CronManager($this->container);
$cronManager->run();
}
public function runRebuild()
{
$auth = $this->getAuth();
$auth->useNoAuth(true);
$dataManager = $this->getContainer()->get('dataManager');
$dataManager->rebuild();
$dataManager = $this->getContainer()->get('dataManager');
$dataManager->rebuild();
}
public function isInstalled()
{
$config = $this->getContainer()->get('config');
$config = $this->getContainer()->get('config');
if (file_exists($config->getConfigPath()) && $config->get('isInstalled')) {
return true;
}
if (file_exists($config->getConfigPath()) && $config->get('isInstalled')) {
return true;
}
return false;
return false;
}
protected function routeHooks()
{
$container = $this->getContainer();
$slim = $this->getSlim();
protected function routeHooks()
{
$container = $this->getContainer();
$slim = $this->getSlim();
$auth = $this->getAuth();
$auth = $this->getAuth();
$apiAuth = new \Espo\Core\Utils\Api\Auth($auth);
$this->getSlim()->add($apiAuth);
$apiAuth = new \Espo\Core\Utils\Api\Auth($auth);
$this->getSlim()->add($apiAuth);
$this->getSlim()->hook('slim.before.dispatch', function () use ($slim, $container) {
$this->getSlim()->hook('slim.before.dispatch', function () use ($slim, $container) {
$route = $slim->router()->getCurrentRoute();
$conditions = $route->getConditions();
$route = $slim->router()->getCurrentRoute();
$conditions = $route->getConditions();
if (isset($conditions['useController']) && $conditions['useController'] == false) {
return;
}
if (isset($conditions['useController']) && $conditions['useController'] == false) {
return;
}
$routeOptions = call_user_func($route->getCallable());
$routeKeys = is_array($routeOptions) ? array_keys($routeOptions) : array();
$routeOptions = call_user_func($route->getCallable());
$routeKeys = is_array($routeOptions) ? array_keys($routeOptions) : array();
if (!in_array('controller', $routeKeys, true)) {
return $container->get('output')->render($routeOptions);
}
if (!in_array('controller', $routeKeys, true)) {
return $container->get('output')->render($routeOptions);
}
$params = $route->getParams();
$data = $slim->request()->getBody();
$params = $route->getParams();
$data = $slim->request()->getBody();
foreach ($routeOptions as $key => $value) {
if (strstr($value, ':')) {
$paramName = str_replace(':', '', $value);
$value = $params[$paramName];
}
$controllerParams[$key] = $value;
}
foreach ($routeOptions as $key => $value) {
if (strstr($value, ':')) {
$paramName = str_replace(':', '', $value);
$value = $params[$paramName];
}
$controllerParams[$key] = $value;
}
$params = array_merge($params, $controllerParams);
$params = array_merge($params, $controllerParams);
$controllerName = ucfirst($controllerParams['controller']);
$controllerName = ucfirst($controllerParams['controller']);
if (!empty($controllerParams['action'])) {
$actionName = $controllerParams['action'];
} else {
$httpMethod = strtolower($slim->request()->getMethod());
$crudList = $container->get('config')->get('crud');
$actionName = $crudList[$httpMethod];
}
if (!empty($controllerParams['action'])) {
$actionName = $controllerParams['action'];
} else {
$httpMethod = strtolower($slim->request()->getMethod());
$crudList = $container->get('config')->get('crud');
$actionName = $crudList[$httpMethod];
}
try {
$controllerManager = new \Espo\Core\ControllerManager($container);
$result = $controllerManager->process($controllerName, $actionName, $params, $data, $slim->request());
$container->get('output')->render($result);
} catch (\Exception $e) {
$container->get('output')->processError($e->getMessage(), $e->getCode());
}
});
try {
$controllerManager = new \Espo\Core\ControllerManager($container);
$result = $controllerManager->process($controllerName, $actionName, $params, $data, $slim->request());
$container->get('output')->render($result);
} catch (\Exception $e) {
$container->get('output')->processError($e->getMessage(), $e->getCode());
}
});
$this->getSlim()->hook('slim.after.router', function () use (&$slim) {
$slim->contentType('application/json');
$this->getSlim()->hook('slim.after.router', function () use (&$slim) {
$slim->contentType('application/json');
$res = $slim->response();
$res->header('Expires', '0');
$res->header('Last-Modified', gmdate("D, d M Y H:i:s") . " GMT");
$res->header('Cache-Control', 'no-store, no-cache, must-revalidate, post-check=0, pre-check=0');
$res->header('Pragma', 'no-cache');
});
}
$res = $slim->response();
$res->header('Expires', '0');
$res->header('Last-Modified', gmdate("D, d M Y H:i:s") . " GMT");
$res->header('Cache-Control', 'no-store, no-cache, must-revalidate, post-check=0, pre-check=0');
$res->header('Pragma', 'no-cache');
});
}
protected function initRoutes()
{
$routes = new \Espo\Core\Utils\Route($this->getContainer()->get('config'), $this->getMetadata(), $this->getContainer()->get('fileManager'));
$crudList = array_keys( $this->getContainer()->get('config')->get('crud') );
protected function initRoutes()
{
$routes = new \Espo\Core\Utils\Route($this->getContainer()->get('config'), $this->getMetadata(), $this->getContainer()->get('fileManager'));
$crudList = array_keys( $this->getContainer()->get('config')->get('crud') );
foreach ($routes->getAll() as $route) {
foreach ($routes->getAll() as $route) {
$method = strtolower($route['method']);
if (!in_array($method, $crudList)) {
$GLOBALS['log']->error('Route: Method ['.$method.'] does not exist. Please check your route ['.$route['route'].']');
continue;
}
$method = strtolower($route['method']);
if (!in_array($method, $crudList)) {
$GLOBALS['log']->error('Route: Method ['.$method.'] does not exist. Please check your route ['.$route['route'].']');
continue;
}
$currentRoute = $this->getSlim()->$method($route['route'], function() use ($route) { //todo change "use" for php 5.4
return $route['params'];
});
return $route['params'];
});
if (isset($route['conditions'])) {
$currentRoute->conditions($route['conditions']);
}
}
}
if (isset($route['conditions'])) {
$currentRoute->conditions($route['conditions']);
}
}
}
}

View File

@@ -25,10 +25,10 @@ namespace Espo\Core;
class Container
{
private $data = array();
private $data = array();
/**
/**
* Constructor
*/
public function __construct()
@@ -38,186 +38,205 @@ class Container
public function get($name)
{
if (empty($this->data[$name])) {
$this->load($name);
}
return $this->data[$name];
if (empty($this->data[$name])) {
$this->load($name);
}
return $this->data[$name];
}
private function load($name)
{
$loadMethod = 'load' . ucfirst($name);
if (method_exists($this, $loadMethod)) {
$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);
$loadMethod = 'load' . ucfirst($name);
if (method_exists($this, $loadMethod)) {
$obj = $this->$loadMethod();
$this->data[$name] = $obj;
} else {
$className = '\Espo\Custom\Core\Loaders\\'.ucfirst($name);
if (!class_exists($className)) {
$className = '\Espo\Core\Loaders\\'.ucfirst($name);
$className = '\Espo\Core\Loaders\\'.ucfirst($name);
}
if (class_exists($className)) {
$loadClass = new $className($this);
$this->data[$name] = $loadClass->load();
}
}
if (class_exists($className)) {
$loadClass = new $className($this);
$this->data[$name] = $loadClass->load();
}
}
// TODO throw an exception
return null;
return null;
}
protected function getServiceClassName($name, $default)
{
$metadata = $this->get('metadata');
$className = $metadata->get('app.serviceContainer.classNames.' . $name, $default);
return $className;
}
protected function loadContainer()
{
return $this;
}
private function loadSlim()
{
//return new \Slim\Slim();
return new \Espo\Core\Utils\Api\Slim();
}
private function loadFileManager()
private function loadFileManager()
{
return new \Espo\Core\Utils\File\Manager(
$this->get('config')
);
return new \Espo\Core\Utils\File\Manager(
$this->get('config')
);
}
private function loadPreferences()
private function loadPreferences()
{
return $this->get('entityManager')->getEntity('Preferences', $this->get('user')->id);
return $this->get('entityManager')->getEntity('Preferences', $this->get('user')->id);
}
private function loadConfig()
private function loadConfig()
{
return new \Espo\Core\Utils\Config(
new \Espo\Core\Utils\File\Manager()
);
return new \Espo\Core\Utils\Config(
new \Espo\Core\Utils\File\Manager()
);
}
private function loadHookManager()
private function loadHookManager()
{
return new \Espo\Core\HookManager(
$this
);
return new \Espo\Core\HookManager(
$this
);
}
private function loadOutput()
private function loadOutput()
{
return new \Espo\Core\Utils\Api\Output(
$this->get('slim')
);
return new \Espo\Core\Utils\Api\Output(
$this->get('slim')
);
}
private function loadMailSender()
private function loadMailSender()
{
return new \Espo\Core\Mail\Sender(
$this->get('config')
);
$className = $this->getServiceClassName('mailSernder', '\\Espo\\Core\\Mail\\Sender');
return new $className(
$this->get('config')
);
}
private function loadDateTime()
private function loadDateTime()
{
return new \Espo\Core\Utils\DateTime(
$this->get('config')->get('dateFormat'),
$this->get('config')->get('timeFormat'),
$this->get('config')->get('timeZone')
);
return new \Espo\Core\Utils\DateTime(
$this->get('config')->get('dateFormat'),
$this->get('config')->get('timeFormat'),
$this->get('config')->get('timeZone')
);
}
private function loadServiceFactory()
private function loadServiceFactory()
{
return new \Espo\Core\ServiceFactory(
$this
);
return new \Espo\Core\ServiceFactory(
$this
);
}
private function loadSelectManagerFactory()
private function loadSelectManagerFactory()
{
return new \Espo\Core\SelectManagerFactory(
$this->get('entityManager'),
$this->get('user'),
$this->get('acl'),
$this->get('metadata')
);
return new \Espo\Core\SelectManagerFactory(
$this->get('entityManager'),
$this->get('user'),
$this->get('acl'),
$this->get('metadata')
);
}
private function loadMetadata()
private function loadMetadata()
{
return new \Espo\Core\Utils\Metadata(
$this->get('config'),
$this->get('fileManager')
);
return new \Espo\Core\Utils\Metadata(
$this->get('config'),
$this->get('fileManager')
);
}
private function loadLayout()
private function loadLayout()
{
return new \Espo\Core\Utils\Layout(
$this->get('fileManager'),
$this->get('metadata')
);
return new \Espo\Core\Utils\Layout(
$this->get('fileManager'),
$this->get('metadata')
);
}
private function loadAcl()
{
return new \Espo\Core\Acl(
$this->get('user'),
$this->get('config'),
$this->get('fileManager')
);
}
private function loadAcl()
{
$className = $this->getServiceClassName('acl', '\\Espo\\Core\\Acl');
return new $className(
$this->get('user'),
$this->get('config'),
$this->get('fileManager'),
$this->get('metadata')
);
}
private function loadSchema()
{
return new \Espo\Core\Utils\Database\Schema\Schema(
$this->get('config'),
$this->get('metadata'),
$this->get('fileManager'),
$this->get('entityManager'),
$this->get('classParser')
);
}
private function loadSchema()
{
return new \Espo\Core\Utils\Database\Schema\Schema(
$this->get('config'),
$this->get('metadata'),
$this->get('fileManager'),
$this->get('entityManager'),
$this->get('classParser')
);
}
private function loadClassParser()
{
return new \Espo\Core\Utils\File\ClassParser(
$this->get('fileManager'),
$this->get('config'),
$this->get('metadata')
);
}
private function loadClassParser()
{
return new \Espo\Core\Utils\File\ClassParser(
$this->get('fileManager'),
$this->get('config'),
$this->get('metadata')
);
}
private function loadLanguage()
{
return new \Espo\Core\Utils\Language(
$this->get('fileManager'),
$this->get('config'),
$this->get('preferences')
);
}
private function loadLanguage()
{
return new \Espo\Core\Utils\Language(
$this->get('fileManager'),
$this->get('config'),
$this->get('preferences')
);
}
private function loadCrypt()
{
return new \Espo\Core\Utils\Crypt(
$this->get('config')
);
}
private function loadScheduledJob()
{
return new \Espo\Core\Cron\ScheduledJob(
$this
);
}
private function loadScheduledJob()
{
return new \Espo\Core\Cron\ScheduledJob(
$this
);
}
private function loadDataManager()
{
return new \Espo\Core\DataManager(
$this
);
}
private function loadDataManager()
{
return new \Espo\Core\DataManager(
$this
);
}
private function loadFieldManager()
{
return new \Espo\Core\Utils\FieldManager(
$this->get('metadata'),
$this->get('language')
);
}
private function loadFieldManager()
{
return new \Espo\Core\Utils\FieldManager(
$this->get('metadata'),
$this->get('language')
);
}
public function setUser($user)
{
$this->data['user'] = $user;
}
public function setUser($user)
{
$this->data['user'] = $user;
}
}

View File

@@ -27,88 +27,88 @@ use \Espo\Core\Exceptions\NotFound;
class ControllerManager
{
private $config;
private $config;
private $metadata;
private $metadata;
private $container;
private $container;
public function __construct(\Espo\Core\Container $container)
{
$this->container = $container;
public function __construct(\Espo\Core\Container $container)
{
$this->container = $container;
$this->config = $this->container->get('config');
$this->metadata = $this->container->get('metadata');
}
$this->config = $this->container->get('config');
$this->metadata = $this->container->get('metadata');
}
protected function getConfig()
{
return $this->config;
}
{
return $this->config;
}
protected function getMetadata()
{
return $this->metadata;
}
protected function getMetadata()
{
return $this->metadata;
}
public function process($controllerName, $actionName, $params, $data, $request)
{
$customeClassName = '\\Espo\\Custom\\Controllers\\' . Util::normilizeClassName($controllerName);
if (class_exists($customeClassName)) {
$controllerClassName = $customeClassName;
} else {
$moduleName = $this->metadata->getScopeModuleName($controllerName);
if ($moduleName) {
$controllerClassName = '\\Espo\\Modules\\' . $moduleName . '\\Controllers\\' . Util::normilizeClassName($controllerName);
} else {
$controllerClassName = '\\Espo\\Controllers\\' . Util::normilizeClassName($controllerName);
}
}
public function process($controllerName, $actionName, $params, $data, $request)
{
$customeClassName = '\\Espo\\Custom\\Controllers\\' . Util::normilizeClassName($controllerName);
if (class_exists($customeClassName)) {
$controllerClassName = $customeClassName;
} else {
$moduleName = $this->metadata->getScopeModuleName($controllerName);
if ($moduleName) {
$controllerClassName = '\\Espo\\Modules\\' . $moduleName . '\\Controllers\\' . Util::normilizeClassName($controllerName);
} else {
$controllerClassName = '\\Espo\\Controllers\\' . Util::normilizeClassName($controllerName);
}
}
if ($data && stristr($request->getContentType(), 'application/json')) {
$data = json_decode($data);
}
if ($data && stristr($request->getContentType(), 'application/json')) {
$data = json_decode($data);
}
if ($data instanceof \stdClass) {
$data = get_object_vars($data);
}
if ($data instanceof \stdClass) {
$data = get_object_vars($data);
}
if (!class_exists($controllerClassName)) {
throw new NotFound("Controller '$controllerName' is not found");
}
if (!class_exists($controllerClassName)) {
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;
}
if ($actionName == 'index') {
$actionName = $controllerClassName::$defaultAction;
}
$actionNameUcfirst = ucfirst($actionName);
$actionNameUcfirst = ucfirst($actionName);
$beforeMethodName = 'before' . $actionNameUcfirst;
if (method_exists($controller, $beforeMethodName)) {
$controller->$beforeMethodName($params, $data, $request);
}
$actionMethodName = 'action' . $actionNameUcfirst;
$beforeMethodName = 'before' . $actionNameUcfirst;
if (method_exists($controller, $beforeMethodName)) {
$controller->$beforeMethodName($params, $data, $request);
}
$actionMethodName = 'action' . $actionNameUcfirst;
if (!method_exists($controller, $actionMethodName)) {
throw new NotFound("Action '$actionMethodName' does not exist in controller '$controller'");
}
if (!method_exists($controller, $actionMethodName)) {
throw new NotFound("Action '$actionMethodName' does not exist in controller '$controller'");
}
$result = $controller->$actionMethodName($params, $data, $request);
$result = $controller->$actionMethodName($params, $data, $request);
$afterMethodName = 'after' . $actionNameUcfirst;
if (method_exists($controller, $afterMethodName)) {
$controller->$afterMethodName($params, $data, $request);
}
$afterMethodName = 'after' . $actionNameUcfirst;
if (method_exists($controller, $afterMethodName)) {
$controller->$afterMethodName($params, $data, $request);
}
if (is_array($result) || is_bool($result)) {
return \Espo\Core\Utils\Json::encode($result);
}
if (is_array($result) || is_bool($result)) {
return \Espo\Core\Utils\Json::encode($result);
}
return $result;
}
return $result;
}
}

View File

@@ -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;
@@ -28,70 +28,91 @@ use \Espo\Core\Utils\Util;
abstract class Base
{
protected $name;
private $container;
public static $defaultAction = 'index';
protected $name;
public function __construct(Container $container)
{
$this->container = $container;
if (empty($this->name)) {
$name = get_class($this);
if (preg_match('@\\\\([\w]+)$@', $name, $matches)) {
$name = $matches[1];
}
$this->name = $name;
}
$this->checkControllerAccess();
}
protected function checkControllerAccess()
{
return;
}
protected function getContainer()
{
return $this->container;
}
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');
}
private $container;
protected function getServiceFactory()
{
return $this->container->get('serviceFactory');
}
protected function getService($name)
{
return $this->getServiceFactory()->create($name);
}
private $requestMethod;
public static $defaultAction = 'index';
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)) {
$name = $matches[1];
}
$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');
}
protected function getServiceFactory()
{
return $this->container->get('serviceFactory');
}
protected function getService($name)
{
return $this->getServiceFactory()->create($name);
}
}

View File

@@ -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,271 +29,277 @@ use \Espo\Core\Utils\Util;
class Record extends Base
{
const MAX_SIZE_LIMIT = 200;
public static $defaultAction = 'list';
protected function getEntityManager()
{
return $this->getContainer()->get('entityManager');
}
protected function getRecordService()
{
if ($this->getServiceFactory()->checkExists($this->name)) {
$service = $this->getServiceFactory()->create($this->name);
} else {
$service = $this->getServiceFactory()->create('Record');
$service->setEntityName($this->name);
}
return $service;
}
const MAX_SIZE_LIMIT = 200;
public function actionRead($params)
{
$id = $params['id'];
$entity = $this->getRecordService()->getEntity($id);
if (empty($entity)) {
throw new NotFound();
}
public static $defaultAction = 'list';
return $entity->toArray();
}
public function actionPatch($params, $data)
{
return $this->actionUpdate($params, $data);
}
public function actionCreate($params, $data)
{
if (!$this->getAcl()->check($this->name, 'edit')) {
throw new Forbidden();
}
protected function getEntityManager()
{
return $this->getContainer()->get('entityManager');
}
$service = $this->getRecordService();
if ($entity = $service->createEntity($data)) {
return $entity->toArray();
}
protected function getRecordService($name = null)
{
if (empty($name)) {
$name = $this->name;
}
throw new Error();
}
if ($this->getServiceFactory()->checkExists($name)) {
$service = $this->getServiceFactory()->create($name);
} else {
$service = $this->getServiceFactory()->create('Record');
$service->setEntityName($name);
}
public function actionUpdate($params, $data)
{
if (!$this->getAcl()->check($this->name, 'edit')) {
throw new Forbidden();
}
$id = $params['id'];
if ($entity = $this->getRecordService()->updateEntity($id, $data)) {
return $entity->toArray();
}
return $service;
}
throw new Error();
}
public function actionRead($params)
{
$id = $params['id'];
$entity = $this->getRecordService()->getEntity($id);
public function actionList($params, $data, $request)
{
if (!$this->getAcl()->check($this->name, 'read')) {
throw new Forbidden();
}
if (empty($entity)) {
throw new NotFound();
}
$where = $request->get('where');
$offset = $request->get('offset');
$maxSize = $request->get('maxSize');
$asc = $request->get('asc') === 'true';
$sortBy = $request->get('sortBy');
$q = $request->get('q');
if (empty($maxSize)) {
$maxSize = self::MAX_SIZE_LIMIT;
}
if (!empty($maxSize) && $maxSize > self::MAX_SIZE_LIMIT) {
throw new Forbidden();
}
return $entity->toArray();
}
$result = $this->getRecordService()->findEntities(array(
'where' => $where,
'offset' => $offset,
'maxSize' => $maxSize,
'asc' => $asc,
'sortBy' => $sortBy,
'q' => $q,
));
return array(
'total' => $result['total'],
'list' => $result['collection']->toArray()
);
}
public function actionListLinked($params, $data, $request)
{
$id = $params['id'];
$link = $params['link'];
public function actionPatch($params, $data)
{
return $this->actionUpdate($params, $data);
}
$where = $request->get('where');
$offset = $request->get('offset');
$maxSize = $request->get('maxSize');
$asc = $request->get('asc') === 'true';
$sortBy = $request->get('sortBy');
$q = $request->get('q');
if (empty($maxSize)) {
$maxSize = self::MAX_SIZE_LIMIT;
}
if (!empty($maxSize) && $maxSize > self::MAX_SIZE_LIMIT) {
throw new Forbidden();
}
public function actionCreate($params, $data)
{
if (!$this->getAcl()->check($this->name, 'edit')) {
throw new Forbidden();
}
$result = $this->getRecordService()->findLinkedEntities($id, $link, array(
'where' => $where,
'offset' => $offset,
'maxSize' => $maxSize,
'asc' => $asc,
'sortBy' => $sortBy,
'q' => $q,
));
return array(
'total' => $result['total'],
'list' => $result['collection']->toArray()
);
}
$service = $this->getRecordService();
public function actionDelete($params)
{
$id = $params['id'];
if ($entity = $service->createEntity($data)) {
return $entity->toArray();
}
if ($this->getRecordService()->deleteEntity($id)) {
return true;
}
throw new Error();
}
public function actionExport($params, $data, $request)
{
// TODO move to service
if (!$this->getAcl()->check($this->name, 'read')) {
throw new Forbidden();
}
$ids = $request->get('ids');
$where = $request->get('where');
return array(
'id' => $this->getRecordService()->export($ids, $where)
);
}
throw new Error();
}
public function actionMassUpdate($params, $data)
{
if (!$this->getAcl()->check($this->name, 'edit')) {
throw new Forbidden();
}
public function actionUpdate($params, $data)
{
if (!$this->getAcl()->check($this->name, 'edit')) {
throw new Forbidden();
}
$ids = $data['ids'];
$where = $data['where'];
$attributes = $data['attributes'];
$id = $params['id'];
$idsUpdated = $this->getRecordService()->massUpdate($attributes, $ids, $where);
if ($entity = $this->getRecordService()->updateEntity($id, $data)) {
return $entity->toArray();
}
return $idsUpdated;
}
throw new Error();
}
public function actionMassDelete($params, $data)
{
if (!$this->getAcl()->check($this->name, 'delete')) {
throw new Forbidden();
}
public function actionList($params, $data, $request)
{
if (!$this->getAcl()->check($this->name, 'read')) {
throw new Forbidden();
}
$ids = $data['ids'];
$where = $data['where'];
$where = $request->get('where');
$offset = $request->get('offset');
$maxSize = $request->get('maxSize');
$asc = $request->get('asc') === 'true';
$sortBy = $request->get('sortBy');
$q = $request->get('q');
$idsDeleted = $this->getRecordService()->massDelete($ids, $where);
if (empty($maxSize)) {
$maxSize = self::MAX_SIZE_LIMIT;
}
if (!empty($maxSize) && $maxSize > self::MAX_SIZE_LIMIT) {
throw new Forbidden();
}
return $idsDeleted;
}
$result = $this->getRecordService()->findEntities(array(
'where' => $where,
'offset' => $offset,
'maxSize' => $maxSize,
'asc' => $asc,
'sortBy' => $sortBy,
'q' => $q,
));
public function actionCreateLink($params, $data)
{
$id = $params['id'];
$link = $params['link'];
$foreignIds = array();
if (isset($data['id'])) {
$foreignIds[] = $data['id'];
}
if (isset($data['ids']) && is_array($data['ids'])) {
foreach ($data['ids'] as $foreignId) {
$foreignIds[] = $foreignId;
}
}
$result = false;
foreach ($foreignIds as $foreignId) {
if ($this->getRecordService()->linkEntity($id, $link, $foreignId)) {
$result = $result || true;
}
}
if ($result) {
return true;
}
throw new Error();
}
public function actionRemoveLink($params, $data)
{
$id = $params['id'];
$link = $params['link'];
$foreignIds = array();
if (isset($data['id'])) {
$foreignIds[] = $data['id'];
}
if (isset($data['ids']) && is_array($data['ids'])) {
foreach ($data['ids'] as $foreignId) {
$foreignIds[] = $foreignId;
}
}
$result = false;
foreach ($foreignIds as $foreignId) {
if ($this->getRecordService()->unlinkEntity($id, $link, $foreignId)) {
$result = $result || true;
}
}
if ($result) {
return true;
}
throw new Error();
}
public function actionFollow($params)
{
if (!$this->getAcl()->check($this->name, 'read')) {
throw new Forbidden();
}
$id = $params['id'];
return $this->getRecordService()->follow($id);
}
public function actionUnfollow($params)
{
if (!$this->getAcl()->check($this->name, 'read')) {
throw new Forbidden();
}
$id = $params['id'];
return $this->getRecordService()->unfollow($id);
}
return array(
'total' => $result['total'],
'list' => $result['collection']->toArray()
);
}
public function actionListLinked($params, $data, $request)
{
$id = $params['id'];
$link = $params['link'];
$where = $request->get('where');
$offset = $request->get('offset');
$maxSize = $request->get('maxSize');
$asc = $request->get('asc') === 'true';
$sortBy = $request->get('sortBy');
$q = $request->get('q');
if (empty($maxSize)) {
$maxSize = self::MAX_SIZE_LIMIT;
}
if (!empty($maxSize) && $maxSize > self::MAX_SIZE_LIMIT) {
throw new Forbidden();
}
$result = $this->getRecordService()->findLinkedEntities($id, $link, array(
'where' => $where,
'offset' => $offset,
'maxSize' => $maxSize,
'asc' => $asc,
'sortBy' => $sortBy,
'q' => $q,
));
return array(
'total' => $result['total'],
'list' => $result['collection']->toArray()
);
}
public function actionDelete($params)
{
$id = $params['id'];
if ($this->getRecordService()->deleteEntity($id)) {
return true;
}
throw new Error();
}
public function actionExport($params, $data, $request)
{
if ($this->getConfig()->get('disableExport') && !$this->getUser()->isAdmin()) {
throw new Forbidden();
}
if (!$this->getAcl()->check($this->name, 'read')) {
throw new Forbidden();
}
$ids = $request->get('ids');
$where = $request->get('where');
return array(
'id' => $this->getRecordService()->export($ids, $where)
);
}
public function actionMassUpdate($params, $data, $request)
{
if (!$this->getAcl()->check($this->name, 'edit')) {
throw new Forbidden();
}
$ids = $data['ids'];
$where = $data['where'];
$attributes = $data['attributes'];
$idsUpdated = $this->getRecordService()->massUpdate($attributes, $ids, $where);
return $idsUpdated;
}
public function actionMassDelete($params, $data, $request)
{
if (!$this->getAcl()->check($this->name, 'delete')) {
throw new Forbidden();
}
$ids = $data['ids'];
$where = $data['where'];
$idsRemoved = $this->getRecordService()->massRemove($ids, $where);
return $idsRemoved;
}
public function actionCreateLink($params, $data)
{
$id = $params['id'];
$link = $params['link'];
$foreignIds = array();
if (isset($data['id'])) {
$foreignIds[] = $data['id'];
}
if (isset($data['ids']) && is_array($data['ids'])) {
foreach ($data['ids'] as $foreignId) {
$foreignIds[] = $foreignId;
}
}
$result = false;
foreach ($foreignIds as $foreignId) {
if ($this->getRecordService()->linkEntity($id, $link, $foreignId)) {
$result = $result || true;
}
}
if ($result) {
return true;
}
throw new Error();
}
public function actionRemoveLink($params, $data)
{
$id = $params['id'];
$link = $params['link'];
$foreignIds = array();
if (isset($data['id'])) {
$foreignIds[] = $data['id'];
}
if (isset($data['ids']) && is_array($data['ids'])) {
foreach ($data['ids'] as $foreignId) {
$foreignIds[] = $foreignId;
}
}
$result = false;
foreach ($foreignIds as $foreignId) {
if ($this->getRecordService()->unlinkEntity($id, $link, $foreignId)) {
$result = $result || true;
}
}
if ($result) {
return true;
}
throw new Error();
}
public function actionFollow($params)
{
if (!$this->getAcl()->check($this->name, 'read')) {
throw new Forbidden();
}
$id = $params['id'];
return $this->getRecordService()->follow($id);
}
public function actionUnfollow($params)
{
if (!$this->getAcl()->check($this->name, 'read')) {
throw new Forbidden();
}
$id = $params['id'];
return $this->getRecordService()->unfollow($id);
}
}

View File

@@ -23,163 +23,163 @@
namespace Espo\Core\Cron;
use Espo\Core\Exceptions\NotFound,
Espo\Core\Utils\Util;
Espo\Core\Utils\Util;
class ScheduledJob
{
private $container;
private $systemUtil;
private $container;
private $systemUtil;
protected $data = null;
protected $data = null;
protected $cacheFile = 'data/cache/application/jobs.php';
protected $cacheFile = 'data/cache/application/jobs.php';
protected $cronFile = 'cron.php';
protected $cronFile = 'cron.php';
protected $allowedMethod = 'run';
protected $allowedMethod = 'run';
/**
* @var array - path to cron job files
*/
private $paths = array(
'corePath' => 'application/Espo/Jobs',
'modulePath' => 'application/Espo/Modules/{*}/Jobs',
'customPath' => 'custom/Espo/Custom/Jobs',
);
/**
* @var array - path to cron job files
*/
private $paths = array(
'corePath' => 'application/Espo/Jobs',
'modulePath' => 'application/Espo/Modules/{*}/Jobs',
'customPath' => 'custom/Espo/Custom/Jobs',
);
protected $cronSetup = array(
'linux' => '* * * * * {PHP-BIN-DIR} -f {CRON-FILE} > /dev/null 2>&1',
'windows' => '{PHP-BIN-DIR}.exe -f {CRON-FILE}',
'mac' => '* * * * * {PHP-BIN-DIR} -f {CRON-FILE} > /dev/null 2>&1',
'default' => '* * * * * {PHP-BIN-DIR} -f {CRON-FILE}',
);
protected $cronSetup = array(
'linux' => '* * * * * {PHP-BIN-DIR} -f {CRON-FILE} > /dev/null 2>&1',
'windows' => '{PHP-BIN-DIR}.exe -f {CRON-FILE}',
'mac' => '* * * * * {PHP-BIN-DIR} -f {CRON-FILE} > /dev/null 2>&1',
'default' => '* * * * * {PHP-BIN-DIR} -f {CRON-FILE}',
);
public function __construct(\Espo\Core\Container $container)
{
$this->container = $container;
$this->systemUtil = new \Espo\Core\Utils\System();
}
public function __construct(\Espo\Core\Container $container)
{
$this->container = $container;
$this->systemUtil = new \Espo\Core\Utils\System();
}
protected function getContainer()
{
return $this->container;
}
protected function getContainer()
{
return $this->container;
}
protected function getEntityManager()
{
return $this->container->get('entityManager');
}
protected function getEntityManager()
{
return $this->container->get('entityManager');
}
protected function getSystemUtil()
{
return $this->systemUtil;
}
protected function getSystemUtil()
{
return $this->systemUtil;
}
public function run(array $job)
{
$jobName = $job['method'];
public function run(array $job)
{
$jobName = $job['method'];
$className = $this->getClassName($jobName);
if ($className === false) {
throw new NotFound();
}
$className = $this->getClassName($jobName);
if ($className === false) {
throw new NotFound();
}
$jobClass = new $className($this->container);
$method = $this->allowedMethod;
$jobClass = new $className($this->container);
$method = $this->allowedMethod;
$jobClass->$method();
}
$jobClass->$method();
}
/**
* Get list of all jobs
*
* @return array
*/
public function getAll()
{
if (!isset($this->data)) {
$this->init();
}
/**
* Get list of all jobs
*
* @return array
*/
public function getAll()
{
if (!isset($this->data)) {
$this->init();
}
return $this->data;
}
return $this->data;
}
/**
* Get class name of a job by name
*
* @param string $name
* @return string
*/
public function get($name)
{
return $this->getClassName($name);
}
/**
* Get class name of a job by name
*
* @param string $name
* @return string
*/
public function get($name)
{
return $this->getClassName($name);
}
/**
* Get list of all job names
*
* @return array
*/
public function getAllNamesOnly()
{
$data = $this->getAll();
/**
* Get list of all job names
*
* @return array
*/
public function getAllNamesOnly()
{
$data = $this->getAll();
$namesOnly = array_keys($data);
$namesOnly = array_keys($data);
return $namesOnly;
}
return $namesOnly;
}
/**
* Get class name of a job
*
* @param string $name
* @return string
*/
protected function getClassName($name)
{
$name = Util::normilizeClassName($name);
/**
* Get class name of a job
*
* @param string $name
* @return string
*/
protected function getClassName($name)
{
$name = Util::normilizeClassName($name);
$data = $this->getAll();
$data = $this->getAll();
$name = ucfirst($name);
if (isset($data[$name])) {
return $data[$name];
}
$name = ucfirst($name);
if (isset($data[$name])) {
return $data[$name];
}
return false;
}
return false;
}
/**
* Load scheduler classes. It loads from ...Jobs, ex. \Espo\Jobs
* @return null
*/
protected function init()
{
$classParser = $this->getContainer()->get('classParser');
$classParser->setAllowedMethods( array($this->allowedMethod) );
$this->data = $classParser->getData($this->paths, $this->cacheFile);
}
/**
* Load scheduler classes. It loads from ...Jobs, ex. \Espo\Jobs
* @return null
*/
protected function init()
{
$classParser = $this->getContainer()->get('classParser');
$classParser->setAllowedMethods( array($this->allowedMethod) );
$this->data = $classParser->getData($this->paths, $this->cacheFile);
}
public function getSetupMessage()
{
$language = $this->getContainer()->get('language');
public function getSetupMessage()
{
$language = $this->getContainer()->get('language');
$OS = $this->getSystemUtil()->getOS();
$phpBin = $this->getSystemUtil()->getPhpBin();
$cronFile = Util::concatPath($this->getSystemUtil()->getRootDir(), $this->cronFile);
$desc = $language->translate('cronSetup', 'options', 'ScheduledJob');
$OS = $this->getSystemUtil()->getOS();
$phpBin = $this->getSystemUtil()->getPhpBin();
$cronFile = Util::concatPath($this->getSystemUtil()->getRootDir(), $this->cronFile);
$desc = $language->translate('cronSetup', 'options', 'ScheduledJob');
$message = isset($desc[$OS]) ? $desc[$OS] : $desc['default'];
$message = isset($desc[$OS]) ? $desc[$OS] : $desc['default'];
$command = isset($this->cronSetup[$OS]) ? $this->cronSetup[$OS] : $this->cronSetup['default'];
$command = str_replace(array('{PHP-BIN-DIR}', '{CRON-FILE}'), array($phpBin, $cronFile), $command);
$command = isset($this->cronSetup[$OS]) ? $this->cronSetup[$OS] : $this->cronSetup['default'];
$command = str_replace(array('{PHP-BIN-DIR}', '{CRON-FILE}'), array($phpBin, $cronFile), $command);
return array(
'message' => $message,
'command' => $command,
);
}
return array(
'message' => $message,
'command' => $command,
);
}
}

View File

@@ -18,50 +18,50 @@
*
* 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;
use Espo\Core\Utils\Json,
Espo\Core\Exceptions\NotFound;
Espo\Core\Exceptions\NotFound;
class Service
{
private $serviceFactory;
private $serviceFactory;
public function __construct(\Espo\Core\ServiceFactory $serviceFactory)
{
$this->serviceFactory = $serviceFactory;
}
public function __construct(\Espo\Core\ServiceFactory $serviceFactory)
{
$this->serviceFactory = $serviceFactory;
}
protected function getServiceFactory()
{
return $this->serviceFactory;
}
protected function getServiceFactory()
{
return $this->serviceFactory;
}
public function run($job)
{
$serviceName = $job['service_name'];
public function run($job)
{
$serviceName = $job['service_name'];
if (!$this->getServiceFactory()->checkExists($serviceName)) {
throw new NotFound();
}
if (!$this->getServiceFactory()->checkExists($serviceName)) {
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();
}
if (!method_exists($service, $serviceMethod)) {
throw new NotFound();
}
$data = $job['data'];
if (Json::isJSON($data)) {
$data = Json::decode($data, true);
}
$data = $job['data'];
if (Json::isJSON($data)) {
$data = Json::decode($data, true);
}
$service->$serviceMethod($data);
}
$service->$serviceMethod($data);
}
}

View File

@@ -24,189 +24,192 @@ namespace Espo\Core;
class CronManager
{
private $container;
private $config;
private $fileManager;
private $container;
private $config;
private $fileManager;
private $scheduledJobCron;
private $serviceCron;
private $scheduledJobCron;
private $serviceCron;
private $jobService;
private $scheduledJobService;
private $jobService;
private $scheduledJobService;
protected $lastRunTime = 'data/cache/application/cronLastRunTime.php';
const PENDING = 'Pending';
const RUNNING = 'Running';
const SUCCESS = 'Success';
const FAILED = 'Failed';
protected $lastRunTime = 'data/cache/application/cronLastRunTime.php';
public function __construct(\Espo\Core\Container $container)
{
$this->container = $container;
public function __construct(\Espo\Core\Container $container)
{
$this->container = $container;
$this->config = $this->container->get('config');
$this->fileManager = $this->container->get('fileManager');
$this->config = $this->container->get('config');
$this->fileManager = $this->container->get('fileManager');
$this->scheduledJobCron = $this->container->get('scheduledJob');
$this->serviceCron = new \Espo\Core\Cron\Service( $this->container->get('serviceFactory'));
$this->scheduledJobCron = $this->container->get('scheduledJob');
$this->serviceCron = new \Espo\Core\Cron\Service( $this->container->get('serviceFactory'));
$this->jobService = $this->container->get('serviceFactory')->create('job');
$this->scheduledJobService = $this->container->get('serviceFactory')->create('scheduledJob');
}
$this->jobService = $this->container->get('serviceFactory')->create('job');
$this->scheduledJobService = $this->container->get('serviceFactory')->create('scheduledJob');
}
protected function getContainer()
{
return $this->container;
}
protected function getContainer()
{
return $this->container;
}
protected function getConfig()
{
return $this->config;
}
protected function getConfig()
{
return $this->config;
}
protected function getFileManager()
{
return $this->fileManager;
}
protected function getFileManager()
{
return $this->fileManager;
}
protected function getJobService()
{
return $this->jobService;
}
protected function getJobService()
{
return $this->jobService;
}
protected function getScheduledJobService()
{
return $this->scheduledJobService;
}
protected function getScheduledJobService()
{
return $this->scheduledJobService;
}
protected function getScheduledJobCron()
{
return $this->scheduledJobCron;
}
protected function getScheduledJobCron()
{
return $this->scheduledJobCron;
}
protected function getServiceCron()
{
return $this->serviceCron;
}
protected function getServiceCron()
{
return $this->serviceCron;
}
protected function getLastRunTime()
{
$lastRunTime = $this->getFileManager()->getContents($this->lastRunTime);
if (!is_int($lastRunTime)) {
$lastRunTime = time() - (intval($this->getConfig()->get('cron.minExecutionTime')) + 60);
}
protected function getLastRunTime()
{
$lastRunTime = $this->getFileManager()->getContents($this->lastRunTime);
if (!is_int($lastRunTime)) {
$lastRunTime = time() - (intval($this->getConfig()->get('cron.minExecutionTime')) + 60);
}
return $lastRunTime;
}
return $lastRunTime;
}
protected function setLastRunTime($time)
{
return $this->getFileManager()->putContentsPHP($this->lastRunTime, $time);
}
protected function setLastRunTime($time)
{
return $this->getFileManager()->putContentsPHP($this->lastRunTime, $time);
}
protected function checkLastRunTime()
{
$currentTime = time();
$lastRunTime = $this->getLastRunTime();
$minTime = $this->getConfig()->get('cron.minExecutionTime');
protected function checkLastRunTime()
{
$currentTime = time();
$lastRunTime = $this->getLastRunTime();
$minTime = $this->getConfig()->get('cron.minExecutionTime');
if ($currentTime > ($lastRunTime + $minTime) ) {
return true;
}
if ($currentTime > ($lastRunTime + $minTime) ) {
return true;
}
return false;
}
return false;
}
public function run()
{
if (!$this->checkLastRunTime()) {
$GLOBALS['log']->info('Cron Manager: Stop cron running, too frequency execution');
return; //stop cron running, too frequency execution
}
public function run()
{
if (!$this->checkLastRunTime()) {
$GLOBALS['log']->info('Cron Manager: Stop cron running, too frequency execution');
return; //stop cron running, too frequency execution
}
$this->setLastRunTime(time());
$this->setLastRunTime(time());
//Check scheduled jobs and create related jobs
$this->createJobsFromScheduledJobs();
//Check scheduled jobs and create related jobs
$this->createJobsFromScheduledJobs();
$pendingJobs = $this->getJobService()->getPendingJobs();
$pendingJobs = $this->getJobService()->getPendingJobs();
foreach ($pendingJobs as $job) {
foreach ($pendingJobs as $job) {
$this->getJobService()->updateEntity($job['id'], array(
'status' => self::RUNNING,
));
$this->getJobService()->updateEntity($job['id'], array(
'status' => 'Running',
));
$isSuccess = true;
$isSuccess = true;
try {
if (!empty($job['scheduled_job_id'])) {
$this->getScheduledJobCron()->run($job);
} else {
$this->getServiceCron()->run($job);
}
} catch (\Exception $e) {
$isSuccess = false;
$GLOBALS['log']->error('Failed job running, job ['.$job['id'].']. Error Details: '.$e->getMessage());
}
try {
if (!empty($job['scheduled_job_id'])) {
$this->getScheduledJobCron()->run($job);
} else {
$this->getServiceCron()->run($job);
}
} catch (\Exception $e) {
$isSuccess = false;
$GLOBALS['log']->error('Failed job running, job ['.$job['id'].']. Error Details: '.$e->getMessage());
}
$status = $isSuccess ? self::SUCCESS : self::FAILED;
$status = $isSuccess ? 'Success' : 'Failed';
$this->getJobService()->updateEntity($job['id'], array(
'status' => $status,
));
$this->getJobService()->updateEntity($job['id'], array(
'status' => $status,
));
//set status in the schedulerJobLog
if (!empty($job['scheduled_job_id'])) {
$this->getScheduledJobService()->addLogRecord($job['scheduled_job_id'], $status);
}
}
//set status in the schedulerJobLog
if (!empty($job['scheduled_job_id'])) {
$this->getScheduledJobService()->addLogRecord($job['scheduled_job_id'], $status);
}
}
}
}
/**
* Check scheduled jobs and create related jobs
* @return array List of created Jobs
*/
protected function createJobsFromScheduledJobs()
{
$activeScheduledJobs = $this->getScheduledJobService()->getActiveJobs();
/**
* Check scheduled jobs and create related jobs
* @return array List of created Jobs
*/
protected function createJobsFromScheduledJobs()
{
$activeScheduledJobs = $this->getScheduledJobService()->getActiveJobs();
$createdJobs = array();
foreach ($activeScheduledJobs as $scheduledJob) {
$createdJobs = array();
foreach ($activeScheduledJobs as $scheduledJob) {
$scheduling = $scheduledJob['scheduling'];
$scheduling = $scheduledJob['scheduling'];
$cronExpression = \Cron\CronExpression::factory($scheduling);
$cronExpression = \Cron\CronExpression::factory($scheduling);
try {
$prevDate = $cronExpression->getPreviousRunDate()->format('Y-m-d H:i:s');
} catch (\Exception $e) {
$GLOBALS['log']->error('ScheduledJob ['.$scheduledJob['id'].']: CronExpression - Impossible CRON expression ['.$scheduling.']');
continue;
}
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.']');
continue;
}
if ($cronExpression->isDue()) {
$prevDate = date('Y-m-d H:i:00');
}
if ($cronExpression->isDue()) {
$prevDate = date('Y-m-d H:i:00');
}
$existsJob = $this->getJobService()->getJobByScheduledJob($scheduledJob['id'], $prevDate);
$existsJob = $this->getJobService()->getJobByScheduledJob($scheduledJob['id'], $prevDate);
if (!isset($existsJob) || empty($existsJob)) {
//create a job
$data = array(
'name' => $scheduledJob['name'],
'status' => self::PENDING,
'scheduledJobId' => $scheduledJob['id'],
'executeTime' => $prevDate,
'method' => $scheduledJob['job'],
);
$createdJobs[] = $this->getJobService()->createEntity($data);
}
}
if (!isset($existsJob) || empty($existsJob)) {
//create a job
$data = array(
'name' => $scheduledJob['name'],
'status' => 'Pending',
'scheduledJobId' => $scheduledJob['id'],
'executeTime' => $prevDate,
'method' => $scheduledJob['job'],
);
$createdJobs[] = $this->getJobService()->createEntity($data);
}
}
return $createdJobs;
}
return $createdJobs;
}
}

View File

@@ -24,105 +24,106 @@ namespace Espo\Core;
class DataManager
{
private $container;
private $container;
private $cachePath = 'data/cache';
private $cachePath = 'data/cache';
public function __construct(Container $container)
{
$this->container = $container;
}
public function __construct(Container $container)
{
$this->container = $container;
}
protected function getContainer()
{
return $this->container;
}
protected function getContainer()
{
return $this->container;
}
/**
* Rebuild the system with metadata, database and cache clearing
*
* @return bool
*/
public function rebuild($entityList = null)
{
$result = $this->clearCache();
/**
* Rebuild the system with metadata, database and cache clearing
*
* @return bool
*/
public function rebuild($entityList = null)
{
$result = $this->clearCache();
$result &= $this->rebuildMetadata();
$result &= $this->rebuildMetadata();
$result &= $this->rebuildDatabase($entityList);
$result &= $this->rebuildDatabase($entityList);
return $result;
}
return $result;
}
/**
* Clear a cache
*
* @return bool
*/
public function clearCache()
{
$result = $this->getContainer()->get('fileManager')->removeInDir($this->cachePath);
/**
* Clear a cache
*
* @return bool
*/
public function clearCache()
{
$result = $this->getContainer()->get('fileManager')->removeInDir($this->cachePath);
if ($result === false) {
throw new Exceptions\Error("Error while clearing cache");
}
if ($result != true) {
throw new Exceptions\Error("Error while clearing cache");
}
$this->updateCacheTimestamp();
$this->updateCacheTimestamp();
return $result;
}
return $result;
}
/**
* Rebuild database
*
* @return bool
*/
public function rebuildDatabase($entityList = null)
{
try {
$result = $this->getContainer()->get('schema')->rebuild($entityList);
} catch (\Exception $e) {
$result = false;
$GLOBALS['log']->error('Fault to rebuild database schema'.'. Details: '.$e->getMessage());
}
/**
* Rebuild database
*
* @return bool
*/
public function rebuildDatabase($entityList = null)
{
try {
$result = $this->getContainer()->get('schema')->rebuild($entityList);
} catch (\Exception $e) {
$result = false;
$GLOBALS['log']->error('Fault to rebuild database schema'.'. Details: '.$e->getMessage());
}
if ($result === false) {
throw new Exceptions\Error("Error while rebuilding database. See log file for details.");
}
if ($result != true) {
throw new Exceptions\Error("Error while rebuilding database. See log file for details.");
}
$this->updateCacheTimestamp();
$this->updateCacheTimestamp();
return $result;
}
return $result;
}
/**
* Rebuild metadata
*
* @return bool
*/
public function rebuildMetadata()
{
$metadata = $this->getContainer()->get('metadata');
/**
* Rebuild metadata
*
* @return bool
*/
public function rebuildMetadata()
{
$metadata = $this->getContainer()->get('metadata');
$metadata->init(true);
$metadata->init(true);
$ormMeta = $metadata->getOrmMetadata(true);
$ormMeta = $metadata->getOrmMetadata(true);
$this->updateCacheTimestamp();
$this->updateCacheTimestamp();
return empty($ormMeta) ? false : true;
}
return empty($ormMeta) ? false : true;
}
/**
* Update cache timestamp
*
* @return bool
*/
public function updateCacheTimestamp()
{
return $this->getContainer()->get('config')->updateCacheTimestamp();
}
/**
* Update cache timestamp
*
* @return bool
*/
public function updateCacheTimestamp()
{
$this->getContainer()->get('config')->updateCacheTimestamp();
$this->getContainer()->get('config')->save();
return true;
}
}
}

View File

@@ -24,30 +24,30 @@ namespace Espo\Core\Entities;
class Person extends \Espo\Core\ORM\Entity
{
public static $person = true;
public function setLastName($value)
{
$this->setValue('lastName', $value);
$firstName = $this->get('firstName');
if (empty($firstName)) {
$this->setValue('name', $value);
} else {
$this->setValue('name', $firstName . ' ' . $value);
}
}
public function setFirstName($value)
{
$this->setValue('firstName', $value);
$lastName = $this->get('lastName');
if (empty($lastName)) {
$this->setValue('name', $value);
} else {
$this->setValue('name', $value . ' ' . $lastName);
}
}
public static $person = true;
public function _setLastName($value)
{
$this->setValue('lastName', $value);
$firstName = $this->get('firstName');
if (empty($firstName)) {
$this->setValue('name', $value);
} else {
$this->setValue('name', $firstName . ' ' . $value);
}
}
public function _setFirstName($value)
{
$this->setValue('firstName', $value);
$lastName = $this->get('lastName');
if (empty($lastName)) {
$this->setValue('name', $value);
} else {
$this->setValue('name', $value . ' ' . $lastName);
}
}
}

View File

@@ -23,93 +23,93 @@
namespace Espo\Core;
use \Espo\Core\Exceptions\NotFound,
\Espo\Core\Utils\Util;
\Espo\Core\Utils\Util;
class EntryPointManager
{
private $container;
private $fileManager;
private $container;
private $fileManager;
protected $data = null;
protected $data = null;
protected $cacheFile = 'data/cache/application/entryPoints.php';
protected $cacheFile = 'data/cache/application/entryPoints.php';
protected $allowedMethods = array(
'run',
);
protected $allowedMethods = array(
'run',
);
/**
/**
* @var array - path to entryPoint files
*/
private $paths = array(
'corePath' => 'application/Espo/EntryPoints',
'modulePath' => 'application/Espo/Modules/{*}/EntryPoints',
'customPath' => 'custom/Espo/Custom/EntryPoints',
);
private $paths = array(
'corePath' => 'application/Espo/EntryPoints',
'modulePath' => 'application/Espo/Modules/{*}/EntryPoints',
'customPath' => 'custom/Espo/Custom/EntryPoints',
);
public function __construct(\Espo\Core\Container $container)
{
$this->container = $container;
$this->fileManager = $container->get('fileManager');
}
public function __construct(\Espo\Core\Container $container)
{
$this->container = $container;
$this->fileManager = $container->get('fileManager');
}
protected function getContainer()
{
return $this->container;
}
protected function getContainer()
{
return $this->container;
}
protected function getFileManager()
{
return $this->fileManager;
}
protected function getFileManager()
{
return $this->fileManager;
}
public function checkAuthRequired($name)
{
$className = $this->getClassName($name);
if ($className === false) {
throw new NotFound();
}
return $className::$authRequired;
}
public function checkAuthRequired($name)
{
$className = $this->getClassName($name);
if ($className === false) {
throw new NotFound();
}
return $className::$authRequired;
}
public function run($name)
{
$className = $this->getClassName($name);
if ($className === false) {
throw new NotFound();
}
$entryPoint = new $className($this->container);
public function run($name)
{
$className = $this->getClassName($name);
if ($className === false) {
throw new NotFound();
}
$entryPoint = new $className($this->container);
$entryPoint->run();
}
$entryPoint->run();
}
protected function getClassName($name)
{
$name = Util::normilizeClassName($name);
if (!isset($this->data)) {
$this->init();
}
protected function getClassName($name)
{
$name = Util::normilizeClassName($name);
if (!isset($this->data)) {
$this->init();
}
$name = ucfirst($name);
if (isset($this->data[$name])) {
return $this->data[$name];
}
$name = ucfirst($name);
if (isset($this->data[$name])) {
return $this->data[$name];
}
return false;
}
}
protected function init()
{
$classParser = $this->getContainer()->get('classParser');
$classParser->setAllowedMethods($this->allowedMethods);
$this->data = $classParser->getData($this->paths, $this->cacheFile);
}
protected function init()
{
$classParser = $this->getContainer()->get('classParser');
$classParser->setAllowedMethods($this->allowedMethods);
$this->data = $classParser->getData($this->paths, $this->cacheFile);
}
}

View File

@@ -28,51 +28,51 @@ use \Espo\Core\Exceptions\Forbidden;
abstract class Base
{
private $container;
public static $authRequired = true;
protected function getContainer()
{
return $this->container;
}
protected function getUser()
{
return $this->getContainer()->get('user');
}
protected function getAcl()
{
return $this->getContainer()->get('acl');
}
protected function getEntityManager()
{
return $this->getContainer()->get('entityManager');
}
protected function getServiceFactory()
{
return $this->getContainer()->get('serviceFactory');
}
protected function getConfig()
{
return $this->getContainer()->get('config');
}
protected function getMetadata()
{
return $this->getContainer()->get('metadata');
}
public function __construct(Container $container)
{
$this->container = $container;
}
abstract public function run();
private $container;
public static $authRequired = true;
protected function getContainer()
{
return $this->container;
}
protected function getUser()
{
return $this->getContainer()->get('user');
}
protected function getAcl()
{
return $this->getContainer()->get('acl');
}
protected function getEntityManager()
{
return $this->getContainer()->get('entityManager');
}
protected function getServiceFactory()
{
return $this->getContainer()->get('serviceFactory');
}
protected function getConfig()
{
return $this->getContainer()->get('config');
}
protected function getMetadata()
{
return $this->getContainer()->get('metadata');
}
public function __construct(Container $container)
{
$this->container = $container;
}
abstract public function run();
}

View File

@@ -24,7 +24,7 @@ namespace Espo\Core\Exceptions;
class BadRequest extends \Exception
{
protected $code = 400;
protected $code = 400;
}

View File

@@ -24,7 +24,7 @@ namespace Espo\Core\Exceptions;
class Conflict extends \Exception
{
protected $code = 409;
protected $code = 409;
}

View File

@@ -24,7 +24,7 @@ namespace Espo\Core\Exceptions;
class Forbidden extends \Exception
{
protected $code = 403;
protected $code = 403;
}

View File

@@ -24,6 +24,6 @@ namespace Espo\Core\Exceptions;
class InternalServerError extends \Exception
{
protected $code = 500;
protected $code = 500;
}

View File

@@ -24,7 +24,7 @@ namespace Espo\Core\Exceptions;
class NotFound extends \Exception
{
protected $code = 404;
protected $code = 404;
}

View File

@@ -24,7 +24,7 @@ namespace Espo\Core\Exceptions;
class Unauthorized extends \Exception
{
protected $code = 401;
protected $code = 401;
}

View 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',
)
);
}

View 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,
);
}
}

View 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';
}
}

View 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();
}

View 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'
);
}
}
}
}

View 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);
}
}

View File

@@ -23,162 +23,162 @@
namespace Espo\Core;
use \Espo\Core\Exceptions\Error,
\Espo\Core\Utils\Util;
\Espo\Core\Utils\Util;
class HookManager
{
private $container;
private $container;
private $data;
private $data;
private $hooks;
private $hooks;
protected $cacheFile = 'data/cache/application/hooks.php';
protected $cacheFile = 'data/cache/application/hooks.php';
/**
/**
* List of defined hooks
*
* @var array
*/
protected $hookList = array(
'beforeSave',
'afterSave',
'beforeRemove',
'afterRemove',
);
protected $hookList = array(
'beforeSave',
'afterSave',
'beforeRemove',
'afterRemove',
);
protected $paths = array(
'corePath' => 'application/Espo/Hooks',
'modulePath' => 'application/Espo/Modules/{*}/Hooks',
'customPath' => 'custom/Espo/Custom/Hooks',
);
protected $paths = array(
'corePath' => 'application/Espo/Hooks',
'modulePath' => 'application/Espo/Modules/{*}/Hooks',
'customPath' => 'custom/Espo/Custom/Hooks',
);
public function __construct(Container $container)
{
$this->container = $container;
$this->loadHooks();
$this->container = $container;
$this->loadHooks();
}
protected function getConfig()
{
return $this->container->get('config');
return $this->container->get('config');
}
protected function getFileManager()
{
return $this->container->get('fileManager');
}
protected function getFileManager()
{
return $this->container->get('fileManager');
}
protected function loadHooks()
{
if ($this->getConfig()->get('useCache') && file_exists($this->cacheFile)) {
$this->data = $this->getFileManager()->getContents($this->cacheFile);
return;
}
if ($this->getConfig()->get('useCache') && file_exists($this->cacheFile)) {
$this->data = $this->getFileManager()->getContents($this->cacheFile);
return;
}
$metadata = $this->container->get('metadata');
$metadata = $this->container->get('metadata');
$this->data = $this->getHookData($this->paths['corePath']);
$this->data = $this->getHookData($this->paths['corePath']);
foreach ($metadata->getModuleList() as $moduleName) {
$modulePath = str_replace('{*}', $moduleName, $this->paths['modulePath']);
$this->data = array_merge($this->data, $this->getHookData($modulePath));
}
foreach ($metadata->getModuleList() as $moduleName) {
$modulePath = str_replace('{*}', $moduleName, $this->paths['modulePath']);
$this->data = array_merge($this->data, $this->getHookData($modulePath));
}
$this->data = array_merge($this->data, $this->getHookData($this->paths['customPath']));
$this->data = array_merge($this->data, $this->getHookData($this->paths['customPath']));
if ($this->getConfig()->get('useCache')) {
$this->getFileManager()->putContentsPHP($this->cacheFile, $this->data);
}
if ($this->getConfig()->get('useCache')) {
$this->getFileManager()->putContentsPHP($this->cacheFile, $this->data);
}
}
public function process($scope, $hookName, $injection = null)
{
if ($scope != 'Common') {
$this->process('Common', $hookName, $injection);
}
if ($scope != 'Common') {
$this->process('Common', $hookName, $injection);
}
if (!empty($this->data[$scope])) {
if (!empty($this->data[$scope][$hookName])) {
foreach ($this->data[$scope][$hookName] as $className) {
if (empty($this->hooks[$className])) {
$this->hooks[$className] = $this->createHookByClassName($className);
}
$hook = $this->hooks[$className];
$hook->$hookName($injection);
}
}
}
if (!empty($this->data[$scope])) {
if (!empty($this->data[$scope][$hookName])) {
foreach ($this->data[$scope][$hookName] as $className) {
if (empty($this->hooks[$className])) {
$this->hooks[$className] = $this->createHookByClassName($className);
}
$hook = $this->hooks[$className];
$hook->$hookName($injection);
}
}
}
}
public function createHookByClassName($className)
{
if (class_exists($className)) {
$hook = new $className();
$dependencies = $hook->getDependencyList();
foreach ($dependencies as $name) {
$hook->inject($name, $this->container->get($name));
}
return $hook;
}
throw new Error("Class '$className' does not exist");
}
public function createHookByClassName($className)
{
if (class_exists($className)) {
$hook = new $className();
$dependencies = $hook->getDependencyList();
foreach ($dependencies as $name) {
$hook->inject($name, $this->container->get($name));
}
return $hook;
}
throw new Error("Class '$className' does not exist");
}
/**
* Get and merge hook data by checking the files exist in $hookDirs
*
* @param array $hookDirs - it can be an array('Espo/Hooks', 'Espo/Custom/Hooks', 'Espo/Modules/Crm/Hooks')
*
* @return array
*/
protected function getHookData($hookDirs)
{
if (is_string($hookDirs)) {
$hookDirs = (array) $hookDirs;
}
*
* @param array $hookDirs - it can be an array('Espo/Hooks', 'Espo/Custom/Hooks', 'Espo/Modules/Crm/Hooks')
*
* @return array
*/
protected function getHookData($hookDirs)
{
if (is_string($hookDirs)) {
$hookDirs = (array) $hookDirs;
}
$hooks = array();
$hooks = array();
foreach ($hookDirs as $hookDir) {
foreach ($hookDirs as $hookDir) {
if (file_exists($hookDir)) {
$fileList = $this->getFileManager()->getFileList($hookDir, 1, '\.php$', 'file');
if (file_exists($hookDir)) {
$fileList = $this->getFileManager()->getFileList($hookDir, 1, '\.php$', true);
foreach ($fileList as $scopeName => $hookFiles) {
foreach ($fileList as $scopeName => $hookFiles) {
$hookScopeDirPath = Util::concatPath($hookDir, $scopeName);
$hookScopeDirPath = Util::concatPath($hookDir, $scopeName);
$scopeHooks = array();
foreach($hookFiles as $hookFile) {
$hookFilePath = Util::concatPath($hookScopeDirPath, $hookFile);
$className = Util::getClassName($hookFilePath);
$scopeHooks = array();
foreach($hookFiles as $hookFile) {
$hookFilePath = Util::concatPath($hookScopeDirPath, $hookFile);
$className = Util::getClassName($hookFilePath);
foreach($this->hookList as $hookName) {
if (method_exists($className, $hookName)) {
$scopeHooks[$hookName][$className::$order][] = $className;
}
}
}
foreach($this->hookList as $hookName) {
if (method_exists($className, $hookName)) {
$scopeHooks[$hookName][$className::$order][] = $className;
}
}
}
//sort hooks by order
foreach ($scopeHooks as $hookName => $hookList) {
ksort($hookList);
//sort hooks by order
foreach ($scopeHooks as $hookName => $hookList) {
ksort($hookList);
$sortedHookList = array();
foreach($hookList as $hookDetails) {
$sortedHookList = array_merge($sortedHookList, $hookDetails);
}
$sortedHookList = array();
foreach($hookList as $hookDetails) {
$sortedHookList = array_merge($sortedHookList, $hookDetails);
}
$hooks[$scopeName][$hookName] = isset($hooks[$scopeName][$hookName]) ? array_merge($hooks[$scopeName][$hookName], $sortedHookList) : $sortedHookList;
}
}
}
}
}
}
}
}
return $hooks;
}
return $hooks;
}
}

View File

@@ -26,70 +26,70 @@ use \Espo\Core\Interfaces\Injectable;
class Base implements Injectable
{
protected $dependencies = array(
'entityManager',
'config',
'metadata',
'acl',
'user',
);
protected $dependencies = array(
'entityManager',
'config',
'metadata',
'acl',
'user',
);
protected $injections = array();
protected $injections = array();
public static $order = 9;
public static $order = 9;
public function __construct()
{
$this->init();
}
public function __construct()
{
$this->init();
}
protected function init()
{
}
protected function init()
{
}
public function getDependencyList()
{
return $this->dependencies;
}
public function getDependencyList()
{
return $this->dependencies;
}
protected function getInjection($name)
{
return $this->injections[$name];
}
protected function getInjection($name)
{
return $this->injections[$name];
}
public function inject($name, $object)
{
$this->injections[$name] = $object;
}
public function inject($name, $object)
{
$this->injections[$name] = $object;
}
protected function getEntityManager()
{
return $this->injections['entityManager'];
}
protected function getEntityManager()
{
return $this->injections['entityManager'];
}
protected function getUser()
{
return $this->injections['user'];
}
protected function getUser()
{
return $this->injections['user'];
}
protected function getAcl()
{
return $this->injections['acl'];
}
protected function getAcl()
{
return $this->injections['acl'];
}
protected function getConfig()
{
return $this->injections['config'];
}
protected function getConfig()
{
return $this->injections['config'];
}
protected function getMetadata()
{
return $this->injections['metadata'];
}
protected function getMetadata()
{
return $this->injections['metadata'];
}
protected function getRepository()
{
return $this->getEntityManager()->getRepository($this->entityName);
}
protected function getRepository()
{
return $this->getEntityManager()->getRepository($this->entityName);
}
}

View File

@@ -24,8 +24,8 @@ namespace Espo\Core\Interfaces;
interface Injectable
{
public function getDependencyList();
public function inject($name, $object);
public function getDependencyList();
public function inject($name, $object);
}

View 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\Core\Interfaces;
interface Loader
{
public function load();
}

View File

@@ -27,44 +27,44 @@ use \Espo\Core\Container;
abstract class Base
{
private $container;
private $container;
protected function getContainer()
{
return $this->container;
}
protected function getContainer()
{
return $this->container;
}
protected function getEntityManager()
{
return $this->getContainer()->get('entityManager');
}
protected function getEntityManager()
{
return $this->getContainer()->get('entityManager');
}
protected function getServiceFactory()
{
return $this->getContainer()->get('serviceFactory');
}
protected function getServiceFactory()
{
return $this->getContainer()->get('serviceFactory');
}
protected function getConfig()
{
return $this->getContainer()->get('config');
}
protected function getConfig()
{
return $this->getContainer()->get('config');
}
protected function getMetadata()
{
return $this->getContainer()->get('metadata');
}
protected function getMetadata()
{
return $this->getContainer()->get('metadata');
}
protected function getUser()
{
return $this->getContainer()->get('user');
}
protected function getUser()
{
return $this->getContainer()->get('user');
}
public function __construct(Container $container)
{
$this->container = $container;
}
public function __construct(Container $container)
{
$this->container = $container;
}
abstract public function run();
abstract public function run();
}

View File

@@ -0,0 +1,38 @@
<?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;
abstract class Base implements \Espo\Core\Interfaces\Loader
{
private $container;
public function __construct(\Espo\Core\Container $container)
{
$this->container = $container;
}
protected function getContainer()
{
return $this->container;
}
}

View File

@@ -22,43 +22,28 @@
namespace Espo\Core\Loaders;
use Doctrine\ORM\Tools\Setup,
Espo\Core\Doctrine\ORM\Mapping\Driver\EspoPHPDriver;
class EntityManager
class EntityManager extends Base
{
private $container;
public function load()
{
$config = $this->getContainer()->get('config');
public function __construct(\Espo\Core\Container $container)
{
$this->container = $container;
}
$params = array(
'host' => $config->get('database.host'),
'port' => $config->get('database.port'),
'dbname' => $config->get('database.dbname'),
'user' => $config->get('database.user'),
'password' => $config->get('database.password'),
'metadata' => $this->getContainer()->get('metadata')->getOrmMetadata(),
'repositoryFactoryClassName' => '\\Espo\\Core\\ORM\\RepositoryFactory',
);
protected function getContainer()
{
return $this->container;
}
$entityManager = new \Espo\Core\ORM\EntityManager($params);
$entityManager->setEspoMetadata($this->getContainer()->get('metadata'));
$entityManager->setHookManager($this->getContainer()->get('hookManager'));
$entityManager->setContainer($this->getContainer());
public function load()
{
$config = $this->getContainer()->get('config');
$params = array(
'host' => $config->get('database.host'),
'port' => $config->get('database.port'),
'dbname' => $config->get('database.dbname'),
'user' => $config->get('database.user'),
'password' => $config->get('database.password'),
'metadata' => $this->getContainer()->get('metadata')->getOrmMetadata(),
'repositoryFactoryClassName' => '\\Espo\\Core\\ORM\\RepositoryFactory',
);
$entityManager = new \Espo\Core\ORM\EntityManager($params);
$entityManager->setEspoMetadata($this->getContainer()->get('metadata'));
$entityManager->setHookManager($this->getContainer()->get('hookManager'));
$entityManager->setContainer($this->getContainer());
return $entityManager;
}
return $entityManager;
}
}

View File

@@ -23,42 +23,30 @@
namespace Espo\Core\Loaders;
use Espo\Core\Utils,
Espo\Core\Utils\Log\Monolog\Handler;
Espo\Core\Utils\Log\Monolog\Handler;
class Log
class Log extends Base
{
private $container;
public function load()
{
$logConfig = $this->getContainer()->get('config')->get('logger');
public function __construct(\Espo\Core\Container $container)
{
$this->container = $container;
}
$log = new Utils\Log('Espo');
protected function getContainer()
{
return $this->container;
}
$levelCode = $log->getLevelCode($logConfig['level']);
public function load()
{
$logConfig = $this->getContainer()->get('config')->get('logger');
if ($logConfig['isRotate']) {
$handler = new Handler\RotatingFileHandler($logConfig['path'], $logConfig['maxRotateFiles'], $levelCode);
} else {
$handler = new Handler\StreamHandler($logConfig['path'], $levelCode);
}
$log->pushHandler($handler);
$log = new Utils\Log('Espo');
$errorHandler = new \Monolog\ErrorHandler($log);
$errorHandler->registerExceptionHandler(null, false);
$errorHandler->registerErrorHandler(array(), false);
$levelCode = $log->getLevelCode($logConfig['level']);
if ($logConfig['isRotate']) {
$handler = new Handler\RotatingFileHandler($logConfig['path'], $logConfig['maxRotateFiles'], $levelCode);
} else {
$handler = new Handler\StreamHandler($logConfig['path'], $levelCode);
}
$log->pushHandler($handler);
$errorHandler = new \Monolog\ErrorHandler($log);
$errorHandler->registerExceptionHandler(null, false);
$errorHandler->registerErrorHandler(array(), false);
return $log;
}
return $log;
}
}

View File

@@ -0,0 +1,249 @@
<?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');
$subject = $message->subject;
if ($subject !== '0' && empty($subject)) {
$subject = '--empty--';
}
$email->set('isHtml', false);
$email->set('name', $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&amp;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;
}
}

View File

@@ -36,221 +36,247 @@ use \Espo\Core\Exceptions\Error;
class Sender
{
protected $config;
protected $config;
protected $transport;
protected $transport;
protected $isGlobal = false;
protected $isGlobal = false;
protected $params = array();
protected $params = array();
public function __construct($config)
{
$this->config = $config;
$this->useGlobal();
}
public function __construct($config)
{
$this->config = $config;
$this->useGlobal();
}
public function resetParams()
{
$this->params = array();
return $this;
}
public function resetParams()
{
$this->params = array();
return $this;
}
public function setParams(array $params = array())
{
$this->params = array_merge($this->params, $params);
return $this;
}
public function setParams(array $params = array())
{
$this->params = array_merge($this->params, $params);
return $this;
}
public function useSmtp(array $params = array())
{
$this->isGlobal = false;
$this->params = $params;
public function useSmtp(array $params = array())
{
$this->isGlobal = false;
$this->params = $params;
$this->transport = new SmtpTransport();
$this->transport = new SmtpTransport();
$opts = array(
'name' => 'admin',
'host' => $params['server'],
'port' => $params['port'],
'connection_config' => array()
);
if ($params['auth']) {
$opts['connection_class'] = 'login';
$opts['connection_config']['username'] = $params['username'];
$opts['connection_config']['password'] = $params['password'];
}
if ($params['security']) {
$opts['connection_config']['ssl'] = strtolower($params['security']);
}
if (in_array('fromName', $params)) {
$this->params['fromName'] = $params['fromName'];
}
if (in_array('fromAddress', $params)) {
$this->params['fromAddress'] = $params['fromAddress'];
}
$options = new SmtpOptions($opts);
$this->transport->setOptions($options);
$opts = array(
'name' => 'admin',
'host' => $params['server'],
'port' => $params['port'],
'connection_config' => array()
);
if ($params['auth']) {
$opts['connection_class'] = 'login';
$opts['connection_config']['username'] = $params['username'];
$opts['connection_config']['password'] = $params['password'];
}
if ($params['security']) {
$opts['connection_config']['ssl'] = strtolower($params['security']);
}
return $this;
}
$options = new SmtpOptions($opts);
$this->transport->setOptions($options);
public function useGlobal()
{
$this->params = array();
if ($this->isGlobal) {
return $this;
}
return $this;
}
$this->transport = new SmtpTransport();
public function useGlobal()
{
$this->params = array();
if ($this->isGlobal) {
return $this;
}
$config = $this->config;
$this->transport = new SmtpTransport();
$opts = array(
'name' => 'admin',
'host' => $config->get('smtpServer'),
'port' => $config->get('smtpPort'),
'connection_config' => array()
);
if ($config->get('smtpAuth')) {
$opts['connection_class'] = 'login';
$opts['connection_config']['username'] = $config->get('smtpUsername');
$opts['connection_config']['password'] = $config->get('smtpPassword');
}
if ($config->get('smtpSecurity')) {
$opts['connection_config']['ssl'] = strtolower($config->get('smtpSecurity'));
}
$config = $this->config;
$options = new SmtpOptions($opts);
$this->transport->setOptions($options);
$opts = array(
'name' => 'admin',
'host' => $config->get('smtpServer'),
'port' => $config->get('smtpPort'),
'connection_config' => array()
);
if ($config->get('smtpAuth')) {
$opts['connection_class'] = 'login';
$opts['connection_config']['username'] = $config->get('smtpUsername');
$opts['connection_config']['password'] = $config->get('smtpPassword');
}
if ($config->get('smtpSecurity')) {
$opts['connection_config']['ssl'] = strtolower($config->get('smtpSecurity'));
}
$this->isGlobal = true;
$options = new SmtpOptions($opts);
$this->transport->setOptions($options);
return $this;
}
$this->isGlobal = true;
public function send(Email $email, $params = array())
{
$message = new Message();
$config = $this->config;
$params = $this->params + $params;
return $this;
}
if ($email->get('from')) {
$fromName = null;
if (!empty($params['fromName'])) {
$fromName = $params['fromName'];
} else {
$fromName = $config->get('outboundEmailFromName');
}
$message->addFrom(trim($email->get('from')), $fromName);
} else {
if (!empty($params['fromAddress'])) {
$fromAddress = $params['fromAddress'];
} else {
if (!$config->get('outboundEmailFromAddress')) {
throw new Error('outboundEmailFromAddress is not specified in config.');
}
$fromAddress = $config->get('outboundEmailFromAddress');
}
public function send(Email $email)
{
$message = new Message();
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);
}
$config = $this->config;
$value = $email->get('to');
if ($value) {
$arr = explode(';', $value);
if (is_array($arr)) {
foreach ($arr as $address) {
$message->addTo(trim($address));
}
}
}
if ($email->get('from')) {
$fromName = null;
if (!empty($this->params['fromName'])) {
$fromName = $this->params['fromName'];
} else {
$fromName = $config->get('outboundEmailFromName');
}
$message->addFrom(trim($email->get('from')), $fromName);
} else {
if (!empty($this->params['fromAddress'])) {
$fromAddress = $this->params['fromAddress'];
} else {
if (!$config->get('outboundEmailFromAddress')) {
throw new Error('outboundEmailFromAddress is not specified in config.');
}
$fromAddress = $config->get('outboundEmailFromAddress');
}
$value = $email->get('cc');
if ($value) {
$arr = explode(';', $value);
if (is_array($arr)) {
foreach ($arr as $address) {
$message->addCC(trim($address));
}
}
}
if (!empty($this->params['fromName'])) {
$fromName = $this->params['fromName'];
} else {
$fromName = $config->get('outboundEmailFromName');
}
$value = $email->get('bcc');
if ($value) {
$arr = explode(';', $value);
if (is_array($arr)) {
foreach ($arr as $address) {
$message->addBCC(trim($address));
}
}
}
$message->addFrom($fromAddress, $fromName);
}
$message->setSubject($email->get('name'));
$value = $email->get('to');
if ($value) {
$arr = explode(';', $value);
if (is_array($arr)) {
foreach ($arr as $address) {
$message->addTo(trim($address));
}
}
}
$body = new MimeMessage;
$parts = array();
$value = $email->get('cc');
if ($value) {
$arr = explode(';', $value);
if (is_array($arr)) {
foreach ($arr as $address) {
$message->addCC(trim($address));
}
}
}
$bodyPart = new MimePart($email->getBodyPlainForSending());
$bodyPart->type = 'text/plain';
$bodyPart->charset = 'utf-8';
$parts[] = $bodyPart;
$value = $email->get('bcc');
if ($value) {
$arr = explode(';', $value);
if (is_array($arr)) {
foreach ($arr as $address) {
$message->addBCC(trim($address));
}
}
}
if ($email->get('isHtml')) {
$bodyPart = new MimePart($email->getBodyForSending());
$bodyPart->type = 'text/html';
$bodyPart->charset = 'utf-8';
$parts[] = $bodyPart;
}
$message->setSubject($email->get('name'));
$aCollection = $email->get('attachments');
if (!empty($aCollection)) {
foreach ($aCollection as $a) {
$fileName = 'data/upload/' . $a->id;
$attachment = new MimePart(file_get_contents($fileName));
$attachment->disposition = Mime::DISPOSITION_ATTACHMENT;
$attachment->encoding = Mime::ENCODING_BASE64;
$attachment->filename = $a->get('name');
if ($a->get('type')) {
$attachment->type = $a->get('type');
}
$parts[] = $attachment;
}
}
$aCollection = $email->getInlineAttachments();
if (!empty($aCollection)) {
foreach ($aCollection as $a) {
$fileName = 'data/upload/' . $a->id;
$attachment = new MimePart(file_get_contents($fileName));
$attachment->disposition = Mime::DISPOSITION_INLINE;
$attachment->encoding = Mime::ENCODING_BASE64;
$attachment->id = $a->id;
if ($a->get('type')) {
$attachment->type = $a->get('type');
}
$parts[] = $attachment;
}
}
$body = new MimeMessage;
$parts = array();
$body->setParts($parts);
$message->setBody($body);
if ($email->get('isHtml')) {
$message->getHeaders()->get('content-type')->setType('multipart/alternative');
}
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';
}
try {
if ($email->get('parentType') && $email->get('parentId')) {
$messageId = '<' . $email->get('parentType') .'/' . $email->get('parentId') . '/' . time() . '@espo>';
} else {
$messageId = '<' . md5($email->get('name')) . '/' . time() . '@espo>';
}
$message->getHeaders()->addHeaderLine('Message-Id', $messageId);
$parts[] = $bodyPart;
$this->transport->send($message);
$aCollection = $email->get('attachments');
if (!empty($aCollection)) {
foreach ($aCollection as $a) {
$fileName = 'data/upload/' . $a->id;
$attachment = new MimePart(file_get_contents($fileName));
$attachment->disposition = Mime::DISPOSITION_ATTACHMENT;
$attachment->encoding = Mime::ENCODING_BASE64;
$attachment->filename = $a->get('name');
if ($a->get('type')) {
$attachment->type = $a->get('type');
}
$parts[] = $attachment;
}
}
$aCollection = $email->getInlineAttachments();
if (!empty($aCollection)) {
foreach ($aCollection as $a) {
$fileName = 'data/upload/' . $a->id;
$attachment = new MimePart(file_get_contents($fileName));
$attachment->disposition = Mime::DISPOSITION_INLINE;
$attachment->encoding = Mime::ENCODING_BASE64;
$attachment->id = $a->id;
if ($a->get('type')) {
$attachment->type = $a->get('type');
}
$parts[] = $attachment;
}
}
$email->set('messageId', $message_id);
$email->set('status', 'Sent');
$email->set('dateSent', date("Y-m-d H:i:s"));
} catch (\Exception $e) {
throw new Error($e->getMessage(), 500);
}
$body->setParts($parts);
$message->setBody($body);
try {
$this->transport->send($message);
$email->set('status', 'Sent');
$email->set('dateSent', date("Y-m-d H:i:s"));
} catch (\Exception $e) {
throw new Error($e->getMessage(), 500);
}
$this->useGlobal();
}
$this->useGlobal();
}
}

View 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 . '"'));
}
}

View File

@@ -18,12 +18,12 @@
*
* 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\ORM\DB;
class MysqlMapper extends \Espo\ORM\DB\MysqlMapper
{
protected $returnCollection = false;
protected $returnCollection = false;
}

View File

@@ -18,26 +18,46 @@
*
* 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\ORM;
class Entity extends \Espo\ORM\Entity
{
public function loadLinkMultipleField($field)
{
if ($this->hasRelation($field) && $this->hasField($field . 'Ids')) {
$collection = $this->get($field);
$ids = array();
$names = new \stdClass();
foreach ($collection as $e) {
$id = $e->id;
$ids[] = $id;
$names->$id = $e->get('name');
}
$this->set($field . 'Ids', $ids);
$this->set($field . 'Names', $names);
}
}
public function loadLinkMultipleField($field, $columns = null)
{
if ($this->hasRelation($field) && $this->hasField($field . 'Ids')) {
$defs = array();
if (!empty($columns)) {
$defs['additionalColumns'] = $columns;
}
$collection = $this->get($field, $defs);
$ids = array();
$names = new \stdClass();
if (!empty($columns)) {
$columnsData = new \stdClass();
}
foreach ($collection as $e) {
$id = $e->id;
$ids[] = $id;
$names->$id = $e->get('name');
if (!empty($columns)) {
$columnsData->$id = new \stdClass();
foreach ($columns as $column => $f) {
$columnsData->$id->$column = $e->get($f);
}
}
}
$this->set($field . 'Ids', $ids);
$this->set($field . 'Names', $names);
if (!empty($columns)) {
$this->set($field . 'Columns', $columnsData);
}
}
}
}

View File

@@ -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\ORM;
@@ -26,75 +26,80 @@ use \Espo\Core\Utils\Util;
class EntityManager extends \Espo\ORM\EntityManager
{
protected $espoMetadata;
private $hookManager;
protected $user;
protected $container;
private $repositoryClassNameHash = array();
private $entityClassNameHash = array();
public function setContainer(\Espo\Core\Container $container)
{
$this->container = $container;
}
public function getContainer()
{
return $this->container;
}
public function setUser($user)
{
$this->user = $user;
}
public function getUser()
{
return $this->user;
}
protected $espoMetadata;
public function setEspoMetadata($espoMetadata)
{
$this->espoMetadata = $espoMetadata;
}
public function setHookManager(\Espo\Core\HookManager $hookManager)
{
$this->hookManager = $hookManager;
}
public function getHookManager()
{
return $this->hookManager;
}
private $hookManager;
public function normalizeRepositoryName($name)
{
if (empty($this->repositoryClassNameHash[$name])) {
$className = '\\Espo\\Custom\\Repositories\\' . Util::normilizeClassName($name);
if (!class_exists($className)) {
$className = $this->espoMetadata->getRepositoryPath($name);
}
$this->repositoryClassNameHash[$name] = $className;
}
return $this->repositoryClassNameHash[$name];
}
public function normalizeEntityName($name)
{
if (empty($this->entityClassNameHash[$name])) {
$className = '\\Espo\\Custom\\Entities\\' . Util::normilizeClassName($name);
if (!class_exists($className)) {
$className = $this->espoMetadata->getEntityPath($name);
}
$this->entityClassNameHash[$name] = $className;
}
return $this->entityClassNameHash[$name];
}
protected $user;
protected $container;
private $repositoryClassNameHash = array();
private $entityClassNameHash = array();
public function setContainer(\Espo\Core\Container $container)
{
$this->container = $container;
}
public function getContainer()
{
return $this->container;
}
public function setUser($user)
{
$this->user = $user;
}
public function getUser()
{
return $this->user;
}
public function getEspoMetadata()
{
return $this->espoMetadata;
}
public function setEspoMetadata($espoMetadata)
{
$this->espoMetadata = $espoMetadata;
}
public function setHookManager(\Espo\Core\HookManager $hookManager)
{
$this->hookManager = $hookManager;
}
public function getHookManager()
{
return $this->hookManager;
}
public function normalizeRepositoryName($name)
{
if (empty($this->repositoryClassNameHash[$name])) {
$className = '\\Espo\\Custom\\Repositories\\' . Util::normilizeClassName($name);
if (!class_exists($className)) {
$className = $this->espoMetadata->getRepositoryPath($name);
}
$this->repositoryClassNameHash[$name] = $className;
}
return $this->repositoryClassNameHash[$name];
}
public function normalizeEntityName($name)
{
if (empty($this->entityClassNameHash[$name])) {
$className = '\\Espo\\Custom\\Entities\\' . Util::normilizeClassName($name);
if (!class_exists($className)) {
$className = $this->espoMetadata->getEntityPath($name);
}
$this->entityClassNameHash[$name] = $className;
}
return $this->entityClassNameHash[$name];
}
}

View File

@@ -26,195 +26,290 @@ 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;
class RDB extends \Espo\ORM\Repositories\RDB implements Injectable
{
public static $mapperClassName = '\\Espo\\Core\\ORM\\DB\\MysqlMapper';
public static $mapperClassName = '\\Espo\\Core\\ORM\\DB\\MysqlMapper';
protected $dependencies = array(
'metadata'
);
protected $dependencies = array(
'metadata'
);
protected $injections = array();
protected $injections = array();
public function inject($name, $object)
{
$this->injections[$name] = $object;
}
public function inject($name, $object)
{
$this->injections[$name] = $object;
}
protected function getInjection($name)
{
return $this->injections[$name];
}
protected function getInjection($name)
{
return $this->injections[$name];
}
public function getDependencyList()
{
return $this->dependencies;
}
public function getDependencyList()
{
return $this->dependencies;
}
protected function getMetadata()
{
return $this->getInjection('metadata');
}
protected function getMetadata()
{
return $this->getInjection('metadata');
}
protected function handleSelectParams(&$params, $entityName = false)
{
$this->handleEmailAddressParams($params, $entityName);
}
public function handleSelectParams(&$params)
{
$this->handleEmailAddressParams($params);
$this->handlePhoneNumberParams($params);
$this->handleCurrencyParams($params);
}
protected function handleEmailAddressParams(&$params, $entityName = false)
{
if (empty($entityName)) {
$entityName = $this->entityName;
}
protected function handleCurrencyParams(&$params)
{
$entityName = $this->entityName;
$defs = $this->getEntityManager()->getMetadata()->get($entityName);
if (!empty($defs['relations']) && array_key_exists('emailAddresses', $defs['relations'])) {
if (empty($params['leftJoins'])) {
$params['leftJoins'] = array();
}
if (empty($params['whereClause'])) {
$params['whereClause'] = array();
}
if (empty($params['joinConditions'])) {
$params['joinConditions'] = array();
}
$params['leftJoins'] = array('emailAddresses');
$params['joinConditions'] = array(
'emailAddresses' => array(
'primary' => 1
)
);
}
}
$metadata = $this->getMetadata();
protected function beforeRemove(Entity $entity)
{
parent::beforeRemove($entity);
$this->getEntityManager()->getHookManager()->process($this->entityName, 'beforeRemove', $entity);
}
if (!$metadata) {
return;
}
protected function afterRemove(Entity $entity)
{
parent::afterRemove($entity);
$this->getEntityManager()->getHookManager()->process($this->entityName, 'afterRemove', $entity);
}
$defs = $metadata->get('entityDefs.' . $entityName);
public function remove(Entity $entity)
{
$this->getEntityManager()->getHookManager()->process($this->entityName, 'beforeRemove', $entity);
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
";
}
}
$result = parent::remove($entity);
if ($result) {
$this->getEntityManager()->getHookManager()->process($this->entityName, 'afterRemove', $entity);
}
return $result;
}
}
protected function beforeSave(Entity $entity)
{
parent::beforeSave($entity);
$this->getEntityManager()->getHookManager()->process($this->entityName, 'beforeSave', $entity);
}
protected function handleEmailAddressParams(&$params)
{
$entityName = $this->entityName;
protected function afterSave(Entity $entity)
{
parent::afterSave($entity);
$this->getEntityManager()->getHookManager()->process($this->entityName, 'afterSave', $entity);
}
$defs = $this->getEntityManager()->getMetadata()->get($entityName);
if (!empty($defs['relations']) && array_key_exists('emailAddresses', $defs['relations'])) {
if (empty($params['leftJoins'])) {
$params['leftJoins'] = array();
}
if (empty($params['whereClause'])) {
$params['whereClause'] = array();
}
if (empty($params['joinConditions'])) {
$params['joinConditions'] = array();
}
$params['leftJoins'][] = 'emailAddresses';
$params['joinConditions']['emailAddresses'] = array(
'primary' => 1
);
}
}
public function save(Entity $entity)
{
$nowString = date('Y-m-d H:i:s', time());
$restoreData = array();
protected function handlePhoneNumberParams(&$params)
{
$entityName = $this->entityName;
if ($entity->isNew()) {
if (!$entity->has('id')) {
$entity->set('id', uniqid());
}
$defs = $this->getEntityManager()->getMetadata()->get($entityName);
if (!empty($defs['relations']) && array_key_exists('phoneNumbers', $defs['relations'])) {
if (empty($params['leftJoins'])) {
$params['leftJoins'] = array();
}
if (empty($params['whereClause'])) {
$params['whereClause'] = array();
}
if (empty($params['joinConditions'])) {
$params['joinConditions'] = array();
}
$params['leftJoins'][] = 'phoneNumbers';
$params['joinConditions']['phoneNumbers'] = array(
'primary' => 1
);
}
}
if ($entity->hasField('createdAt')) {
$entity->set('createdAt', $nowString);
}
if ($entity->hasField('createdById')) {
$entity->set('createdById', $this->entityManager->getUser()->id);
}
protected function beforeRemove(Entity $entity)
{
parent::beforeRemove($entity);
$this->getEntityManager()->getHookManager()->process($this->entityName, 'beforeRemove', $entity);
}
if ($entity->has('modifiedById')) {
$restoreData['modifiedById'] = $entity->get('modifiedById');
}
if ($entity->has('modifiedAt')) {
$restoreData['modifiedAt'] = $entity->get('modifiedAt');
}
$entity->clear('modifiedById');
$entity->clear('modifiedAt');
} else {
if ($entity->hasField('modifiedAt')) {
$entity->set('modifiedAt', $nowString);
}
if ($entity->hasField('modifiedById')) {
$entity->set('modifiedById', $this->entityManager->getUser()->id);
}
protected function afterRemove(Entity $entity)
{
parent::afterRemove($entity);
$this->getEntityManager()->getHookManager()->process($this->entityName, 'afterRemove', $entity);
}
if ($entity->has('createdById')) {
$restoreData['createdById'] = $entity->get('createdById');
}
if ($entity->has('createdAt')) {
$restoreData['createdAt'] = $entity->get('createdAt');
}
$entity->clear('createdById');
$entity->clear('createdAt');
}
$result = parent::save($entity);
public function remove(Entity $entity)
{
$this->getEntityManager()->getHookManager()->process($this->entityName, 'beforeRemove', $entity);
$entity->set($restoreData);
$result = parent::remove($entity);
if ($result) {
$this->getEntityManager()->getHookManager()->process($this->entityName, 'afterRemove', $entity);
}
return $result;
}
$this->handleEmailAddressSave($entity);
$this->handleSpecifiedRelations($entity);
protected function beforeSave(Entity $entity)
{
parent::beforeSave($entity);
$this->getEntityManager()->getHookManager()->process($this->entityName, 'beforeSave', $entity);
}
return $result;
}
protected function afterSave(Entity $entity)
{
parent::afterSave($entity);
$this->getEntityManager()->getHookManager()->process($this->entityName, 'afterSave', $entity);
}
protected function handleEmailAddressSave(Entity $entity)
{
if ($entity->hasRelation('emailAddresses') && $entity->hasField('emailAddress')) {
$emailAddressRepository = $this->getEntityManager()->getRepository('EmailAddress')->storeEntityEmailAddress($entity);
}
}
public function save(Entity $entity)
{
$nowString = date('Y-m-d H:i:s', time());
$restoreData = array();
protected function handleSpecifiedRelations(Entity $entity)
{
$relationTypes = array($entity::HAS_MANY, $entity::MANY_MANY, $entity::HAS_CHILDREN);
foreach ($entity->getRelations() as $name => $defs) {
if (in_array($defs['type'], $relationTypes)) {
$fieldName = $name . 'Ids';
if ($entity->has($fieldName)) {
$specifiedIds = $entity->get($fieldName);
if (is_array($specifiedIds)) {
$toRemoveIds = array();
$existingIds = array();
foreach ($entity->get($name) as $foreignEntity) {
$existingIds[] = $foreignEntity->id;
}
foreach ($existingIds as $id) {
if (!in_array($id, $specifiedIds)) {
$toRemoveIds[] = $id;
}
}
foreach ($specifiedIds as $id) {
if (!in_array($id, $existingIds)) {
$this->relate($entity, $name, $id);
}
}
foreach ($toRemoveIds as $id) {
$this->unrelate($entity, $name, $id);
}
}
}
}
}
}
if ($entity->isNew()) {
if (!$entity->has('id')) {
$entity->set('id', uniqid());
}
if ($entity->hasField('createdAt')) {
$entity->set('createdAt', $nowString);
}
if ($entity->hasField('modifiedAt')) {
$entity->set('modifiedAt', $nowString);
}
if ($entity->hasField('createdById')) {
$entity->set('createdById', $this->entityManager->getUser()->id);
}
if ($entity->has('modifiedById')) {
$restoreData['modifiedById'] = $entity->get('modifiedById');
}
if ($entity->has('modifiedAt')) {
$restoreData['modifiedAt'] = $entity->get('modifiedAt');
}
$entity->clear('modifiedById');
} else {
if ($entity->hasField('modifiedAt')) {
$entity->set('modifiedAt', $nowString);
}
if ($entity->hasField('modifiedById')) {
$entity->set('modifiedById', $this->entityManager->getUser()->id);
}
if ($entity->has('createdById')) {
$restoreData['createdById'] = $entity->get('createdById');
}
if ($entity->has('createdAt')) {
$restoreData['createdAt'] = $entity->get('createdAt');
}
$entity->clear('createdById');
$entity->clear('createdAt');
}
$result = parent::save($entity);
$entity->set($restoreData);
$this->handleEmailAddressSave($entity);
$this->handlePhoneNumberSave($entity);
$this->handleSpecifiedRelations($entity);
return $result;
}
protected function handleEmailAddressSave(Entity $entity)
{
if ($entity->hasRelation('emailAddresses') && $entity->hasField('emailAddress')) {
$emailAddressRepository = $this->getEntityManager()->getRepository('EmailAddress')->storeEntityEmailAddress($entity);
}
}
protected function handlePhoneNumberSave(Entity $entity)
{
if ($entity->hasRelation('phoneNumbers') && $entity->hasField('phoneNumber')) {
$emailAddressRepository = $this->getEntityManager()->getRepository('PhoneNumber')->storeEntityPhoneNumber($entity);
}
}
protected function handleSpecifiedRelations(Entity $entity)
{
$relationTypes = array($entity::HAS_MANY, $entity::MANY_MANY, $entity::HAS_CHILDREN);
foreach ($entity->getRelations() as $name => $defs) {
if (in_array($defs['type'], $relationTypes)) {
$fieldName = $name . 'Ids';
if ($entity->has($fieldName)) {
$specifiedIds = $entity->get($fieldName);
if (is_array($specifiedIds)) {
$toRemoveIds = array();
$existingIds = array();
$toUpdateIds = array();
$existingColumnsData = new \stdClass();
$defs = array();
$columns = $this->getMetadata()->get("entityDefs." . $entity->getEntityName() . ".fields.{$name}.columns");
if (!empty($columns)) {
$columnData = $entity->get($name . 'Columns');
$defs['additionalColumns'] = $columns;
}
foreach ($entity->get($name, $defs) as $foreignEntity) {
$existingIds[] = $foreignEntity->id;
if (!empty($columns)) {
$data = new \stdClass();
foreach ($columns as $columnName => $columnField) {
$foreignId = $foreignEntity->id;
$data->$columnName = $foreignEntity->get($columnField);
}
$existingColumnsData->$foreignId = $data;
}
}
foreach ($existingIds as $id) {
if (!in_array($id, $specifiedIds)) {
$toRemoveIds[] = $id;
} else {
if (!empty($columns)) {
foreach ($columns as $columnName => $columnField) {
if ($columnData->$id->$columnName != $existingColumnsData->$id->$columnName) {
$toUpdateIds[] = $id;
}
}
}
}
}
foreach ($specifiedIds as $id) {
if (!in_array($id, $existingIds)) {
$data = null;
if (!empty($columns)) {
$data = $columnData->$id;
}
$this->relate($entity, $name, $id, $data);
}
}
foreach ($toRemoveIds as $id) {
$this->unrelate($entity, $name, $id);
}
if (!empty($columns)) {
foreach ($toUpdateIds as $id) {
$data = $columnData->$id;
$this->updateRelation($entity, $name, $id, $data);
}
}
}
}
}
}
}
}

View File

@@ -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\ORM;
@@ -26,23 +26,23 @@ use \Espo\Core\Interfaces\Injectable;
abstract class Repository extends \Espo\ORM\Repository implements Injectable
{
protected $dependencies = array();
protected $injections = array();
public function inject($name, $object)
{
$this->injections[$name] = $object;
}
protected function getInjection($name)
{
return $this->injections[$name];
}
public function getDependencyList()
{
return $this->dependencies;
}
protected $dependencies = array();
protected $injections = array();
public function inject($name, $object)
{
$this->injections[$name] = $object;
}
protected function getInjection($name)
{
return $this->injections[$name];
}
public function getDependencyList()
{
return $this->dependencies;
}
}

View File

@@ -18,23 +18,23 @@
*
* 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\ORM;
class RepositoryFactory extends \Espo\ORM\RepositoryFactory
{
protected $defaultRepositoryClassName = '\\Espo\\Core\\ORM\\Repositories\\RDB';
{
protected $defaultRepositoryClassName = '\\Espo\\Core\\ORM\\Repositories\\RDB';
public function create($name)
{
$repository = parent::create($name);
$dependencies = $repository->getDependencyList();
foreach ($dependencies as $name) {
$repository->inject($name, $this->entityManager->getContainer()->get($name));
}
return $repository;
}
public function create($name)
{
$repository = parent::create($name);
$dependencies = $repository->getDependencyList();
foreach ($dependencies as $name) {
$repository->inject($name, $this->entityManager->getContainer()->get($name));
}
return $repository;
}
}

View File

@@ -28,41 +28,41 @@ use \Espo\Core\Utils\Util;
class SelectManagerFactory
{
private $entityManager;
private $user;
private $acl;
private $metadata;
private $entityManager;
private $user;
private $acl;
private $metadata;
public function __construct($entityManager, \Espo\Entities\User $user, Acl $acl, $metadata)
{
$this->entityManager = $entityManager;
$this->user = $user;
$this->acl = $acl;
$this->metadata = $metadata;
$this->entityManager = $entityManager;
$this->user = $user;
$this->acl = $acl;
$this->metadata = $metadata;
}
public function create($entityName)
{
$className = '\\Espo\\Custom\\SelectManagers\\' . Util::normilizeClassName($entityName);
if (!class_exists($className)) {
$moduleName = $this->metadata->getScopeModuleName($entityName);
if ($moduleName) {
$className = '\\Espo\\Modules\\' . $moduleName . '\\SelectManagers\\' . Util::normilizeClassName($entityName);
} else {
$className = '\\Espo\\SelectManagers\\' . Util::normilizeClassName($entityName);
}
if (!class_exists($className)) {
$className = '\\Espo\\Core\\SelectManagers\\Base';
}
}
$selectManager = new $className($this->entityManager, $this->user, $this->acl, $this->metadata);
$selectManager->setEntityName($entityName);
return $selectManager;
}
public function create($entityName)
{
$className = '\\Espo\\Custom\\SelectManagers\\' . Util::normilizeClassName($entityName);
if (!class_exists($className)) {
$moduleName = $this->metadata->getScopeModuleName($entityName);
if ($moduleName) {
$className = '\\Espo\\Modules\\' . $moduleName . '\\SelectManagers\\' . Util::normilizeClassName($entityName);
} else {
$className = '\\Espo\\SelectManagers\\' . Util::normilizeClassName($entityName);
}
if (!class_exists($className)) {
$className = '\\Espo\\Core\\SelectManagers\\Base';
}
}
$selectManager = new $className($this->entityManager, $this->user, $this->acl, $this->metadata);
$selectManager->setEntityName($entityName);
return $selectManager;
}
}

View File

@@ -28,262 +28,374 @@ use \Espo\Core\Acl;
class Base
{
protected $container;
protected $container;
protected $user;
protected $user;
protected $acl;
protected $acl;
protected $entityManager;
protected $entityManager;
protected $entityName;
protected $entityName;
protected $metadata;
protected $metadata;
const MIN_LENGTH_FOR_CONTENT_SEARCH = 4;
public function __construct($entityManager, \Espo\Entities\User $user, Acl $acl, $metadata)
{
$this->entityManager = $entityManager;
$this->user = $user;
$this->acl = $acl;
$this->metadata = $metadata;
$this->entityManager = $entityManager;
$this->user = $user;
$this->acl = $acl;
$this->metadata = $metadata;
}
public function setEntityName($entityName)
{
$this->entityName = $entityName;
$this->entityName = $entityName;
}
protected function limit($params, &$result)
{
if (isset($params['offset']) && !is_null($params['offset'])) {
$result['offset'] = $params['offset'];
}
if (isset($params['maxSize']) && !is_null($params['maxSize'])) {
$result['limit'] = $params['maxSize'];
}
if (isset($params['offset']) && !is_null($params['offset'])) {
$result['offset'] = $params['offset'];
}
if (isset($params['maxSize']) && !is_null($params['maxSize'])) {
$result['limit'] = $params['maxSize'];
}
}
protected function order($params, &$result)
{
if (!empty($params['sortBy'])) {
$result['orderBy'] = $params['sortBy'];
$type = $this->metadata->get("entityDefs.{$this->entityName}.fields." . $result['orderBy'] . ".type");
if ($type == 'link') {
$result['orderBy'] .= 'Name';
} else if ($type == 'linkParent') {
$result['orderBy'] .= 'Type';
}
}
if (isset($params['asc'])) {
if ($params['asc']) {
$result['order'] = 'ASC';
} else {
$result['order'] = 'DESC';
}
}
if (!empty($params['sortBy'])) {
$result['orderBy'] = $params['sortBy'];
$type = $this->metadata->get("entityDefs.{$this->entityName}.fields." . $result['orderBy'] . ".type");
if ($type == 'link') {
$result['orderBy'] .= 'Name';
} else if ($type == 'linkParent') {
$result['orderBy'] .= 'Type';
}
}
if (isset($params['asc'])) {
if ($params['asc']) {
$result['order'] = 'ASC';
} else {
$result['order'] = 'DESC';
}
}
}
protected function getTextFilterFields()
{
return $this->metadata->get("entityDefs.{$this->entityName}.collection.textFilterFields", array('name'));
}
protected function where($params, &$result)
{
if (!empty($params['where']) && is_array($params['where'])) {
$where = array();
if (!empty($params['where']) && is_array($params['where'])) {
$where = array();
foreach ($params['where'] as $item) {
if ($item['type'] == 'boolFilters' && !empty($item['value']) && is_array($item['value'])) {
foreach ($item['value'] as $filter) {
$p = $this->getBoolFilterWhere($filter);
if (!empty($p)) {
$params['where'][] = $p;
}
}
}
}
foreach ($params['where'] as $item) {
if ($item['type'] == 'boolFilters' && !empty($item['value']) && is_array($item['value'])) {
foreach ($item['value'] as $filter) {
$p = $this->getBoolFilterWhere($filter);
if (!empty($p)) {
$params['where'][] = $p;
}
}
} else if ($item['type'] == 'textFilter' && !empty($item['value'])) {
if (!empty($item['value'])) {
if (empty($result['whereClause'])) {
$result['whereClause'] = array();
}
$fieldDefs = $this->entityManager->getEntity($this->entityName)->getFields();
$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 . '*'] = '%' . $item['value'] . '%';
} else {
$d[$field . '*'] = $item['value'] . '%';
}
}
$where['OR'] = $d;
}
}
}
$linkedWith = array();
$ignoreList = array('linkedWith', 'boolFilters');
foreach ($params['where'] as $item) {
if (!in_array($item['type'], $ignoreList)) {
$part = $this->getWherePart($item);
if (!empty($part)) {
$where[] = $part;
}
} else {
if ($item['type'] == 'linkedWith') {
$linkedWith[$item['field']] = $item['value'];
}
}
}
$linkedWith = array();
$ignoreList = array('linkedWith', 'boolFilters');
foreach ($params['where'] as $item) {
if (!in_array($item['type'], $ignoreList)) {
$part = $this->getWherePart($item);
if (!empty($part)) {
$where[] = $part;
}
} else {
if ($item['type'] == 'linkedWith' && !empty($item['value'])) {
$linkedWith[$item['field']] = $item['value'];
}
}
}
if (!empty($linkedWith)) {
$joins = array();
if (!empty($linkedWith)) {
$joins = array();
$part = array();
foreach ($linkedWith as $link => $ids) {
$joins[] = $link;
$defs = $this->entityManager->getMetadata()->get($this->entityName);
$part = array();
foreach ($linkedWith as $link => $ids) {
$joins[] = $link;
$defs = $this->entityManager->getMetadata()->get($this->entityName);
$entityName = $defs['relations'][$link]['entity'];
if ($entityName) {
$part[$entityName . '.id'] = $ids;
}
}
$entityName = $defs['relations'][$link]['entity'];
if ($entityName) {
$part[$entityName . '.id'] = $ids;
}
}
if (!empty($part)) {
$where[] = $part;
}
$result['joins'] = $joins;
$result['distinct'] = true;
if (!empty($part)) {
$where[] = $part;
}
$result['joins'] = $joins;
$result['distinct'] = true;
}
}
$result['whereClause'] = $where;
}
$result['whereClause'] = $where;
}
}
protected function q($params, &$result)
{
if (!empty($params['q'])) {
if (empty($result['whereClause'])) {
$result['whereClause'] = array();
}
$result['whereClause']['name*'] = $params['q'] . '%';
}
}
if (!empty($params['q'])) {
if (empty($result['whereClause'])) {
$result['whereClause'] = array();
}
$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;
}
}
protected function access(&$result)
{
if ($this->acl->checkReadOnlyOwn($this->entityName)) {
if ($this->acl->checkReadOnlyOwn($this->entityName)) {
if (!array_key_exists('whereClause', $result)) {
$result['whereClause'] = array();
}
$result['whereClause']['assignedUserId'] = $this->user->id;
}
if ($this->acl->checkReadOnlyTeam($this->entityName)) {
if (!array_key_exists('whereClause', $result)) {
$result['whereClause'] = array();
}
if (!array_key_exists('joins', $result)) {
$result['joins'] = array();
}
if (!in_array('teams', $result['joins'])) {
$result['joins'][] = 'teams';
}
if (!array_key_exists('whereClause', $result)) {
$result['whereClause'] = array();
}
$result['whereClause']['assignedUserId'] = $this->user->id;
}
if (!$this->user->isAdmin() && $this->acl->checkReadOnlyTeam($this->entityName)) {
if (!array_key_exists('whereClause', $result)) {
$result['whereClause'] = array();
}
$result['distinct'] = true;
if (!array_key_exists('joins', $result)) {
$result['joins'] = array();
}
if (!in_array('teams', $result['joins'])) {
$result['leftJoins'][] = 'teams';
}
$result['whereClause']['Team.id'] = $this->user->get('teamsIds');
}
$result['whereClause']['OR'] = array(
'Team.id' => $this->user->get('teamsIds'),
'assignedUserId' => $this->user->id
);
//$result['whereClause']['Team.id'] = $this->user->get('teamsIds');
}
}
public function getAclParams()
{
$result = array();
$this->access($result);
return $result;
$result = array();
$this->access($result);
return $result;
}
public function getSelectParams(array $params, $withAcl = false)
{
$result = array();
public function getSelectParams(array $params, $withAcl = false)
{
$result = array();
$this->order($params, $result);
$this->limit($params, $result);
$this->where($params, $result);
$this->q($params, $result);
$this->order($params, $result);
$this->limit($params, $result);
$this->where($params, $result);
$this->q($params, $result);
if ($withAcl) {
$this->access($result);
}
if ($withAcl) {
$this->access($result);
}
return $result;
}
return $result;
}
protected function getWherePart($item)
{
$part = array();
protected function getWherePart($item)
{
$part = array();
if (!empty($item['type'])) {
switch ($item['type']) {
case 'or':
case 'and':
if (is_array($item['value'])) {
$arr = array();
foreach ($item['value'] as $i) {
$a = $this->getWherePart($i);
foreach ($a as $left => $right) {
if (!empty($right)) {
$arr[$left] = $right;
}
}
}
$part[strtoupper($item['type'])] = $arr;
}
break;
case 'like':
$part[$item['field'] . '*'] = $item['value'];
break;
case 'equals':
case 'on':
$part[$item['field'] . '='] = $item['value'];
break;
case 'notEquals':
case 'notOn':
$part[$item['field'] . '!='] = $item['value'];
break;
case 'greaterThan':
case 'after':
$part[$item['field'] . '>'] = $item['value'];
break;
case 'lessThan':
case 'before':
$part[$item['field'] . '<'] = $item['value'];
break;
case 'greaterThanOrEquals':
$part[$item['field'] . '>='] = $item['value'];
break;
case 'lessThanOrEquals':
$part[$item['field'] . '<'] = $item['value'];
break;
case 'in':
$part[$item['field'] . '='] = $item['value'];
break;
case 'notIn':
$part[$item['field'] . '!='] = $item['value'];
break;
case 'isTrue':
$part[$item['field'] . '='] = true;
break;
case 'isFalse':
$part[$item['field'] . '='] = false;
break;
case 'between':
if (is_array($item['value'])) {
$part['AND'] = array(
$item['field'] . '>=' => $item['value'][0],
$item['field'] . '<=' => $item['value'][1],
);
}
break;
}
}
if (!empty($item['type'])) {
switch ($item['type']) {
case 'or':
case 'and':
if (is_array($item['value'])) {
$arr = array();
foreach ($item['value'] as $i) {
$a = $this->getWherePart($i);
foreach ($a as $left => $right) {
if (!empty($right)) {
$arr[$left] = $right;
}
}
}
$part[strtoupper($item['type'])] = $arr;
}
break;
case 'like':
$part[$item['field'] . '*'] = $item['value'];
break;
case 'equals':
case 'on':
$part[$item['field'] . '='] = $item['value'];
break;
case 'notEquals':
case 'notOn':
$part[$item['field'] . '!='] = $item['value'];
break;
case 'greaterThan':
case 'after':
$part[$item['field'] . '>'] = $item['value'];
break;
case 'lessThan':
case 'before':
$part[$item['field'] . '<'] = $item['value'];
break;
case 'greaterThanOrEquals':
$part[$item['field'] . '>='] = $item['value'];
break;
case 'lessThanOrEquals':
$part[$item['field'] . '<'] = $item['value'];
break;
case 'in':
$part[$item['field'] . '='] = $item['value'];
break;
case 'notIn':
$part[$item['field'] . '!='] = $item['value'];
break;
case 'isTrue':
$part[$item['field'] . '='] = true;
break;
case 'isFalse':
$part[$item['field'] . '='] = false;
break;
case 'today':
$part[$item['field'] . '='] = date('Y-m-d');
break;
case 'past':
$part[$item['field'] . '<'] = date('Y-m-d');
break;
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(
$item['field'] . '>=' => $item['value'][0],
$item['field'] . '<=' => $item['value'][1],
);
}
break;
}
}
return $part;
}
return $part;
}
protected function getBoolFilterWhere($filterName)
{
$method = 'getBoolFilterWhere' . ucfirst($filterName);
if (method_exists($this, $method)) {
return $this->$method();
}
}
protected function getBoolFilterWhere($filterName)
{
$method = 'getBoolFilterWhere' . ucfirst($filterName);
if (method_exists($this, $method)) {
return $this->$method();
}
}
protected function getBoolFilterWhereOnlyMy()
{
return array(
'type' => 'equals',
'field' => 'assignedUserId',
'value' => $this->user->id,
);
}
protected function getBoolFilterWhereOnlyMy()
{
return array(
'type' => 'equals',
'field' => 'assignedUserId',
'value' => $this->user->id,
);
}
}

View File

@@ -28,127 +28,127 @@ use \Espo\Core\Utils\Util;
class ServiceFactory
{
private $container;
private $container;
protected $cacheFile = 'data/cache/application/services.php';
protected $cacheFile = 'data/cache/application/services.php';
/**
/**
* @var array - path to Service files
*/
protected $paths = array(
'corePath' => 'application/Espo/Services',
'modulePath' => 'application/Espo/Modules/{*}/Services',
'customPath' => 'custom/Espo/Custom/Services',
);
protected $paths = array(
'corePath' => 'application/Espo/Services',
'modulePath' => 'application/Espo/Modules/{*}/Services',
'customPath' => 'custom/Espo/Custom/Services',
);
protected $data;
protected $data;
public function __construct(Container $container)
{
$this->container = $container;
$this->container = $container;
}
protected function init()
{
$config = $this->getContainer()->get('config');
protected function init()
{
$config = $this->getContainer()->get('config');
if (file_exists($this->cacheFile) && $config->get('useCache')) {
$this->data = $this->getFileManager()->getContents($this->cacheFile);
} else {
$this->data = $this->getClassNameHash($this->paths['corePath']);
if (file_exists($this->cacheFile) && $config->get('useCache')) {
$this->data = $this->getFileManager()->getContents($this->cacheFile);
} else {
$this->data = $this->getClassNameHash($this->paths['corePath']);
foreach ($this->getContainer()->get('metadata')->getModuleList() as $moduleName) {
$path = str_replace('{*}', $moduleName, $this->paths['modulePath']);
$this->data = array_merge($this->data, $this->getClassNameHash($path));
}
foreach ($this->getContainer()->get('metadata')->getModuleList() as $moduleName) {
$path = str_replace('{*}', $moduleName, $this->paths['modulePath']);
$this->data = array_merge($this->data, $this->getClassNameHash($path));
}
$this->data = array_merge($this->data, $this->getClassNameHash($this->paths['customPath']));
$this->data = array_merge($this->data, $this->getClassNameHash($this->paths['customPath']));
if ($config->get('useCache')) {
$result = $this->getFileManager()->putContentsPHP($this->cacheFile, $this->data);
if ($result == false) {
throw new \Espo\Core\Exceptions\Error();
}
}
}
}
if ($config->get('useCache')) {
$result = $this->getFileManager()->putContentsPHP($this->cacheFile, $this->data);
if ($result == false) {
throw new \Espo\Core\Exceptions\Error();
}
}
}
}
protected function getFileManager()
{
return $this->container->get('fileManager');
}
protected function getFileManager()
{
return $this->container->get('fileManager');
}
protected function getContainer()
{
return $this->container;
}
protected function getContainer()
{
return $this->container;
}
protected function getClassName($name)
{
$name = Util::normilizeClassName($name);
protected function getClassName($name)
{
$name = Util::normilizeClassName($name);
if (!isset($this->data)) {
$this->init();
}
if (!isset($this->data)) {
$this->init();
}
$name = ucfirst($name);
if (isset($this->data[$name])) {
return $this->data[$name];
}
$name = ucfirst($name);
if (isset($this->data[$name])) {
return $this->data[$name];
}
return false;
}
}
public function checkExists($name) {
$className = $this->getClassName($name);
if (!empty($className)) {
return true;
}
}
public function checkExists($name) {
$className = $this->getClassName($name);
if (!empty($className)) {
return true;
}
}
public function create($name)
{
$className = $this->getClassName($name);
if (empty($className)) {
throw new Error();
}
return $this->createByClassName($className);
$className = $this->getClassName($name);
if (empty($className)) {
throw new Error();
}
return $this->createByClassName($className);
}
protected function createByClassName($className)
{
if (class_exists($className)) {
$service = new $className();
$dependencies = $service->getDependencyList();
foreach ($dependencies as $name) {
$service->inject($name, $this->container->get($name));
}
return $service;
}
throw new Error("Class '$className' does not exist");
}
protected function createByClassName($className)
{
if (class_exists($className)) {
$service = new $className();
$dependencies = $service->getDependencyList();
foreach ($dependencies as $name) {
$service->inject($name, $this->container->get($name));
}
return $service;
}
throw new Error("Class '$className' does not exist");
}
// TODO delegate to another class
protected function getClassNameHash($dirs)
{
if (is_string($dirs)) {
$dirs = (array) $dirs;
}
// TODO delegate to another class
protected function getClassNameHash($dirs)
{
if (is_string($dirs)) {
$dirs = (array) $dirs;
}
$data = array();
$data = array();
foreach ($dirs as $dir) {
if (file_exists($dir)) {
$fileList = $this->getFileManager()->getFileList($dir, false, '\.php$', 'file');
foreach ($fileList as $file) {
$filePath = Util::concatPath($dir, $file);
$className = Util::getClassName($filePath);
$fileName = $this->getFileManager()->getFileName($filePath);
$data[$fileName] = $className;
}
}
}
return $data;
}
foreach ($dirs as $dir) {
if (file_exists($dir)) {
$fileList = $this->getFileManager()->getFileList($dir, false, '\.php$', true);
foreach ($fileList as $file) {
$filePath = Util::concatPath($dir, $file);
$className = Util::getClassName($filePath);
$fileName = $this->getFileManager()->getFileName($filePath);
$data[$fileName] = $className;
}
}
}
return $data;
}
}

View File

@@ -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\Services;
@@ -26,32 +26,51 @@ use \Espo\Core\Interfaces\Injectable;
abstract class Base implements Injectable
{
protected $dependencies = array();
protected $injections = array();
public function inject($name, $object)
{
$this->injections[$name] = $object;
}
public function __construct()
{
$this->init();
}
protected function init()
{
}
protected function getInjection($name)
{
return $this->injections[$name];
}
public function getDependencyList()
{
return $this->dependencies;
}
protected $dependencies = array(
'config',
'entityManager',
'user',
);
protected $injections = array();
public function inject($name, $object)
{
$this->injections[$name] = $object;
}
public function __construct()
{
$this->init();
}
protected function init()
{
}
protected function getInjection($name)
{
return $this->injections[$name];
}
public function getDependencyList()
{
return $this->dependencies;
}
protected function getEntityManager()
{
return $this->getInjection('entityManager');
}
protected function getConfig()
{
return $this->getInjection('config');
}
protected function getUser()
{
return $this->getInjection('user');
}
}

View File

@@ -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',
)
);
}

View 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];
}
}

View File

@@ -0,0 +1,495 @@
<?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 $config;
private $entityManager;
protected $data;
protected $params = null;
private $container;
private $actionManager;
private $zipUtil;
private $fileManager;
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($withEmptyDirs = false)
{
$deleteFileList = $this->getDeleteFileList();
//remove directories, leave only files
foreach ($deleteFileList as $key => $filePath) {
if (!is_file($filePath)) {
unset($deleteFileList[$key]);
}
}
if (!empty($deleteFileList)) {
return $this->getFileManager()->remove($deleteFileList, null, $withEmptyDirs);
}
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, '', true, 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()
{
}
}

View 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;
}
}

View 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);
}
}

View 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(true)) {
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);
}
}

View 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;
}
}

View 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);
}
}

View 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'));
}
}

View File

@@ -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);
}
}

View 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
{
}

View 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;
}
}

View 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
{
}

View File

@@ -23,362 +23,72 @@
namespace Espo\Core\Upgrades;
use Espo\Core\Utils\Util,
Espo\Core\Utils\Json,
Espo\Core\Exceptions\Error;
Espo\Core\Utils\Json,
Espo\Core\Exceptions\Error;
abstract class Base
{
private $container;
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';
const UNINSTALL = 'uninstall';
protected $data;
const DELETE = 'delete';
protected $packagePath = null;
public function __construct($container)
{
$this->container = $container;
protected $packagePostfix = 'z';
$this->actionManager = new ActionManager($this->name, $container, $this->params);
}
protected $scriptNames = array(
'before' => 'Before',
'after' => 'After',
);
protected function getContainer()
{
return $this->container;
}
protected $paths = array(
'files' => 'files',
'scripts' => 'scripts',
);
protected function getActionManager()
{
return $this->actionManager;
}
public function getManifest()
{
return $this->getActionManager()->getManifest();
}
public function __construct($container)
{
$this->container = $container;
public function upload($data)
{
$this->getActionManager()->setAction(self::UPLOAD);
$this->zipUtil = new \Espo\Core\Utils\File\ZipArchive($container->get('fileManager'));
}
return $this->getActionManager()->run($data);
}
public function __destruct()
{
$this->upgradeId = null;
$this->data = null;
}
public function install($processId)
{
$this->getActionManager()->setAction(self::INSTALL);
protected function getContainer()
{
return $this->container;
}
return $this->getActionManager()->run($processId);
}
protected function getZipUtil()
{
return $this->zipUtil;
}
public function uninstall($processId)
{
$this->getActionManager()->setAction(self::UNINSTALL);
protected function getFileManager()
{
if (!isset($this->fileManager)) {
$this->fileManager = $this->getContainer()->get('fileManager');
}
return $this->fileManager;
}
return $this->getActionManager()->run($processId);
}
protected function getConfig()
{
if (!isset($this->config)) {
$this->config = $this->getContainer()->get('config');
}
return $this->config;
}
public function delete($processId)
{
$this->getActionManager()->setAction(self::DELETE);
/**
* 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);
}
public function getManifest()
{
if (!isset($this->data['manifest'])) {
$upgradePath = $this->getUpgradePath();
$manifestJson = $this->getFileManager()->getContents(array($upgradePath, $this->manifestName));
$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'];
}
/**
* Check if the manifest is correct
*
* @param array $manifest
* @return boolean
*/
protected function checkManifest(array $manifest)
{
$requiredFields = array(
'name',
'version',
'acceptableVersions',
);
foreach ($requiredFields as $fieldName) {
if (empty($manifest[$fieldName])) {
return false;
}
}
return true;
}
/**
* Delete temporary package files
*
* @return boolean
*/
protected function deletePackageFiles()
{
$upgradePath = $this->getUpgradePath();
$upgradePackagePath = $this->getUpgradePath(true);
$res = $this->getFileManager()->removeInDir($upgradePath, true);
$res &= $this->getFileManager()->removeFile($upgradePackagePath);
return $res;
}
protected function systemRebuild()
{
$manifest = $this->getManifest();
$res = $this->getConfig()->set('version', $manifest['version']);
$res &= $this->getContainer()->get('dataManager')->rebuild();
return $res;
}
}
return $this->getActionManager()->run($processId);
}
}

View File

@@ -26,108 +26,108 @@ use \Espo\Core\Utils\Api\Slim;
class Auth extends \Slim\Middleware
{
protected $auth;
protected $auth;
protected $authRequired = null;
protected $authRequired = null;
protected $showDialog = false;
protected $showDialog = false;
public function __construct(\Espo\Core\Utils\Auth $auth, $authRequired = null, $showDialog = false)
{
$this->auth = $auth;
$this->authRequired = $authRequired;
$this->showDialog = $showDialog;
}
public function __construct(\Espo\Core\Utils\Auth $auth, $authRequired = null, $showDialog = false)
{
$this->auth = $auth;
$this->authRequired = $authRequired;
$this->showDialog = $showDialog;
}
function call()
{
$req = $this->app->request();
function call()
{
$req = $this->app->request();
$uri = $req->getResourceUri();
$httpMethod = $req->getMethod();
$uri = $req->getResourceUri();
$httpMethod = $req->getMethod();
$authUsername = $req->headers('PHP_AUTH_USER');
$authPassword = $req->headers('PHP_AUTH_PW');
$authUsername = $req->headers('PHP_AUTH_USER');
$authPassword = $req->headers('PHP_AUTH_PW');
$espoAuth = $req->headers('HTTP_ESPO_AUTHORIZATION');
if (isset($espoAuth)) {
list($authUsername, $authPassword) = explode(':', base64_decode($espoAuth));
}
$espoAuth = $req->headers('HTTP_ESPO_AUTHORIZATION');
if (isset($espoAuth)) {
list($authUsername, $authPassword) = explode(':', base64_decode($espoAuth));
}
$espoCgiAuth = $req->headers('HTTP_ESPO_CGI_AUTH');
if ( !isset($authUsername) && !isset($authPassword) && isset($espoCgiAuth) ) {
list($authUsername, $authPassword) = explode(':' , base64_decode(substr($espoCgiAuth, 6)));
}
$espoCgiAuth = $req->headers('HTTP_ESPO_CGI_AUTH');
if ( !isset($authUsername) && !isset($authPassword) && isset($espoCgiAuth) ) {
list($authUsername, $authPassword) = explode(':' , base64_decode(substr($espoCgiAuth, 6)));
}
if (is_null($this->authRequired)) {
$routes = $this->app->router()->getMatchedRoutes($httpMethod, $uri);
if (is_null($this->authRequired)) {
$routes = $this->app->router()->getMatchedRoutes($httpMethod, $uri);
if (!empty($routes[0])) {
$routeConditions = $routes[0]->getConditions();
if (isset($routeConditions['auth']) && $routeConditions['auth'] === false) {
if (!empty($routes[0])) {
$routeConditions = $routes[0]->getConditions();
if (isset($routeConditions['auth']) && $routeConditions['auth'] === false) {
if ($authUsername && $authPassword) {
$isAuthenticated = $this->auth->login($authUsername, $authPassword);
if ($isAuthenticated) {
$this->next->call();
return;
}
}
if ($authUsername && $authPassword) {
$isAuthenticated = $this->auth->login($authUsername, $authPassword);
if ($isAuthenticated) {
$this->next->call();
return;
}
}
$this->auth->useNoAuth();
$this->next->call();
return;
}
}
} else {
if (!$this->authRequired) {
$this->auth->useNoAuth();
$this->next->call();
return;
}
}
$this->auth->useNoAuth();
$this->next->call();
return;
}
}
} else {
if (!$this->authRequired) {
$this->auth->useNoAuth();
$this->next->call();
return;
}
}
if ($authUsername && $authPassword) {
if ($authUsername && $authPassword) {
$isAuthenticated = $this->auth->login($authUsername, $authPassword);
$isAuthenticated = $this->auth->login($authUsername, $authPassword);
if ($isAuthenticated) {
$this->next->call();
} else {
$this->processUnauthorized();
}
} else {
if (!$this->isXMLHttpRequest()) {
$this->showDialog = true;
}
$this->processUnauthorized();
}
}
if ($isAuthenticated) {
$this->next->call();
} else {
$this->processUnauthorized();
}
} else {
if (!$this->isXMLHttpRequest()) {
$this->showDialog = true;
}
$this->processUnauthorized();
}
}
protected function processUnauthorized()
{
$res = $this->app->response();
protected function processUnauthorized()
{
$res = $this->app->response();
if ($this->showDialog) {
$res->header('WWW-Authenticate', 'Basic realm=""');
} else {
$res->header('WWW-Authenticate');
}
$res->status(401);
}
if ($this->showDialog) {
$res->header('WWW-Authenticate', 'Basic realm=""');
} else {
$res->header('WWW-Authenticate');
}
$res->status(401);
}
protected function isXMLHttpRequest()
{
$req = $this->app->request();
protected function isXMLHttpRequest()
{
$req = $this->app->request();
$httpXRequestedWith = $req->headers('HTTP_X_REQUESTED_WITH');
$httpXRequestedWith = $req->headers('HTTP_X_REQUESTED_WITH');
if (isset($httpXRequestedWith) && strtolower($httpXRequestedWith) == 'xmlhttprequest') {
return true;
}
if (isset($httpXRequestedWith) && strtolower($httpXRequestedWith) == 'xmlhttprequest') {
return true;
}
return false;
}
return false;
}
}

View File

@@ -24,94 +24,94 @@ namespace Espo\Core\Utils\Api;
class Output
{
private $slim;
private $slim;
protected $errorDesc = array(
400 => 'Bad Request',
401 => 'Unauthorized',
403 => 'Forbidden',
404 => 'Page Not Found',
409 => 'Conflict',
500 => 'Internal Server Error',
);
protected $errorDesc = array(
400 => 'Bad Request',
401 => 'Unauthorized',
403 => 'Forbidden',
404 => 'Page Not Found',
409 => 'Conflict',
500 => 'Internal Server Error',
);
public function __construct(\Espo\Core\Utils\Api\Slim $slim)
{
$this->slim = $slim;
}
public function __construct(\Espo\Core\Utils\Api\Slim $slim)
{
$this->slim = $slim;
}
protected function getSlim()
{
return $this->slim;
}
protected function getSlim()
{
return $this->slim;
}
/**
* Output the result
*
* @param mixed $data - JSON
*/
public function render($data = null)
{
if (is_array($data)) {
$dataArr = array_values($data);
$data = empty($dataArr[0]) ? false : $dataArr[0];
}
/**
* Output the result
*
* @param mixed $data - JSON
*/
public function render($data = null)
{
if (is_array($data)) {
$dataArr = array_values($data);
$data = empty($dataArr[0]) ? false : $dataArr[0];
}
ob_clean();
echo $data;
}
ob_clean();
echo $data;
}
public function processError($message = 'Error', $code = 500, $isPrint = false)
{
$GLOBALS['log']->error('API ['.$this->getSlim()->request()->getMethod().']:'.$this->getSlim()->router()->getCurrentRoute()->getPattern().', Params:'.print_r($this->getSlim()->router()->getCurrentRoute()->getParams(), true).', InputData: '.$this->getSlim()->request()->getBody().' - '.$message);
$this->displayError($message, $code, $isPrint);
}
public function processError($message = 'Error', $code = 500, $isPrint = false)
{
$GLOBALS['log']->error('API ['.$this->getSlim()->request()->getMethod().']:'.$this->getSlim()->router()->getCurrentRoute()->getPattern().', Params:'.print_r($this->getSlim()->router()->getCurrentRoute()->getParams(), true).', InputData: '.$this->getSlim()->request()->getBody().' - '.$message);
$this->displayError($message, $code, $isPrint);
}
/**
* Output the error and stop app execution
*
* @param string $text
* @param int $statusCode
*
* @return void
*/
public function displayError($text, $statusCode = 500, $isPrint = false)
{
$GLOBALS['log']->error('Display Error: '.$text.', Code: '.$statusCode.' URL: '.$_SERVER['REQUEST_URI']);
/**
* Output the error and stop app execution
*
* @param string $text
* @param int $statusCode
*
* @return void
*/
public function displayError($text, $statusCode = 500, $isPrint = false)
{
$GLOBALS['log']->error('Display Error: '.$text.', Code: '.$statusCode.' URL: '.$_SERVER['REQUEST_URI']);
if (!empty( $this->slim)) {
$this->getSlim()->response()->status($statusCode);
$this->getSlim()->response()->header('X-Status-Reason', $text);
if (!empty( $this->slim)) {
$this->getSlim()->response()->status($statusCode);
$this->getSlim()->response()->header('X-Status-Reason', $text);
if ($isPrint) {
$status = $this->getCodeDesc($statusCode);
$status = isset($status) ? $statusCode.' '.$status : 'HTTP '.$statusCode;
$this->getSlim()->printError($text, $status);
}
if ($isPrint) {
$status = $this->getCodeDesc($statusCode);
$status = isset($status) ? $statusCode.' '.$status : 'HTTP '.$statusCode;
$this->getSlim()->printError($text, $status);
}
$this->getSlim()->stop();
}
else {
$GLOBALS['log']->info('Could not get Slim instance. It looks like a direct call (bypass API). URL: '.$_SERVER['REQUEST_URI']);
die($text);
}
}
$this->getSlim()->stop();
}
else {
$GLOBALS['log']->info('Could not get Slim instance. It looks like a direct call (bypass API). URL: '.$_SERVER['REQUEST_URI']);
die($text);
}
}
/**
* Get status code desription
*
* @param int $statusCode
* @return string | null
*/
protected function getCodeDesc($statusCode)
{
if (isset($this->errorDesc[$statusCode])) {
return $this->errorDesc[$statusCode];
}
/**
* Get status code desription
*
* @param int $statusCode
* @return string | null
*/
protected function getCodeDesc($statusCode)
{
if (isset($this->errorDesc[$statusCode])) {
return $this->errorDesc[$statusCode];
}
return null;
}
return null;
}

View File

@@ -26,60 +26,60 @@ namespace Espo\Core\Utils\Api;
class Slim extends \Slim\Slim
{
/**
* Redefine the run method
*
* We no need to use a Slim handler
*/
public function run()
{
//set_error_handler(array('\Slim\Slim', 'handleErrors')); //Espo: no needs to use this handler
/**
* Redefine the run method
*
* We no need to use a Slim handler
*/
public function run()
{
//set_error_handler(array('\Slim\Slim', 'handleErrors')); //Espo: no needs to use this handler
//Apply final outer middleware layers
if ($this->config('debug')) {
//Apply pretty exceptions only in debug to avoid accidental information leakage in production
//$this->add(new \Slim\Middleware\PrettyExceptions()); //Espo: no needs to use this handler
}
//Apply final outer middleware layers
if ($this->config('debug')) {
//Apply pretty exceptions only in debug to avoid accidental information leakage in production
//$this->add(new \Slim\Middleware\PrettyExceptions()); //Espo: no needs to use this handler
}
//Invoke middleware and application stack
$this->middleware[0]->call();
//Invoke middleware and application stack
$this->middleware[0]->call();
//Fetch status, header, and body
list($status, $headers, $body) = $this->response->finalize();
//Fetch status, header, and body
list($status, $headers, $body) = $this->response->finalize();
// Serialize cookies (with optional encryption)
\Slim\Http\Util::serializeCookies($headers, $this->response->cookies, $this->settings);
// Serialize cookies (with optional encryption)
\Slim\Http\Util::serializeCookies($headers, $this->response->cookies, $this->settings);
//Send headers
if (headers_sent() === false) {
//Send status
if (strpos(PHP_SAPI, 'cgi') === 0) {
header(sprintf('Status: %s', \Slim\Http\Response::getMessageForCode($status)));
} else {
header(sprintf('HTTP/%s %s', $this->config('http.version'), \Slim\Http\Response::getMessageForCode($status)));
}
//Send headers
if (headers_sent() === false) {
//Send status
if (strpos(PHP_SAPI, 'cgi') === 0) {
header(sprintf('Status: %s', \Slim\Http\Response::getMessageForCode($status)));
} else {
header(sprintf('HTTP/%s %s', $this->config('http.version'), \Slim\Http\Response::getMessageForCode($status)));
}
//Send headers
foreach ($headers as $name => $value) {
$hValues = explode("\n", $value);
foreach ($hValues as $hVal) {
header("$name: $hVal", false);
}
}
}
//Send headers
foreach ($headers as $name => $value) {
$hValues = explode("\n", $value);
foreach ($hValues as $hVal) {
header("$name: $hVal", false);
}
}
}
//Send body, but only if it isn't a HEAD request
if (!$this->request->isHead()) {
echo $body;
}
//Send body, but only if it isn't a HEAD request
if (!$this->request->isHead()) {
echo $body;
}
//restore_error_handler(); //Espo: no needs to use this handler
}
//restore_error_handler(); //Espo: no needs to use this handler
}
public function printError($error, $status)
{
echo static::generateTemplateMarkup($status, '<p>'.$error.'</p><a href="' . $this->request->getRootUri() . '/">Visit the Home Page</a>');
}
public function printError($error, $status)
{
echo static::generateTemplateMarkup($status, '<p>'.$error.'</p><a href="' . $this->request->getRootUri() . '/">Visit the Home Page</a>');
}
}

View File

@@ -18,92 +18,96 @@
*
* 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;
use \Espo\Core\Exceptions\Error;
class Auth
class Auth
{
protected $container;
public function __construct(\Espo\Core\Container $container)
{
$this->container = $container;
}
public function useNoAuth($isAdmin = false)
{
$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');
}
protected $container;
$entityManager->setUser($user);
$this->container->setUser($user);
}
public function login($username, $password)
{
$GLOBALS['log']->debug('AUTH: Try to authenticate');
$hash = md5($password);
$entityManager = $this->container->get('entityManager');
$authToken = $entityManager->getRepository('AuthToken')->where(array('token' => $password))->findOne();
if ($authToken) {
$hash = $authToken->get('hash');
}
$user = $entityManager->getRepository('User')->findOne(array(
'whereClause' => array(
'userName' => $username,
'password' => $hash
),
));
if ($user) {
$entityManager->setUser($user);
$this->container->setUser($user);
$GLOBALS['log']->debug('AUTH: Result of authenticate is [true]');
if (!$authToken) {
$authToken = $entityManager->getEntity('AuthToken');
$token = $this->createToken($user);
$authToken->set('token', $token);
$authToken->set('hash', $user->get('password'));
$authToken->set('ipAddress', $_SERVER['REMOTE_ADDR']);
$authToken->set('userId', $user->id);
}
$authToken->set('lastAccess', date('Y-m-d H:i:s'));
$entityManager->saveEntity($authToken);
$user->set('token', $authToken->get('token'));
return true;
}
}
protected function createToken($user)
{
return md5(uniqid($user->get('password')));
}
public function destroyAuthToken($token)
{
$entityManager = $this->container->get('entityManager');
$authToken = $entityManager->getRepository('AuthToken')->where(array('token' => $token))->findOne();
if ($authToken) {
$entityManager->removeEntity($authToken);
return true;
}
}
protected $authentication;
protected $config;
protected $entityManager;
public function __construct(\Espo\Core\Container $container)
{
$this->container = $container;
$this->entityManager = $this->container->get('entityManager');
$this->config = $this->container->get('config');
$authenticationMethod = $this->config->get('authenticationMethod', 'Espo');
$authenticationClassName = "\\Espo\\Core\\Utils\\Authentication\\" . $authenticationMethod;
$this->authentication = new $authenticationClassName($this->config, $this->entityManager, $this);
}
public function useNoAuth($isAdmin = false)
{
$entityManager = $this->container->get('entityManager');
$user = $entityManager->getRepository('User')->get('system');
if (!$user) {
throw new Error('System user is not found');
}
$user->set('isAdmin', $isAdmin);
$entityManager->setUser($user);
$this->container->setUser($user);
}
public function login($username, $password)
{
$GLOBALS['log']->debug('AUTH: Try to authenticate');
$entityManager = $this->entityManager;
$authToken = $entityManager->getRepository('AuthToken')->where(array('token' => $password))->findOne();
$user = $this->authentication->login($username, $password, $authToken);
if ($user) {
$entityManager->setUser($user);
$this->container->setUser($user);
$GLOBALS['log']->debug('AUTH: Result of authenticate is [true]');
if (!$authToken) {
$authToken = $entityManager->getEntity('AuthToken');
$token = $this->createToken($user);
$authToken->set('token', $token);
$authToken->set('hash', $user->get('password'));
$authToken->set('ipAddress', $_SERVER['REMOTE_ADDR']);
$authToken->set('userId', $user->id);
}
$authToken->set('lastAccess', date('Y-m-d H:i:s'));
$entityManager->saveEntity($authToken);
$user->set('token', $authToken->get('token'));
return true;
}
}
protected function createToken($user)
{
return md5(uniqid($user->get('id')));
}
public function destroyAuthToken($token)
{
$entityManager = $this->container->get('entityManager');
$authToken = $entityManager->getRepository('AuthToken')->where(array('token' => $token))->findOne();
if ($authToken) {
$entityManager->removeEntity($authToken);
return true;
}
}
}

View File

@@ -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\Utils\Authentication;
use \Espo\Core\Utils\Config;
use \Espo\Core\ORM\EntityManager;
use \Espo\Core\Utils\Auth;
abstract class Base
{
private $config;
private $entityManager;
private $auth;
private $passwordHash;
public function __construct(Config $config, EntityManager $entityManager, Auth $auth)
{
$this->config = $config;
$this->entityManager = $entityManager;
$this->auth = $auth;
}
protected function getConfig()
{
return $this->config;
}
protected function getEntityManager()
{
return $this->entityManager;
}
protected function getAuth()
{
return $this->auth;
}
protected function getPasswordHash()
{
if (!isset($this->passwordHash)) {
$this->passwordHash = new \Espo\Core\Utils\PasswordHash($this->config);
}
return $this->passwordHash;
}
}

View File

@@ -0,0 +1,47 @@
<?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\Authentication;
use \Espo\Core\Exceptions\Error;
class Espo extends Base
{
public function login($username, $password, \Espo\Entities\AuthToken $authToken = null)
{
if ($authToken) {
$hash = $authToken->get('hash');
} else {
$hash = $this->getPasswordHash()->hash($password);
}
$user = $this->getEntityManager()->getRepository('User')->findOne(array(
'whereClause' => array(
'userName' => $username,
'password' => $hash
),
));
return $user;
}
}

View File

@@ -0,0 +1,201 @@
<?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\Authentication;
use Espo\Core\Exceptions\Error,
Espo\Core\Utils\Config,
Espo\Core\ORM\EntityManager,
Espo\Core\Utils\Auth;
class LDAP extends Base
{
private $utils;
private $zendLdap;
/**
* Espo => LDAP name
*
* @var array
*/
private $fields = array(
'userName' => 'cn',
'firstName' => 'givenname',
'lastName' => 'sn',
'title' => 'title',
'emailAddress' => 'mail',
'phoneNumber' => 'telephonenumber',
);
public function __construct(Config $config, EntityManager $entityManager, Auth $auth)
{
parent::__construct($config, $entityManager, $auth);
$this->zendLdap = new LDAP\LDAP();
$this->utils = new LDAP\Utils($config);
}
protected function getZendLdap()
{
return $this->zendLdap;
}
protected function getUtils()
{
return $this->utils;
}
/**
* LDAP login
*
* @param string $username
* @param string $password
* @param \Espo\Entities\AuthToken $authToken
* @return \Espo\Entities\User | null
*/
public function login($username, $password, \Espo\Entities\AuthToken $authToken = null)
{
if ($authToken) {
return $this->loginByToken($username, $authToken);
}
$options = $this->getUtils()->getZendOptions();
$ldap = $this->getZendLdap();
$ldap = $ldap->setOptions($options);
try {
$ldap->bind($username, $password);
$dn = $ldap->getDn($username);
$loginFilter = $this->getUtils()->getOption('userLoginFilter');
$userData = $ldap->searchByLoginFilter($loginFilter, $dn, 3);
} catch (\Zend\Ldap\Exception\LdapException $zle) {
$admin = $this->adminLogin($username, $password);
if (!isset($admin)) {
$GLOBALS['log']->info('LDAP Authentication: ' . $zle->getMessage());
return null;
}
$GLOBALS['log']->info('LDAP Authentication: Administrator login by username ['.$username.']');
}
$user = $this->getEntityManager()->getRepository('User')->findOne(array(
'whereClause' => array(
'userName' => $username,
),
));
$isCreateUser = $this->getUtils()->getOption('createEspoUser');
if (!isset($user) && $isCreateUser) {
$this->getAuth()->useNoAuth(); /** Required to fix Acl "isFetched()" error */
$user = $this->createUser($userData);
}
return $user;
}
/**
* Login by authorization token
*
* @param string $username
* @param \Espo\Entities\AuthToken $authToken
* @return \Espo\Entities\User | null
*/
protected function loginByToken($username, \Espo\Entities\AuthToken $authToken = null)
{
if (!isset($authToken)) {
return null;
}
$userId = $authToken->get('userId');
$user = $this->getEntityManager()->getEntity('User', $userId);
$tokenUsername = $user->get('userName');
if ($username != $tokenUsername) {
$GLOBALS['log']->alert('Unauthorized access attempt for user ['.$username.'] from IP ['.$_SERVER['REMOTE_ADDR'].']');
return null;
}
$user = $this->getEntityManager()->getRepository('User')->findOne(array(
'whereClause' => array(
'userName' => $username,
),
));
return $user;
}
/**
* Login user with administrator rights
*
* @param string $username
* @param string $password
* @return \Espo\Entities\User | null
*/
protected function adminLogin($username, $password)
{
$hash = $this->getPasswordHash()->hash($password);
$user = $this->getEntityManager()->getRepository('User')->findOne(array(
'whereClause' => array(
'userName' => $username,
'password' => $hash,
'isAdmin' => 1
),
));
return $user;
}
/**
* Create Espo user with data gets from LDAP server
*
* @param array $userData LDAP entity data
* @return \Espo\Entities\User
*/
protected function createUser(array $userData)
{
$data = array();
foreach ($this->fields as $espo => $ldap) {
if (isset($userData[$ldap][0])) {
$data[$espo] = $userData[$ldap][0];
}
}
$user = $this->getEntityManager()->getEntity('User');
$user->set($data);
$this->getEntityManager()->saveEntity($user);
return $user;
}
}

View File

@@ -0,0 +1,123 @@
<?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\Authentication\LDAP;
class LDAP extends \Zend\Ldap\Ldap
{
protected $usernameAttribute = 'cn';
/**
* Get DN depends on options, ex. "cn=test,ou=People,dc=maxcrc,dc=com"
*
* @return string DN format
*/
public function getDn($acctname)
{
return $this->getAccountDn($acctname, \Zend\Ldap\Ldap::ACCTNAME_FORM_DN);
}
/**
* Fix a bug, ex. CN=Alice Baker,CN=Users,DC=example,DC=com
*
* @param string $acctname
* @return string - Account DN
*/
protected function getAccountDn($acctname)
{
$baseDn = $this->getBaseDn();
if ($this->getBindRequiresDn() && isset($baseDn)) {
try {
return parent::getAccountDn($acctname);
} catch (\Zend\Ldap\Exception\LdapException $zle) {
if ($zle->getCode() != \Zend\Ldap\Exception\LdapException::LDAP_NO_SUCH_OBJECT) {
throw $zle;
}
}
$acctname = $this->usernameAttribute . '=' . \Zend\Ldap\Filter\AbstractFilter::escapeValue($acctname) . ',' . $baseDn;
}
return parent::getAccountDn($acctname);
}
/**
* Search a user using userLoginFilter
*
* @param string $filter
* @param string $basedn
* @param int $scope
* @param array $attributes
* @return array
*/
public function searchByLoginFilter($filter, $basedn = null, $scope = self::SEARCH_SCOPE_SUB, array $attributes = array())
{
$filter = $this->getLoginFilter($filter);
$result = $this->search($filter, $basedn, $scope, $attributes);
if ($result->count() > 0) {
return $result->getFirst();
}
throw new \Zend\Ldap\Exception\LdapException($this, 'searching: ' . $filter);
}
/**
* Get login filter in LDAP format
*
* @param string $filter
* @return string
*/
protected function getLoginFilter($filter)
{
$baseFilter = '(objectClass=*)';
if (!empty($filter)) {
$baseFilter = '(&' . $baseFilter . $this->convertToFilterFormat($filter). ')';
}
return $baseFilter;
}
/**
* Check and convert filter item in LDAP format
*
* @param string $filter [description]
* @return string
*/
protected function convertToFilterFormat($filter)
{
$filter = trim($filter);
if (substr($filter, 0, 1) != '(') {
$filter = '(' . $filter;
}
if (substr($filter, -1) != ')') {
$filter = $filter . ')';
}
return $filter;
}
}

Some files were not shown because too many files have changed in this diff Show More