mirror of
https://github.com/espocrm/espocrm.git
synced 2026-03-03 16:27:02 +00:00
Compare commits
586 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9595d528a8 | ||
|
|
9bfb27e10a | ||
|
|
be50630d2f | ||
|
|
d8b629a5a0 | ||
|
|
6d0b39f2b6 | ||
|
|
b778f74628 | ||
|
|
6db658c0b3 | ||
|
|
6fb88665bb | ||
|
|
f20a47542a | ||
|
|
c77e3b7e92 | ||
|
|
e7b033304c | ||
|
|
2b8a8d23eb | ||
|
|
0f59f79a9e | ||
|
|
2904cd1f53 | ||
|
|
d87ae60fea | ||
|
|
0d17cf6e78 | ||
|
|
81739d59f5 | ||
|
|
7704d5afd0 | ||
|
|
da268f2b29 | ||
|
|
01dc251ef2 | ||
|
|
9054d70f4c | ||
|
|
788b265cd4 | ||
|
|
c96640bcb1 | ||
|
|
66fb7b4e81 | ||
|
|
d83a19e316 | ||
|
|
452e39903e | ||
|
|
797fcc172c | ||
|
|
cdb7c919b3 | ||
|
|
0f7f438935 | ||
|
|
7c01eedda8 | ||
|
|
bab7f3e9fc | ||
|
|
761d85a112 | ||
|
|
52e323123a | ||
|
|
01af1677cf | ||
|
|
d4f4fcb10e | ||
|
|
74fd228bfb | ||
|
|
f452d2e5d2 | ||
|
|
3a01348e02 | ||
|
|
b1743ee4a2 | ||
|
|
ab14769387 | ||
|
|
5c800601e4 | ||
|
|
8aea81340b | ||
|
|
8513911f21 | ||
|
|
6a46c453cd | ||
|
|
2029dc5e10 | ||
|
|
70664d1a7a | ||
|
|
7d212ec62f | ||
|
|
fa7b145e07 | ||
|
|
830645cb73 | ||
|
|
94e03b3c18 | ||
|
|
3ace85eebc | ||
|
|
c6cfdd9e90 | ||
|
|
d1b2dfae3e | ||
|
|
98fb345a5a | ||
|
|
481314886f | ||
|
|
ad90cd171a | ||
|
|
8272e0e652 | ||
|
|
f218de2e04 | ||
|
|
53529fc506 | ||
|
|
aef99fb4fd | ||
|
|
86f690c79f | ||
|
|
71f9e90436 | ||
|
|
75608f41b1 | ||
|
|
0730ae5b3f | ||
|
|
a7f537879e | ||
|
|
6066cf1d65 | ||
|
|
ccda236b6e | ||
|
|
32ec348369 | ||
|
|
d85f66171d | ||
|
|
8c6aa46ec8 | ||
|
|
d2f7bc475a | ||
|
|
410cf02518 | ||
|
|
958414017e | ||
|
|
8fbfad9637 | ||
|
|
07e8f94748 | ||
|
|
4db162f9f7 | ||
|
|
459dfb7937 | ||
|
|
56b0536152 | ||
|
|
5bb7dd3ccd | ||
|
|
6e50e4fd8e | ||
|
|
878e1616da | ||
|
|
64a410099e | ||
|
|
9cb8664ddf | ||
|
|
6d5c3c8ad5 | ||
|
|
f07c8fca64 | ||
|
|
944c76ad93 | ||
|
|
ae8f9df02b | ||
|
|
6da3659b7d | ||
|
|
1f1d9f3abd | ||
|
|
530d7f2d81 | ||
|
|
e67ecded2a | ||
|
|
b9343d5e64 | ||
|
|
898393c7ac | ||
|
|
9b2ea5298d | ||
|
|
0d2b56c58f | ||
|
|
076c920dc7 | ||
|
|
638df642ec | ||
|
|
d2f4190612 | ||
|
|
7201f517e8 | ||
|
|
c91365f627 | ||
|
|
f3bc4dbccf | ||
|
|
d4daef6012 | ||
|
|
dbf4f68a44 | ||
|
|
8a7325963b | ||
|
|
fc0d8dffcd | ||
|
|
f8498e3adc | ||
|
|
e4b51ba675 | ||
|
|
83f9ead607 | ||
|
|
bf6778770e | ||
|
|
093b80293a | ||
|
|
34dee314e7 | ||
|
|
313b94168e | ||
|
|
d6085bbdcf | ||
|
|
160dc5d61c | ||
|
|
987b383d7c | ||
|
|
8b4cb1568e | ||
|
|
aef4028180 | ||
|
|
9b779ee8cd | ||
|
|
ccc339cf48 | ||
|
|
6aabbfd944 | ||
|
|
0e87626e34 | ||
|
|
8641181511 | ||
|
|
123c3ef8ab | ||
|
|
07bd5a9d60 | ||
|
|
deca89039a | ||
|
|
1542fa86d8 | ||
|
|
93ca814fe3 | ||
|
|
4d9e5ee302 | ||
|
|
0a697cdc0a | ||
|
|
1b01e476ac | ||
|
|
ee689fb351 | ||
|
|
92a76d80f2 | ||
|
|
a662c1a5fe | ||
|
|
3ffa949276 | ||
|
|
371966e2cf | ||
|
|
8f1a4d2a02 | ||
|
|
3128b6f25a | ||
|
|
0920821f1e | ||
|
|
0f8f9c01ff | ||
|
|
1d9621bc91 | ||
|
|
e138daec5f | ||
|
|
4a51e754d7 | ||
|
|
e6e0bc1703 | ||
|
|
49fbc6e082 | ||
|
|
a0ed610f60 | ||
|
|
9f8c0eb4a2 | ||
|
|
be29fac010 | ||
|
|
b3cefd9bcb | ||
|
|
501d6f2692 | ||
|
|
3d7560024f | ||
|
|
a201b45d04 | ||
|
|
41f88a4015 | ||
|
|
52a131ef93 | ||
|
|
7ab28601ca | ||
|
|
5de509a0de | ||
|
|
2534b14dce | ||
|
|
27f98b95eb | ||
|
|
b08bee78b9 | ||
|
|
a39327a95b | ||
|
|
f979a8dd46 | ||
|
|
ecf1645e05 | ||
|
|
d015bec89c | ||
|
|
92e1d4b8e6 | ||
|
|
a75df456e2 | ||
|
|
5393c2f314 | ||
|
|
c49bcc29db | ||
|
|
3e74fb49ac | ||
|
|
cf885cafb4 | ||
|
|
7a7c605687 | ||
|
|
5676d42801 | ||
|
|
c893a4441d | ||
|
|
c5e1d0847f | ||
|
|
f0b4c2dc79 | ||
|
|
1584f25af5 | ||
|
|
761e7b2344 | ||
|
|
7099c92c39 | ||
|
|
be26ec2651 | ||
|
|
7a2f49ad43 | ||
|
|
22477385f7 | ||
|
|
e7ae0862ba | ||
|
|
f501a7377d | ||
|
|
9ce9ccdb5c | ||
|
|
f8a425b7d1 | ||
|
|
8ab92f8668 | ||
|
|
e598665242 | ||
|
|
1bc984f8fa | ||
|
|
3a0b1a22f0 | ||
|
|
8fd41d5ea7 | ||
|
|
787adc72a5 | ||
|
|
a99b043d95 | ||
|
|
2079c19dc0 | ||
|
|
9f9ba2c915 | ||
|
|
31db584658 | ||
|
|
a09c7db717 | ||
|
|
19bd38bb85 | ||
|
|
7e678a8378 | ||
|
|
93c5d7eb91 | ||
|
|
a9fcf5d510 | ||
|
|
6f1266dcea | ||
|
|
2395fb6986 | ||
|
|
48a0fa5e96 | ||
|
|
95a0f78fa7 | ||
|
|
85f18fe338 | ||
|
|
cbfad8eb79 | ||
|
|
5cd4a92049 | ||
|
|
e5b4de1683 | ||
|
|
cdd07a9f44 | ||
|
|
121eaabe40 | ||
|
|
f559c512fd | ||
|
|
9aa5ed63d0 | ||
|
|
fa9c0e5b3b | ||
|
|
469c6f3b45 | ||
|
|
e23e013432 | ||
|
|
e051ef4935 | ||
|
|
2a4e816448 | ||
|
|
4095530491 | ||
|
|
5a40507b54 | ||
|
|
f438b0898b | ||
|
|
58cfeeb1be | ||
|
|
6dbd521501 | ||
|
|
541cb13ec3 | ||
|
|
e7fbcbbac6 | ||
|
|
7bc3d8a826 | ||
|
|
a814a95c9a | ||
|
|
e95a40f24d | ||
|
|
b5972da08e | ||
|
|
9f488c5539 | ||
|
|
aeea86155c | ||
|
|
843ca2a7c5 | ||
|
|
bbb67856c0 | ||
|
|
1100e82364 | ||
|
|
7dfafaee22 | ||
|
|
cd1aab0b1e | ||
|
|
fa9c2806ca | ||
|
|
736a53c8d0 | ||
|
|
0b713be508 | ||
|
|
715b290174 | ||
|
|
54d241d247 | ||
|
|
bf8f9023e2 | ||
|
|
f57c81efe4 | ||
|
|
6d12cf44b4 | ||
|
|
4e76855a12 | ||
|
|
724b2adbbd | ||
|
|
c95031912a | ||
|
|
4f7c6dacee | ||
|
|
716e434099 | ||
|
|
f1f566d56f | ||
|
|
4cf1b8dbda | ||
|
|
87ce26f3cd | ||
|
|
94c157df7a | ||
|
|
d13ccb8dc7 | ||
|
|
b73d82ba00 | ||
|
|
afdeeeffa7 | ||
|
|
16cd135cb7 | ||
|
|
0c6df91604 | ||
|
|
58a6ced886 | ||
|
|
d0d3f39f5d | ||
|
|
82a96c743c | ||
|
|
a18453c3af | ||
|
|
a75dc61748 | ||
|
|
0a60663548 | ||
|
|
53cac1c299 | ||
|
|
4d624aa6d1 | ||
|
|
ca807c7ec8 | ||
|
|
f245b30d90 | ||
|
|
0cfb29ad6d | ||
|
|
27ed23cb51 | ||
|
|
1794042cea | ||
|
|
6657078a89 | ||
|
|
a156e869fc | ||
|
|
06ffe9d373 | ||
|
|
817fc2fd40 | ||
|
|
2ec4464a52 | ||
|
|
e79874c039 | ||
|
|
72b9d77e44 | ||
|
|
c622b976de | ||
|
|
4e0d570f90 | ||
|
|
ffce8cb0f7 | ||
|
|
6dd2e365ad | ||
|
|
c324729cdf | ||
|
|
5b3eee299c | ||
|
|
2ff6946b91 | ||
|
|
c3a44a413a | ||
|
|
a4050b1476 | ||
|
|
2da6d68fe3 | ||
|
|
ed19b9d328 | ||
|
|
f41e4f2df4 | ||
|
|
410bd7f177 | ||
|
|
caa659020e | ||
|
|
877820f5f5 | ||
|
|
18c6847481 | ||
|
|
274c043f44 | ||
|
|
529d8c1100 | ||
|
|
c05c169948 | ||
|
|
99db3f5416 | ||
|
|
1fa976a43c | ||
|
|
32198144cc | ||
|
|
29420a5306 | ||
|
|
67f6f9b250 | ||
|
|
c2bbc2e61e | ||
|
|
2d74cddf86 | ||
|
|
53049cf1f4 | ||
|
|
6aa012891d | ||
|
|
5a7f3ed101 | ||
|
|
131743e702 | ||
|
|
b5cde9a157 | ||
|
|
b150aad977 | ||
|
|
75d220e74d | ||
|
|
39a3d215d6 | ||
|
|
8fe87ccd04 | ||
|
|
621a2ffbbf | ||
|
|
0f582c59ab | ||
|
|
ce18f41400 | ||
|
|
d780847232 | ||
|
|
c074423f0b | ||
|
|
31cb2fed88 | ||
|
|
225f407545 | ||
|
|
f10dd19446 | ||
|
|
78d5547e08 | ||
|
|
af08f23ca1 | ||
|
|
99d2f14008 | ||
|
|
a90a2b859d | ||
|
|
b0edae1eae | ||
|
|
a5d923c4e3 | ||
|
|
86e118341e | ||
|
|
ed152c9d4c | ||
|
|
8fa805f5eb | ||
|
|
16ce5385f4 | ||
|
|
d1fe581706 | ||
|
|
dc651b5d77 | ||
|
|
be3dabe5a7 | ||
|
|
21326ec3b5 | ||
|
|
8b851463bc | ||
|
|
d4a3eb1026 | ||
|
|
0980120184 | ||
|
|
db275028d1 | ||
|
|
f78004b9d3 | ||
|
|
bac0227675 | ||
|
|
9f84faa776 | ||
|
|
639c52d1d6 | ||
|
|
811db09a1d | ||
|
|
9c61e03542 | ||
|
|
3e4e86bd5a | ||
|
|
5acf253a98 | ||
|
|
84cfcd4352 | ||
|
|
73f3673a11 | ||
|
|
2c18f75152 | ||
|
|
3601ee35bd | ||
|
|
76379f49be | ||
|
|
1f1fc9111f | ||
|
|
334bd55ad6 | ||
|
|
2f9f0964ed | ||
|
|
b5b04f85d0 | ||
|
|
554f5de0af | ||
|
|
5f528c9f6f | ||
|
|
64b98a7a3c | ||
|
|
74c9d5a8e6 | ||
|
|
ff2ca7f18c | ||
|
|
a0203d3310 | ||
|
|
bddd55213f | ||
|
|
fa97c0ede4 | ||
|
|
1dbfe36d1e | ||
|
|
ec898f297a | ||
|
|
67049d2f08 | ||
|
|
a2c7f84907 | ||
|
|
338ba010a2 | ||
|
|
a9737e8352 | ||
|
|
fb8a4b90ca | ||
|
|
6876bd9a6d | ||
|
|
392f107de1 | ||
|
|
17ab2cc717 | ||
|
|
abddb6c686 | ||
|
|
0a5ec4b81c | ||
|
|
ddba654f00 | ||
|
|
27a5833b36 | ||
|
|
c4cc29b452 | ||
|
|
ac56846e1b | ||
|
|
efb7592782 | ||
|
|
6c40c5a20c | ||
|
|
724c79d089 | ||
|
|
7148cb232b | ||
|
|
9943d1794b | ||
|
|
972615c8e6 | ||
|
|
213546b83f | ||
|
|
e23345edc6 | ||
|
|
7af38e8d21 | ||
|
|
b1e62ecb20 | ||
|
|
f05e3924ff | ||
|
|
2ccb9c3a17 | ||
|
|
c64d27f413 | ||
|
|
2a3711d0b4 | ||
|
|
2baace4ef9 | ||
|
|
aa501a4429 | ||
|
|
3095f61011 | ||
|
|
001de70fe8 | ||
|
|
58733450d1 | ||
|
|
0605672c32 | ||
|
|
0c570b0d83 | ||
|
|
0833428b71 | ||
|
|
4c4714a846 | ||
|
|
155cd428f6 | ||
|
|
06bde4f1ce | ||
|
|
6112a9d02d | ||
|
|
a3f4beac61 | ||
|
|
b116821731 | ||
|
|
3439267926 | ||
|
|
1ac55737b4 | ||
|
|
c66cfeb297 | ||
|
|
85f9fe6f3b | ||
|
|
fe9154fde7 | ||
|
|
bdc7bbada4 | ||
|
|
9f4a203abe | ||
|
|
a89872b785 | ||
|
|
b6bc0471b8 | ||
|
|
c38544e6ad | ||
|
|
6122edb091 | ||
|
|
684441040c | ||
|
|
55c733b13a | ||
|
|
dc7571d30c | ||
|
|
699c1d1f23 | ||
|
|
f67fbbd621 | ||
|
|
dbcc7e61c1 | ||
|
|
afd0f5a5ef | ||
|
|
859f1f0cd9 | ||
|
|
3f8ccb69fc | ||
|
|
ba65ccffe4 | ||
|
|
533fff4d30 | ||
|
|
7b0b3d05ad | ||
|
|
e09c101f82 | ||
|
|
c87c657b02 | ||
|
|
4e6b300477 | ||
|
|
7453eb583a | ||
|
|
b5d2eb93aa | ||
|
|
b5b8ab4a8e | ||
|
|
b6010a7ad7 | ||
|
|
ebdb649bd7 | ||
|
|
ec17306992 | ||
|
|
9b6bf4171b | ||
|
|
252b5ef729 | ||
|
|
220d4d1b77 | ||
|
|
2f8e1aeaf2 | ||
|
|
ced41021f0 | ||
|
|
36e3cc4688 | ||
|
|
20db3b0bd2 | ||
|
|
0ab702726d | ||
|
|
6d796c0b20 | ||
|
|
100fec9409 | ||
|
|
0b5beeba85 | ||
|
|
dec5ab6a16 | ||
|
|
909d31b9fe | ||
|
|
d9522cf555 | ||
|
|
e42a877bf6 | ||
|
|
68cbadda4c | ||
|
|
8beeb64cbf | ||
|
|
da3a18e766 | ||
|
|
ffb94b960d | ||
|
|
f73ac0779b | ||
|
|
8003af682e | ||
|
|
cbf7bf18f2 | ||
|
|
ceaa0a8322 | ||
|
|
8ca410d994 | ||
|
|
5fc7f2509d | ||
|
|
f2e1ba3780 | ||
|
|
93ac871640 | ||
|
|
187a8a02a1 | ||
|
|
bcf5686eec | ||
|
|
027507b61e | ||
|
|
49b3d17952 | ||
|
|
e0958cfeec | ||
|
|
00e12b50b7 | ||
|
|
44b8b00106 | ||
|
|
e0855e3092 | ||
|
|
cb0d70430a | ||
|
|
042575ce6b | ||
|
|
5cd18b57d2 | ||
|
|
d1e46e3d9a | ||
|
|
1a3348f2c2 | ||
|
|
75edc5c165 | ||
|
|
60184ebbbe | ||
|
|
ddb6cb7483 | ||
|
|
2ddd44a2fe | ||
|
|
ce55866445 | ||
|
|
2bc7f85a58 | ||
|
|
a27df2c41f | ||
|
|
170581dd28 | ||
|
|
00b0c904ae | ||
|
|
fdab17265f | ||
|
|
96d0a7db00 | ||
|
|
2835928ac0 | ||
|
|
4c22b42b99 | ||
|
|
64ddaa40a8 | ||
|
|
bc7006e193 | ||
|
|
1ae0a9df28 | ||
|
|
a4f9280eba | ||
|
|
2528fc34c8 | ||
|
|
979f07bf9b | ||
|
|
52bff4de1c | ||
|
|
4c017361f8 | ||
|
|
84aa1339d9 | ||
|
|
987cd4a121 | ||
|
|
e50ad5106f | ||
|
|
071cbcb0fb | ||
|
|
43f1cb9af9 | ||
|
|
220c55e9b4 | ||
|
|
927610efb0 | ||
|
|
78fcaf1fa3 | ||
|
|
3bd9af031d | ||
|
|
16ee3d68e8 | ||
|
|
d49ee3c187 | ||
|
|
2e544f1ccf | ||
|
|
1c51125e66 | ||
|
|
1ed47f5d0d | ||
|
|
133fa0cb36 | ||
|
|
295904bf4c | ||
|
|
951230f7e1 | ||
|
|
ee58886206 | ||
|
|
41575f6f13 | ||
|
|
18ae33d417 | ||
|
|
36daf5a762 | ||
|
|
8a41a2cd05 | ||
|
|
61497d2a01 | ||
|
|
a3045a88f3 | ||
|
|
fd072520a9 | ||
|
|
6ef9d8428f | ||
|
|
33a7176165 | ||
|
|
044de7d744 | ||
|
|
801ba05cd8 | ||
|
|
0dc5a4e4f3 | ||
|
|
230ed63e67 | ||
|
|
7316866a1a | ||
|
|
c7be54d9c9 | ||
|
|
dcc118ec5d | ||
|
|
84e98054b7 | ||
|
|
f37308f5a5 | ||
|
|
9688b3be3c | ||
|
|
6490a1ca97 | ||
|
|
c15fc89f52 | ||
|
|
9207030ccb | ||
|
|
018eb44de6 | ||
|
|
bc92b96a6b | ||
|
|
ee57c9223c | ||
|
|
f799ffc61f | ||
|
|
bdb1f2f3b6 | ||
|
|
fd755df67b | ||
|
|
e9edd01d08 | ||
|
|
dea7e0b33e | ||
|
|
25b50baa1a | ||
|
|
8a53657b9c | ||
|
|
c6ecbf4942 | ||
|
|
56d11807a1 | ||
|
|
cf3b4b284a | ||
|
|
953a59cb57 | ||
|
|
f60061a387 | ||
|
|
c627d84273 | ||
|
|
5a16ee0493 | ||
|
|
14252d6e9e | ||
|
|
c0de3e1c4e | ||
|
|
8b4070f9ae | ||
|
|
f4ef5fc36f | ||
|
|
b1e184c6d1 | ||
|
|
fbf665fd76 | ||
|
|
4b98ea79e0 | ||
|
|
2e916a2ba8 | ||
|
|
26a4d1c6ff | ||
|
|
33fef4c90e | ||
|
|
2dc15294fc | ||
|
|
9b846b45bc | ||
|
|
bc65975f74 | ||
|
|
a5308831f2 | ||
|
|
83f0a81eb7 | ||
|
|
9e28d4a261 | ||
|
|
a9b3320302 | ||
|
|
884ccb5265 | ||
|
|
838288a463 | ||
|
|
f4b9356173 | ||
|
|
beaa4a29ba | ||
|
|
987ba2faa5 | ||
|
|
a24f697dca | ||
|
|
c7947d0c46 | ||
|
|
16aca57f17 | ||
|
|
a225748840 | ||
|
|
fff1be9d07 | ||
|
|
b73ca3f1bc | ||
|
|
93a4f999b6 | ||
|
|
3030643ce4 | ||
|
|
46913c3574 |
11
Gruntfile.js
11
Gruntfile.js
@@ -17,7 +17,7 @@
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with EspoCRM. If not, see http://www.gnu.org/licenses/.
|
||||
************************************************************************/
|
||||
************************************************************************/
|
||||
module.exports = function (grunt) {
|
||||
|
||||
var jsFilesToMinify = [
|
||||
@@ -65,10 +65,10 @@ module.exports = function (grunt) {
|
||||
'client/src/controllers/base.js',
|
||||
'client/src/view.js',
|
||||
];
|
||||
|
||||
|
||||
grunt.initConfig({
|
||||
pkg: grunt.file.readJSON('package.json'),
|
||||
|
||||
|
||||
mkdir: {
|
||||
tmp: {
|
||||
options: {
|
||||
@@ -126,7 +126,8 @@ module.exports = function (grunt) {
|
||||
'modules/**',
|
||||
'img/**',
|
||||
'css/**',
|
||||
'sounds/**'
|
||||
'sounds/**',
|
||||
'custom/**'
|
||||
],
|
||||
dest: 'build/tmp/client',
|
||||
},
|
||||
@@ -154,6 +155,8 @@ module.exports = function (grunt) {
|
||||
'bootstrap.php',
|
||||
'cron.php',
|
||||
'rebuild.php',
|
||||
'clear_cache.php',
|
||||
'upgrade.php',
|
||||
'index.php',
|
||||
'LICENSE.txt',
|
||||
'.htaccess',
|
||||
|
||||
17
README.md
17
README.md
@@ -2,7 +2,7 @@
|
||||
|
||||
<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.
|
||||
It's a web application with a frontend designed as a single page application based on backbone.js and a REST API backend written in PHP.
|
||||
|
||||
Download the latest release from our [website](http://www.espocrm.com).
|
||||
|
||||
@@ -33,6 +33,21 @@ You need to have nodejs and Grunt CLI installed.
|
||||
|
||||
The build will be created in the `build` directory.
|
||||
|
||||
### How to make translation
|
||||
|
||||
Build po file with command:
|
||||
`node po.js en_EN`
|
||||
(specify needed language instead of en_EN)
|
||||
|
||||
After that tranlate the generated po file.
|
||||
|
||||
Build json files from the translated po file:
|
||||
|
||||
1. Put your po file espocrm-en_EN.po to the `build` directory
|
||||
2. Run `node lang.js en_EN`
|
||||
|
||||
The files will be created in build directory.
|
||||
|
||||
### License
|
||||
|
||||
EspoCRM is published under the GNU GPLv3 [license](https://raw.githubusercontent.com/espocrm/espocrm/master/LICENSE.txt).
|
||||
|
||||
@@ -72,7 +72,7 @@ class Admin extends \Espo\Core\Controllers\Base
|
||||
{
|
||||
$upgradeManager = new \Espo\Core\UpgradeManager($this->getContainer());
|
||||
|
||||
$upgradeManager->install($data['id']);
|
||||
$upgradeManager->install($data);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -29,19 +29,19 @@ 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 (is_null($data['password'])) {
|
||||
if ($data['type'] == 'preferences') {
|
||||
if (!$this->getUser()->isAdmin() && $data['id'] != $this->getUser()->id) {
|
||||
throw new Forbidden();
|
||||
@@ -50,7 +50,7 @@ class Email extends \Espo\Core\Controllers\Record
|
||||
if (!$preferences) {
|
||||
throw new Error();
|
||||
}
|
||||
|
||||
|
||||
$data['password'] = $this->getContainer()->get('crypt')->decrypt($preferences->get('smtpPassword'));
|
||||
} else {
|
||||
if (!$this->getUser()->isAdmin()) {
|
||||
@@ -59,8 +59,29 @@ class Email extends \Espo\Core\Controllers\Record
|
||||
$data['password'] = $this->getConfig()->get('smtpPassword');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return $this->getRecordService()->sendTestEmail($data);
|
||||
}
|
||||
|
||||
public function actionMarkAsRead($params, $data, $request)
|
||||
{
|
||||
if (!$request->isPost()) {
|
||||
throw new BadRequest();
|
||||
}
|
||||
if (empty($data['ids']) || !is_array($data['ids'])) {
|
||||
throw new BadRequest();
|
||||
}
|
||||
$ids = $data['ids'];
|
||||
|
||||
return $this->getRecordService()->markAsReadByIds($ids);
|
||||
}
|
||||
|
||||
public function actionMarkAllAsRead($params, $data, $request)
|
||||
{
|
||||
if (!$request->isPost()) {
|
||||
throw new BadRequest();
|
||||
}
|
||||
return $this->getRecordService()->markAllAsRead();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -44,5 +44,27 @@ class EmailAccount extends \Espo\Core\Controllers\Record
|
||||
throw new Forbidden();
|
||||
}
|
||||
}
|
||||
|
||||
public function actionTestConnection($params, $data, $request)
|
||||
{
|
||||
if (!$request->isPost()) {
|
||||
throw new BadRequest();
|
||||
}
|
||||
|
||||
if (is_null($data['password'])) {
|
||||
$emailAccount = $this->getEntityManager()->getEntity('EmailAccount', $data['id']);
|
||||
if (!$emailAccount) {
|
||||
throw new Error();
|
||||
}
|
||||
|
||||
if ($emailAccount->get('assignedUserId') != $this->getUser()->id && !$this->getUser()->isAdmin()) {
|
||||
throw new Forbidden();
|
||||
}
|
||||
|
||||
$data['password'] = $this->getContainer()->get('crypt')->decrypt($emailAccount->get('password'));
|
||||
}
|
||||
|
||||
return $this->getRecordService()->testConnection($data);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
227
application/Espo/Controllers/EntityManager.php
Normal file
227
application/Espo/Controllers/EntityManager.php
Normal file
@@ -0,0 +1,227 @@
|
||||
<?php
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM - Open Source CRM application.
|
||||
* Copyright (C) 2014-2015 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\BadRequest;
|
||||
use \Espo\Core\Exceptions\Forbidden;
|
||||
use \Espo\Core\Exceptions\Error;
|
||||
|
||||
class EntityManager extends \Espo\Core\Controllers\Base
|
||||
{
|
||||
protected function checkControllerAccess()
|
||||
{
|
||||
if (!$this->getUser()->isAdmin()) {
|
||||
throw new Forbidden();
|
||||
}
|
||||
}
|
||||
|
||||
public function actionCreateEntity($params, $data, $request)
|
||||
{
|
||||
if (!$request->isPost()) {
|
||||
throw new BadRequest();
|
||||
}
|
||||
|
||||
if (empty($data['name']) || empty($data['type'])) {
|
||||
throw new BadRequest();
|
||||
}
|
||||
|
||||
$name = $data['name'];
|
||||
$type = $data['type'];
|
||||
|
||||
$name = filter_var($name, \FILTER_SANITIZE_STRING);
|
||||
$type = filter_var($type, \FILTER_SANITIZE_STRING);
|
||||
|
||||
$params = array();
|
||||
|
||||
if (!empty($data['labelSingular'])) {
|
||||
$params['labelSingular'] = $data['labelSingular'];
|
||||
}
|
||||
if (!empty($data['labelPlural'])) {
|
||||
$params['labelPlural'] = $data['labelPlural'];
|
||||
}
|
||||
if (!empty($data['stream'])) {
|
||||
$params['stream'] = $data['stream'];
|
||||
}
|
||||
|
||||
$result = $this->getContainer()->get('entityManagerUtil')->create($name, $type, $params);
|
||||
|
||||
if ($result) {
|
||||
$tabList = $this->getConfig()->get('tabList', []);
|
||||
$tabList[] = $name;
|
||||
$this->getConfig()->set('tabList', $tabList);
|
||||
$this->getConfig()->save();
|
||||
|
||||
$this->getContainer()->get('dataManager')->rebuild();
|
||||
} else {
|
||||
throw new Error();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function actionUpdateEntity($params, $data, $request)
|
||||
{
|
||||
if (!$request->isPost()) {
|
||||
throw new BadRequest();
|
||||
}
|
||||
if (empty($data['name'])) {
|
||||
throw new BadRequest();
|
||||
}
|
||||
$name = $data['name'];
|
||||
$name = filter_var($name, \FILTER_SANITIZE_STRING);
|
||||
|
||||
$result = $this->getContainer()->get('entityManagerUtil')->update($name, $data);
|
||||
|
||||
if ($result) {
|
||||
$this->getContainer()->get('dataManager')->clearCache();
|
||||
} else {
|
||||
throw new Error();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function actionRemoveEntity($params, $data, $request)
|
||||
{
|
||||
if (!$request->isPost()) {
|
||||
throw new BadRequest();
|
||||
}
|
||||
|
||||
if (empty($data['name'])) {
|
||||
throw new BadRequest();
|
||||
}
|
||||
$name = $data['name'];
|
||||
$name = filter_var($name, \FILTER_SANITIZE_STRING);
|
||||
|
||||
$result = $this->getContainer()->get('entityManagerUtil')->delete($name);
|
||||
|
||||
if ($result) {
|
||||
$tabList = $this->getConfig()->get('tabList', []);
|
||||
if (($key = array_search($name, $tabList)) !== false) {
|
||||
unset($tabList[$key]);
|
||||
$tabList = array_values($tabList);
|
||||
}
|
||||
$this->getConfig()->set('tabList', $tabList);
|
||||
$this->getConfig()->save();
|
||||
|
||||
$this->getContainer()->get('dataManager')->clearCache();
|
||||
} else {
|
||||
throw new Error();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function actionCreateLink($params, $data, $request)
|
||||
{
|
||||
if (!$request->isPost()) {
|
||||
throw new BadRequest();
|
||||
}
|
||||
|
||||
$paramList = [
|
||||
'entity',
|
||||
'entityForeign',
|
||||
'link',
|
||||
'linkForeign',
|
||||
'label',
|
||||
'labelForeign',
|
||||
'linkType'
|
||||
];
|
||||
|
||||
$d = array();
|
||||
foreach ($paramList as $item) {
|
||||
if (empty($data[$item])) {
|
||||
throw new BadRequest();
|
||||
}
|
||||
$d[$item] = filter_var($data[$item], \FILTER_SANITIZE_STRING);
|
||||
}
|
||||
|
||||
$result = $this->getContainer()->get('entityManagerUtil')->createLink($d);
|
||||
|
||||
if ($result) {
|
||||
$this->getContainer()->get('dataManager')->rebuild();
|
||||
} else {
|
||||
throw new Error();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function actionUpdateLink($params, $data, $request)
|
||||
{
|
||||
if (!$request->isPost()) {
|
||||
throw new BadRequest();
|
||||
}
|
||||
|
||||
$paramList = [
|
||||
'entity',
|
||||
'entityForeign',
|
||||
'link',
|
||||
'linkForeign',
|
||||
'label',
|
||||
'labelForeign'
|
||||
];
|
||||
|
||||
$d = array();
|
||||
foreach ($paramList as $item) {
|
||||
$d[$item] = filter_var($data[$item], \FILTER_SANITIZE_STRING);
|
||||
}
|
||||
|
||||
$result = $this->getContainer()->get('entityManagerUtil')->updateLink($d);
|
||||
|
||||
if ($result) {
|
||||
$this->getContainer()->get('dataManager')->clearCache();
|
||||
} else {
|
||||
throw new Error();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function actionRemoveLink($params, $data, $request)
|
||||
{
|
||||
if (!$request->isPost()) {
|
||||
throw new BadRequest();
|
||||
}
|
||||
|
||||
$paramList = [
|
||||
'entity',
|
||||
'link',
|
||||
];
|
||||
$d = array();
|
||||
foreach ($paramList as $item) {
|
||||
$d[$item] = filter_var($data[$item], \FILTER_SANITIZE_STRING);
|
||||
}
|
||||
|
||||
$result = $this->getContainer()->get('entityManagerUtil')->deleteLink($d);
|
||||
|
||||
if ($result) {
|
||||
$this->getContainer()->get('dataManager')->clearCache();
|
||||
} else {
|
||||
throw new Error();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -61,7 +61,7 @@ class Extension extends \Espo\Core\Controllers\Record
|
||||
|
||||
$manager = new \Espo\Core\ExtensionManager($this->getContainer());
|
||||
|
||||
$manager->install($data['id']);
|
||||
$manager->install($data);
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -74,7 +74,7 @@ class Extension extends \Espo\Core\Controllers\Record
|
||||
|
||||
$manager = new \Espo\Core\ExtensionManager($this->getContainer());
|
||||
|
||||
$manager->uninstall($data['id']);
|
||||
$manager->uninstall($data);
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -103,7 +103,7 @@ class Extension extends \Espo\Core\Controllers\Record
|
||||
{
|
||||
$manager = new \Espo\Core\ExtensionManager($this->getContainer());
|
||||
|
||||
$manager->delete($params['id']);
|
||||
$manager->delete($params);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -18,50 +18,94 @@
|
||||
*
|
||||
* 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\Utils as Utils;
|
||||
use \Espo\Core\Exceptions\Error;
|
||||
use \Espo\Core\Exceptions\Forbidden;
|
||||
use \Espo\Core\Exceptions\BadRequest;
|
||||
|
||||
class Import extends \Espo\Core\Controllers\Record
|
||||
{
|
||||
protected function checkControllerAccess()
|
||||
{
|
||||
if (!$this->getUser()->isAdmin()) {
|
||||
throw new Forbidden();
|
||||
}
|
||||
}
|
||||
|
||||
public function actionPatch($params, $data)
|
||||
{
|
||||
throw new BadRequest();
|
||||
}
|
||||
|
||||
public function actionUpdate($params, $data)
|
||||
{
|
||||
throw new BadRequest();
|
||||
}
|
||||
|
||||
public function actionMassUpdate($params, $data, $request)
|
||||
{
|
||||
throw new BadRequest();
|
||||
}
|
||||
|
||||
public function actionCreateLink($params, $data)
|
||||
{
|
||||
throw new BadRequest();
|
||||
}
|
||||
|
||||
public function actionRemoveLink($params, $data)
|
||||
{
|
||||
throw new BadRequest();
|
||||
}
|
||||
|
||||
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');
|
||||
$attachment->set('role', 'Import File');
|
||||
$attachment->set('role', 'Import File');
|
||||
$attachment->set('name', 'import-file.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']);
|
||||
{
|
||||
if (empty($data['id'])) {
|
||||
throw new BadRequest();
|
||||
}
|
||||
return $this->getService('Import')->revert($data['id']);
|
||||
}
|
||||
|
||||
|
||||
public function actionRemoveDuplicates($params, $data)
|
||||
{
|
||||
if (empty($data['id'])) {
|
||||
throw new BadRequest();
|
||||
}
|
||||
return $this->getService('Import')->removeDuplicates($data['id']);
|
||||
}
|
||||
|
||||
public function actionCreate($params, $data)
|
||||
{
|
||||
{
|
||||
$importParams = array(
|
||||
'headerRow' => $data['headerRow'],
|
||||
'fieldDelimiter' => $data['fieldDelimiter'],
|
||||
@@ -74,13 +118,13 @@ class Import extends \Espo\Core\Controllers\Base
|
||||
'defaultValues' => $data['defaultValues'],
|
||||
'action' => $data['action'],
|
||||
);
|
||||
|
||||
|
||||
$attachmentId = $data['attachmentId'];
|
||||
|
||||
|
||||
if (!$this->getAcl()->check($data['entityType'], 'edit')) {
|
||||
throw new Forbidden();
|
||||
}
|
||||
|
||||
|
||||
return $this->getService('Import')->import($data['entityType'], $data['fields'], $attachmentId, $importParams);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -28,22 +28,22 @@ 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 getCrypt()
|
||||
{
|
||||
return $this->getContainer()->get('crypt');
|
||||
}
|
||||
|
||||
|
||||
protected function handleUserAccess($userId)
|
||||
{
|
||||
if (!$this->getUser()->isAdmin()) {
|
||||
@@ -52,7 +52,7 @@ class Preferences extends \Espo\Core\Controllers\Base
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function actionDelete($params, $data)
|
||||
{
|
||||
$userId = $params['id'];
|
||||
@@ -60,38 +60,38 @@ class Preferences extends \Espo\Core\Controllers\Base
|
||||
throw new BadRequest();
|
||||
}
|
||||
$this->handleUserAccess($userId);
|
||||
|
||||
return $this->getEntityManager()->getRepository('Preferences')->resetToDefaults($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);
|
||||
|
||||
|
||||
if (array_key_exists('smtpPassword', $data)) {
|
||||
$data['smtpPassword'] = $this->getCrypt()->encrypt($data['smtpPassword']);
|
||||
}
|
||||
|
||||
$user = $this->getEntityManager()->getEntity('User', $userId);
|
||||
|
||||
$user = $this->getEntityManager()->getEntity('User', $userId);
|
||||
|
||||
$entity = $this->getEntityManager()->getEntity('Preferences', $userId);
|
||||
|
||||
if ($entity) {
|
||||
|
||||
if ($entity && $user) {
|
||||
$entity->set($data);
|
||||
$this->getEntityManager()->saveEntity($entity);
|
||||
|
||||
$entity->set('smtpEmailAddress', $user->get('emailAddress'));
|
||||
|
||||
$entity->set('smtpEmailAddress', $user->get('emailAddress'));
|
||||
$entity->set('name', $user->get('name'));
|
||||
|
||||
|
||||
$entity->clear('smtpPassword');
|
||||
|
||||
return $entity->toArray();
|
||||
|
||||
return $entity->toArray();
|
||||
}
|
||||
throw new Error();
|
||||
}
|
||||
@@ -101,18 +101,19 @@ class Preferences extends \Espo\Core\Controllers\Base
|
||||
$userId = $params['id'];
|
||||
$this->handleUserAccess($userId);
|
||||
|
||||
$entity = $this->getEntityManager()->getEntity('Preferences', $userId);
|
||||
$entity = $this->getEntityManager()->getEntity('Preferences', $userId);
|
||||
$user = $this->getEntityManager()->getEntity('User', $userId);
|
||||
|
||||
|
||||
if (!$entity || !$user) {
|
||||
throw new NotFound();
|
||||
}
|
||||
|
||||
$entity->set('smtpEmailAddress', $user->get('emailAddress'));
|
||||
$entity->set('name', $user->get('name'));
|
||||
|
||||
|
||||
$entity->clear('smtpPassword');
|
||||
|
||||
if ($entity) {
|
||||
return $entity->toArray();
|
||||
}
|
||||
throw new NotFound();
|
||||
|
||||
return $entity->toArray();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -35,30 +35,33 @@ class User extends \Espo\Core\Controllers\Record
|
||||
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)
|
||||
|
||||
public function actionChangeOwnPassword($params, $data, $request)
|
||||
{
|
||||
if (!$request->isPost()) {
|
||||
throw new BadRequest();
|
||||
}
|
||||
return $this->getService('User')->changePassword($this->getUser()->id, $data['password']);
|
||||
}
|
||||
|
||||
public function actionChangePasswordByRequest($params, $data, $request)
|
||||
{
|
||||
if (!$request->isPost()) {
|
||||
throw new Forbidden();
|
||||
throw new BadRequest();
|
||||
}
|
||||
if (empty($data['requestId']) || empty($data['password'])) {
|
||||
throw new BadRequest();
|
||||
|
||||
@@ -28,7 +28,9 @@ use \Espo\ORM\Entity;
|
||||
|
||||
class Acl
|
||||
{
|
||||
private $data = array();
|
||||
private $data = array(
|
||||
'table' => array()
|
||||
);
|
||||
|
||||
private $cacheFile;
|
||||
|
||||
@@ -74,16 +76,16 @@ class Acl
|
||||
|
||||
public function checkScope($scope, $action = null, $isOwner = null, $inTeam = null, $entity = null)
|
||||
{
|
||||
if (array_key_exists($scope, $this->data)) {
|
||||
if ($this->data[$scope] === false) {
|
||||
if (array_key_exists($scope, $this->data['table'])) {
|
||||
if ($this->data['table'][$scope] === false) {
|
||||
return false;
|
||||
}
|
||||
if ($this->data[$scope] === true) {
|
||||
if ($this->data['table'][$scope] === true) {
|
||||
return true;
|
||||
}
|
||||
if (!is_null($action)) {
|
||||
if (array_key_exists($action, $this->data[$scope])) {
|
||||
$value = $this->data[$scope][$action];
|
||||
if (array_key_exists($action, $this->data['table'][$scope])) {
|
||||
$value = $this->data['table'][$scope][$action];
|
||||
|
||||
if ($value === 'all' || $value === true) {
|
||||
return true;
|
||||
@@ -125,14 +127,29 @@ class Acl
|
||||
return $this->data;
|
||||
}
|
||||
|
||||
public function get($permission)
|
||||
{
|
||||
if ($this->user->isAdmin()) {
|
||||
return true;
|
||||
}
|
||||
if ($permission == 'table') {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (array_key_exists($permission, $this->data)) {
|
||||
return $this->data[$permission];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
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];
|
||||
if (array_key_exists($scope, $this->data['table'])) {
|
||||
if (array_key_exists($action, $this->data['table'][$scope])) {
|
||||
return $this->data['table'][$scope][$action];
|
||||
}
|
||||
}
|
||||
return false;
|
||||
@@ -156,8 +173,8 @@ class Acl
|
||||
|
||||
public function checkReadOnlyTeam($scope)
|
||||
{
|
||||
if (isset($this->data[$scope]) && isset($this->data[$scope]['read'])) {
|
||||
return $this->data[$scope]['read'] === 'team';
|
||||
if (isset($this->data['table'][$scope]) && isset($this->data['table'][$scope]['read'])) {
|
||||
return $this->data['table'][$scope]['read'] === 'team';
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -167,8 +184,8 @@ class Acl
|
||||
if ($this->user->isAdmin()) {
|
||||
return false;
|
||||
}
|
||||
if (isset($this->data[$scope]) && isset($this->data[$scope]['read'])) {
|
||||
return $this->data[$scope]['read'] === 'own';
|
||||
if (isset($this->data['table'][$scope]) && isset($this->data['table'][$scope]['read'])) {
|
||||
return $this->data['table'][$scope]['read'] === 'own';
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -213,12 +230,14 @@ class Acl
|
||||
|
||||
private function load()
|
||||
{
|
||||
$aclTables = array();
|
||||
$aclTables = [];
|
||||
$assignmentPermissionList = [];
|
||||
|
||||
$userRoles = $this->user->get('roles');
|
||||
|
||||
foreach ($userRoles as $role) {
|
||||
$aclTables[] = $role->get('data');
|
||||
$assignmentPermissionList[] = $role->get('assignmentPermission');
|
||||
}
|
||||
|
||||
$teams = $this->user->get('teams');
|
||||
@@ -226,21 +245,47 @@ class Acl
|
||||
$teamRoles = $team->get('roles');
|
||||
foreach ($teamRoles as $role) {
|
||||
$aclTables[] = $role->get('data');
|
||||
$assignmentPermissionList[] = $role->get('assignmentPermission');
|
||||
}
|
||||
}
|
||||
|
||||
$this->data = $this->merge($aclTables);
|
||||
$this->data['table'] = $this->merge($aclTables);
|
||||
$this->data['assignmentPermission'] = $this->mergeValues($assignmentPermissionList, 'all');
|
||||
}
|
||||
|
||||
private function initSolid()
|
||||
{
|
||||
if (!$this->metadata) {
|
||||
return;
|
||||
}
|
||||
|
||||
$data = $this->metadata->get('app.acl.solid', array());
|
||||
|
||||
foreach ($data as $entityName => $item) {
|
||||
$this->data[$entityName] = $item;
|
||||
$this->data['table'][$entityName] = $item;
|
||||
}
|
||||
}
|
||||
|
||||
private function mergeValues(array $list, $defaultValue)
|
||||
{
|
||||
$result = null;
|
||||
foreach ($list as $level) {
|
||||
if ($level != 'not-set') {
|
||||
if (is_null($result)) {
|
||||
$result = $level;
|
||||
continue;
|
||||
}
|
||||
if (array_search($result, $this->levelList) > array_search($level, $this->levelList)) {
|
||||
$result = $level;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (is_null($result)) {
|
||||
$result = $defaultValue;
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
private function merge($tables)
|
||||
{
|
||||
$data = array();
|
||||
|
||||
@@ -138,6 +138,12 @@ class Application
|
||||
$dataManager->rebuild();
|
||||
}
|
||||
|
||||
public function runClearCache()
|
||||
{
|
||||
$dataManager = $this->getContainer()->get('dataManager');
|
||||
$dataManager->clearCache();
|
||||
}
|
||||
|
||||
public function isInstalled()
|
||||
{
|
||||
$config = $this->getContainer()->get('config');
|
||||
|
||||
@@ -79,6 +79,28 @@ class Container
|
||||
return $className;
|
||||
}
|
||||
|
||||
protected function loadLog()
|
||||
{
|
||||
$logConfig = $this->get('config')->get('logger');
|
||||
|
||||
$log = new \Espo\Core\Utils\Log('Espo');
|
||||
|
||||
$levelCode = $log->getLevelCode($logConfig['level']);
|
||||
|
||||
if ($logConfig['isRotate']) {
|
||||
$handler = new \Espo\Core\Utils\Log\Monolog\Handler\RotatingFileHandler($logConfig['path'], $logConfig['maxRotateFiles'], $levelCode);
|
||||
} else {
|
||||
$handler = new \Espo\Core\Utils\Log\Monolog\Handler\StreamHandler($logConfig['path'], $levelCode);
|
||||
}
|
||||
$log->pushHandler($handler);
|
||||
|
||||
$errorHandler = new \Monolog\ErrorHandler($log);
|
||||
$errorHandler->registerExceptionHandler(null, false);
|
||||
$errorHandler->registerErrorHandler(array(), false);
|
||||
|
||||
return $log;
|
||||
}
|
||||
|
||||
protected function loadContainer()
|
||||
{
|
||||
return $this;
|
||||
|
||||
@@ -25,6 +25,7 @@ namespace Espo\Core\Controllers;
|
||||
use \Espo\Core\Exceptions\Error;
|
||||
use \Espo\Core\Exceptions\Forbidden;
|
||||
use \Espo\Core\Exceptions\NotFound;
|
||||
use \Espo\Core\Exceptions\BadRequest;
|
||||
use \Espo\Core\Utils\Util;
|
||||
|
||||
class Record extends Base
|
||||
@@ -193,9 +194,17 @@ class Record extends Base
|
||||
|
||||
$ids = $request->get('ids');
|
||||
$where = $request->get('where');
|
||||
$byWhere = $request->get('byWhere');
|
||||
|
||||
$params = array();
|
||||
if ($byWhere) {
|
||||
$params['where'] = $where;
|
||||
} else {
|
||||
$params['ids'] = $ids;
|
||||
}
|
||||
|
||||
return array(
|
||||
'id' => $this->getRecordService()->export($ids, $where)
|
||||
'id' => $this->getRecordService()->export($params)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -204,12 +213,20 @@ class Record extends Base
|
||||
if (!$this->getAcl()->check($this->name, 'edit')) {
|
||||
throw new Forbidden();
|
||||
}
|
||||
if (empty($data['attributes'])) {
|
||||
throw new BadRequest();
|
||||
}
|
||||
|
||||
$params = array();
|
||||
if (array_key_exists('where', $data) && !empty($data['byWhere'])) {
|
||||
$params['where'] = json_decode(json_encode($data['where']), true);
|
||||
} else if (array_key_exists('ids', $data)) {
|
||||
$params['ids'] = $data['ids'];
|
||||
}
|
||||
|
||||
$ids = $data['ids'];
|
||||
$where = $data['where'];
|
||||
$attributes = $data['attributes'];
|
||||
|
||||
$idsUpdated = $this->getRecordService()->massUpdate($attributes, $ids, $where);
|
||||
$idsUpdated = $this->getRecordService()->massUpdate($attributes, $params);
|
||||
|
||||
return $idsUpdated;
|
||||
}
|
||||
@@ -220,37 +237,56 @@ class Record extends Base
|
||||
throw new Forbidden();
|
||||
}
|
||||
|
||||
$ids = $data['ids'];
|
||||
$where = $data['where'];
|
||||
$params = array();
|
||||
if (array_key_exists('where', $data) && !empty($data['byWhere'])) {
|
||||
$where = json_decode(json_encode($data['where']), true);
|
||||
$params['where'] = $where;
|
||||
}
|
||||
if (array_key_exists('ids', $data)) {
|
||||
$where = json_decode(json_encode($data['where']), true);
|
||||
$params['ids'] = $data['ids'];
|
||||
}
|
||||
|
||||
$idsRemoved = $this->getRecordService()->massRemove($ids, $where);
|
||||
$idsRemoved = $this->getRecordService()->massRemove($params);
|
||||
|
||||
return $idsRemoved;
|
||||
}
|
||||
|
||||
public function actionCreateLink($params, $data)
|
||||
{
|
||||
if (empty($params['id']) || empty($params['link'])) {
|
||||
throw BadRequest();
|
||||
}
|
||||
|
||||
$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;
|
||||
if (!empty($data['massRelate'])) {
|
||||
if (!is_array($data['where'])) {
|
||||
throw new BadRequest();
|
||||
}
|
||||
$where = json_decode(json_encode($data['where']), true);
|
||||
return $this->getRecordService()->linkEntityMass($id, $link, $where);
|
||||
} else {
|
||||
$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;
|
||||
$result = false;
|
||||
foreach ($foreignIds as $foreignId) {
|
||||
if ($this->getRecordService()->linkEntity($id, $link, $foreignId)) {
|
||||
$result = true;
|
||||
}
|
||||
}
|
||||
if ($result) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if ($result) {
|
||||
return true;
|
||||
}
|
||||
|
||||
throw new Error();
|
||||
@@ -261,6 +297,10 @@ class Record extends Base
|
||||
$id = $params['id'];
|
||||
$link = $params['link'];
|
||||
|
||||
if (empty($params['id']) || empty($params['link'])) {
|
||||
throw BadRequest();
|
||||
}
|
||||
|
||||
$foreignIds = array();
|
||||
if (isset($data['id'])) {
|
||||
$foreignIds[] = $data['id'];
|
||||
@@ -301,5 +341,24 @@ class Record extends Base
|
||||
$id = $params['id'];
|
||||
return $this->getRecordService()->unfollow($id);
|
||||
}
|
||||
|
||||
public function actionMerge($params, $data, $request)
|
||||
{
|
||||
if (!$request->isPost()) {
|
||||
throw new BadRequest();
|
||||
}
|
||||
|
||||
if (empty($data['targetId']) || empty($data['sourceIds']) || !is_array($data['sourceIds'])) {
|
||||
throw new BadRequest();
|
||||
}
|
||||
$targetId = $data['targetId'];
|
||||
$sourceIds = $data['sourceIds'];
|
||||
|
||||
if (!$this->getAcl()->check($this->name, 'edit')) {
|
||||
throw new Forbidden();
|
||||
}
|
||||
|
||||
return $this->getRecordService()->merge($targetId, $sourceIds);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -98,9 +98,11 @@ class CronManager
|
||||
|
||||
protected function getLastRunTime()
|
||||
{
|
||||
$lastRunTime = $this->getFileManager()->getPhpContents($this->lastRunTime);
|
||||
if (!is_int($lastRunTime)) {
|
||||
$lastRunTime = time() - (intval($this->getConfig()->get('cron.minExecutionTime')) + 60);
|
||||
$lastRunData = $this->getFileManager()->getPhpContents($this->lastRunTime);
|
||||
|
||||
$lastRunTime = time() - intval($this->getConfig()->get('cron.minExecutionTime')) - 1;
|
||||
if (is_array($lastRunData) && !empty($lastRunData['time'])) {
|
||||
$lastRunTime = $lastRunData['time'];
|
||||
}
|
||||
|
||||
return $lastRunTime;
|
||||
@@ -108,7 +110,10 @@ class CronManager
|
||||
|
||||
protected function setLastRunTime($time)
|
||||
{
|
||||
return $this->getFileManager()->putPhpContents($this->lastRunTime, $time);
|
||||
$data = array(
|
||||
'time' => $time,
|
||||
);
|
||||
return $this->getFileManager()->putPhpContents($this->lastRunTime, $data);
|
||||
}
|
||||
|
||||
protected function checkLastRunTime()
|
||||
@@ -183,7 +188,6 @@ class CronManager
|
||||
$cronScheduledJob->addLogRecord($job['scheduled_job_id'], $status);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -28,7 +28,6 @@ class ExtensionManager extends Upgrades\Base
|
||||
|
||||
protected $params = array(
|
||||
'packagePath' => 'data/upload/extensions',
|
||||
|
||||
'backupPath' => 'data/.backup/extensions',
|
||||
|
||||
'scriptNames' => array(
|
||||
|
||||
@@ -155,7 +155,7 @@ abstract class OAuth2Abstract implements IClient
|
||||
$code = $r['code'];
|
||||
}
|
||||
|
||||
if ($code == 200) {
|
||||
if ($code >= 200 && $code < 300) {
|
||||
return $r['result'];
|
||||
} else {
|
||||
$handledData = $this->handleErrorResponse($r);
|
||||
|
||||
@@ -233,7 +233,7 @@ class Client
|
||||
$params['grant_type'] = $grantType;
|
||||
|
||||
$httpHeaders = array();
|
||||
switch ($this->clientAuth) {
|
||||
switch ($this->tokenType) {
|
||||
case self::AUTH_TYPE_URI:
|
||||
case self::AUTH_TYPE_FORM:
|
||||
$params['client_id'] = $this->clientId;
|
||||
|
||||
@@ -93,10 +93,10 @@ class HookManager
|
||||
}
|
||||
}
|
||||
|
||||
public function process($scope, $hookName, $injection = null)
|
||||
public function process($scope, $hookName, $injection = null, array $options = array())
|
||||
{
|
||||
if ($scope != 'Common') {
|
||||
$this->process('Common', $hookName, $injection);
|
||||
$this->process('Common', $hookName, $injection, $options);
|
||||
}
|
||||
|
||||
if (!empty($this->data[$scope])) {
|
||||
@@ -106,7 +106,7 @@ class HookManager
|
||||
$this->hooks[$className] = $this->createHookByClassName($className);
|
||||
}
|
||||
$hook = $this->hooks[$className];
|
||||
$hook->$hookName($injection);
|
||||
$hook->$hookName($injection, $options);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -170,7 +170,9 @@ class HookManager
|
||||
$sortedHookList = array_merge($sortedHookList, $hookDetails);
|
||||
}
|
||||
|
||||
$hooks[$scopeName][$hookName] = isset($hooks[$scopeName][$hookName]) ? array_merge($hooks[$scopeName][$hookName], $sortedHookList) : $sortedHookList;
|
||||
$normalizedScopeName = Util::normilizeScopeName($scopeName);
|
||||
|
||||
$hooks[$normalizedScopeName][$hookName] = isset($hooks[$normalizedScopeName][$hookName]) ? array_merge($hooks[$normalizedScopeName][$hookName], $sortedHookList) : $sortedHookList;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ namespace Espo\Core\Hooks;
|
||||
|
||||
use \Espo\Core\Interfaces\Injectable;
|
||||
|
||||
class Base implements Injectable
|
||||
abstract class Base implements Injectable
|
||||
{
|
||||
protected $dependencies = array(
|
||||
'entityManager',
|
||||
@@ -52,6 +52,11 @@ class Base implements Injectable
|
||||
return $this->dependencies;
|
||||
}
|
||||
|
||||
protected function addDependency($name)
|
||||
{
|
||||
$this->dependencies[] = $name;
|
||||
}
|
||||
|
||||
protected function getInjection($name)
|
||||
{
|
||||
return $this->injections[$name];
|
||||
|
||||
@@ -22,31 +22,17 @@
|
||||
|
||||
namespace Espo\Core\Loaders;
|
||||
|
||||
use Espo\Core\Utils,
|
||||
Espo\Core\Utils\Log\Monolog\Handler;
|
||||
|
||||
class Log extends Base
|
||||
class EntityManagerUtil extends Base
|
||||
{
|
||||
public function load()
|
||||
{
|
||||
$logConfig = $this->getContainer()->get('config')->get('logger');
|
||||
$entityManager = new \Espo\Core\Utils\EntityManager(
|
||||
$this->getContainer()->get('metadata'),
|
||||
$this->getContainer()->get('language'),
|
||||
$this->getContainer()->get('fileManager')
|
||||
);
|
||||
|
||||
$log = new Utils\Log('Espo');
|
||||
|
||||
$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 $entityManager;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,6 +24,8 @@ namespace Espo\Core\Mail;
|
||||
|
||||
use \Zend\Mime\Mime as Mime;
|
||||
|
||||
use \Espo\ORM\Entity;
|
||||
|
||||
class Importer
|
||||
{
|
||||
private $entityManager;
|
||||
@@ -60,7 +62,7 @@ class Importer
|
||||
|
||||
$subject = $message->subject;
|
||||
if ($subject !== '0' && empty($subject)) {
|
||||
$subject = '--empty--';
|
||||
$subject = '(No Subject)';
|
||||
}
|
||||
|
||||
$email->set('isHtml', false);
|
||||
@@ -72,11 +74,18 @@ class Importer
|
||||
|
||||
$fromArr = $this->getAddressListFromMessage($message, 'from');
|
||||
if (isset($message->from)) {
|
||||
$email->set('fromName', $message->from);
|
||||
$email->set('fromString', $message->from);
|
||||
}
|
||||
if (isset($message->replyTo)) {
|
||||
$email->set('replyToString', $message->replyTo);
|
||||
}
|
||||
|
||||
$toArr = $this->getAddressListFromMessage($message, 'to');
|
||||
$ccArr = $this->getAddressListFromMessage($message, 'cc');
|
||||
|
||||
$email->set('from', $fromArr[0]);
|
||||
$email->set('to', implode(';', $this->getAddressListFromMessage($message, 'to')));
|
||||
$email->set('cc', implode(';', $this->getAddressListFromMessage($message, 'cc')));
|
||||
$email->set('to', implode(';', $toArr));
|
||||
$email->set('cc', implode(';', $ccArr));
|
||||
|
||||
if (isset($message->messageId) && !empty($message->messageId)) {
|
||||
$email->set('messageId', $message->messageId);
|
||||
@@ -85,7 +94,13 @@ class Importer
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->checkIsDuplicate($email)) {
|
||||
if ($duplicate = $this->findDuplicate($email)) {
|
||||
$this->getEntityManager()->getRepository('Email')->relate($duplicate, 'users', $userId);
|
||||
if (!empty($teamsIds)) {
|
||||
foreach ($teamsIds as $teamId) {
|
||||
$this->getEntityManager()->getRepository('Email')->relate($duplicate, 'teams', $teamId);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -95,7 +110,9 @@ class Importer
|
||||
$dateSent = $dt->setTimezone(new \DateTimeZone('UTC'))->format('Y-m-d H:i:s');
|
||||
$email->set('dateSent', $dateSent);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$email->set('dateSent', date('Y-m-d H:i:s'));
|
||||
}
|
||||
if (isset($message->deliveryDate)) {
|
||||
$dt = new \DateTime($message->deliveryDate);
|
||||
if ($dt) {
|
||||
@@ -108,11 +125,10 @@ class Importer
|
||||
|
||||
if ($message->isMultipart()) {
|
||||
foreach (new \RecursiveIteratorIterator($message) as $part) {
|
||||
echo "-";
|
||||
$this->importPartDataToEmail($email, $part, $inlineIds);
|
||||
}
|
||||
} else {
|
||||
$this->importPartDataToEmail($email, $message, $inlineIds);
|
||||
$this->importPartDataToEmail($email, $message, $inlineIds, 'text/plain');
|
||||
}
|
||||
|
||||
$body = $email->get('body');
|
||||
@@ -123,6 +139,8 @@ class Importer
|
||||
$email->set('body', $body);
|
||||
}
|
||||
|
||||
$parentFound = false;
|
||||
|
||||
if (isset($message->references) && !empty($message->references)) {
|
||||
$reference = str_replace(array('/', '@'), " ", trim($message->references, '<>'));
|
||||
$parentType = $parentId = null;
|
||||
@@ -132,26 +150,19 @@ class Importer
|
||||
if (!empty($parentType) && !empty($parentId)) {
|
||||
$email->set('parentType', $parentType);
|
||||
$email->set('parentId', $parentId);
|
||||
$parentFound = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!$email->has('parentId')) {
|
||||
if (!$parentFound) {
|
||||
$from = $email->get('from');
|
||||
if ($from) {
|
||||
$contact = $this->getEntityManager()->getRepository('Contact')->where(array(
|
||||
'emailAddress' => $from
|
||||
))->findOne();
|
||||
if ($contact) {
|
||||
if (!$this->getConfig()->get('b2cMode')) {
|
||||
if ($contact->get('accountId')) {
|
||||
$email->set('parentType', 'Account');
|
||||
$email->set('parentId', $contact->get('accountId'));
|
||||
}
|
||||
} else {
|
||||
$email->set('parentType', 'Contact');
|
||||
$email->set('parentId', $contact->id);
|
||||
}
|
||||
$parentFound = $this->findParent($email, $from);
|
||||
}
|
||||
if (!$parentFound) {
|
||||
if (!empty($toArr)) {
|
||||
$parentFound = $this->findParent($email, $toArr[0]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -163,14 +174,52 @@ class Importer
|
||||
} catch (\Exception $e) {}
|
||||
}
|
||||
|
||||
protected function checkIsDuplicate($email)
|
||||
protected function findParent(Entity $email, $emailAddress)
|
||||
{
|
||||
if ($email->get('messageIdInternal')) {
|
||||
$contact = $this->getEntityManager()->getRepository('Contact')->where(array(
|
||||
'emailAddress' => $emailAddress
|
||||
))->findOne();
|
||||
if ($contact) {
|
||||
if (!$this->getConfig()->get('b2cMode')) {
|
||||
if ($contact->get('accountId')) {
|
||||
$email->set('parentType', 'Account');
|
||||
$email->set('parentId', $contact->get('accountId'));
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
$email->set('parentType', 'Contact');
|
||||
$email->set('parentId', $contact->id);
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
$account = $this->getEntityManager()->getRepository('Account')->where(array(
|
||||
'emailAddress' => $emailAddress
|
||||
))->findOne();
|
||||
if ($account) {
|
||||
$email->set('parentType', 'Account');
|
||||
$email->set('parentId', $account->id);
|
||||
return true;
|
||||
} else {
|
||||
$lead = $this->getEntityManager()->getRepository('Lead')->where(array(
|
||||
'emailAddress' => $emailAddress
|
||||
))->findOne();
|
||||
if ($lead) {
|
||||
$email->set('parentType', 'Lead');
|
||||
$email->set('parentId', $lead->id);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected function findDuplicate(Entity $email)
|
||||
{
|
||||
if ($email->get('messageId')) {
|
||||
$duplicate = $this->getEntityManager()->getRepository('Email')->where(array(
|
||||
'messageIdInternal' => $email->get('messageIdInternal')
|
||||
'messageId' => $email->get('messageId')
|
||||
))->findOne();
|
||||
if ($duplicate) {
|
||||
return true;
|
||||
return $duplicate;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -188,81 +237,102 @@ class Importer
|
||||
return $addressList;
|
||||
}
|
||||
|
||||
protected function importPartDataToEmail(\Espo\Entities\Email $email, $part, &$inlineIds = array())
|
||||
protected function importPartDataToEmail(\Espo\Entities\Email $email, $part, &$inlineIds = array(), $defaultContentType = null)
|
||||
{
|
||||
try {
|
||||
if (!$part->getHeaders() || !isset($part->contentType)) {
|
||||
return;
|
||||
$type = null;
|
||||
|
||||
if ($part->getHeaders() && isset($part->contentType)) {
|
||||
$type = strtok($part->contentType, ';');
|
||||
}
|
||||
|
||||
if (empty($type)) {
|
||||
if (!empty($defaultContentType)) {
|
||||
$type = $defaultContentType;
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
$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;
|
||||
$isAttachment = true;
|
||||
|
||||
$fileName = null;
|
||||
$contentId = null;
|
||||
if ($type == 'text/plain' || $type == 'text/html') {
|
||||
|
||||
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';
|
||||
$isAttachment = false;
|
||||
$content = $this->getContentFromPart($part);
|
||||
if ($type == 'text/plain') {
|
||||
if ($email->get('bodyPlain')) {
|
||||
$isAttachment = true;
|
||||
} else {
|
||||
$email->set('bodyPlain', $content);
|
||||
if (!$email->get('body')) {
|
||||
$email->set('body', $content);
|
||||
}
|
||||
}
|
||||
|
||||
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 if ($type == 'text/html') {
|
||||
if ($email->get('isHtml')) {
|
||||
$isAttachment = true;
|
||||
} else {
|
||||
$attachment->set('role', 'Attachment');
|
||||
$email->set('body', $content);
|
||||
$email->set('isHtml', true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($encoding == 'base64') {
|
||||
$content = base64_decode($content);
|
||||
if ($isAttachment) {
|
||||
$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';
|
||||
}
|
||||
}
|
||||
|
||||
$attachment->set('size', strlen($content));
|
||||
if (isset($part->contentTransferEncoding)) {
|
||||
$encoding = strtolower($part->getHeader('Content-Transfer-Encoding')->getTransferEncoding());
|
||||
}
|
||||
|
||||
$this->getEntityManager()->saveEntity($attachment);
|
||||
$attachment = $this->getEntityManager()->getEntity('Attachment');
|
||||
$attachment->set('name', $fileName);
|
||||
$attachment->set('type', $type);
|
||||
|
||||
$path = 'data/upload/' . $attachment->id;
|
||||
$this->getFileManager()->putContents($path, $content);
|
||||
if ($disposition == 'inline') {
|
||||
$attachment->set('role', 'Inline Attachment');
|
||||
} else {
|
||||
$attachment->set('role', 'Attachment');
|
||||
}
|
||||
|
||||
if ($disposition == 'attachment') {
|
||||
$attachmentsIds = $email->get('attachmentsIds');
|
||||
$attachmentsIds[] = $attachment->id;
|
||||
$email->set('attachmentsIds', $attachmentsIds);
|
||||
} else if ($disposition == 'inline') {
|
||||
$inlineIds[$contentId] = $attachment->id;
|
||||
}
|
||||
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) {}
|
||||
}
|
||||
@@ -298,16 +368,16 @@ class Importer
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
if ($charset !== 'UTF-8') {
|
||||
$content = mb_convert_encoding($content, 'UTF-8', $charset);
|
||||
}
|
||||
}
|
||||
return $content;
|
||||
}
|
||||
|
||||
46
application/Espo/Core/Mail/Mail/Headers.php
Normal file
46
application/Espo/Core/Mail/Mail/Headers.php
Normal file
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
namespace Espo\Core\Mail\Mail;
|
||||
|
||||
use ArrayIterator;
|
||||
use Countable;
|
||||
use Iterator;
|
||||
use Traversable;
|
||||
use Zend\Loader\PluginClassLocator;
|
||||
|
||||
class Headers extends \Zend\Mail\Headers
|
||||
{
|
||||
public static function fromString($string, $EOL = self::EOL)
|
||||
{
|
||||
$headers = new static();
|
||||
$currentLine = '';
|
||||
|
||||
// iterate the header lines, some might be continuations
|
||||
foreach (explode($EOL, $string) as $line) {
|
||||
// check if a header name is present
|
||||
if (preg_match('/^(?P<name>[\x21-\x39\x3B-\x7E]+):.*$/', $line, $matches)) {
|
||||
if ($currentLine) {
|
||||
// a header name was present, then store the current complete line
|
||||
$headers->addHeaderLine($currentLine);
|
||||
}
|
||||
$currentLine = trim($line);
|
||||
} elseif (preg_match('/^\s+.*$/', $line, $matches)) {
|
||||
// continuation: append to current line
|
||||
$currentLine .= $line;
|
||||
} elseif (preg_match('/^\s*$/', $line)) {
|
||||
// empty line indicates end of headers
|
||||
break;
|
||||
} else {
|
||||
// Line does not match header format!
|
||||
throw new Exception\RuntimeException(sprintf(
|
||||
'Line "%s"does not match header format!',
|
||||
$line
|
||||
));
|
||||
}
|
||||
}
|
||||
if ($currentLine) {
|
||||
$headers->addHeaderLine($currentLine);
|
||||
}
|
||||
return $headers;
|
||||
}
|
||||
}
|
||||
@@ -20,11 +20,11 @@
|
||||
* along with EspoCRM. If not, see http://www.gnu.org/licenses/.
|
||||
************************************************************************/
|
||||
|
||||
namespace Espo\Core\Mail\Storage;
|
||||
namespace Espo\Core\Mail\Mail\Storage;
|
||||
|
||||
class Imap extends \Zend\Mail\Storage\Imap
|
||||
{
|
||||
protected $messageClass = '\\Espo\\Core\\Mail\\Storage\\Message';
|
||||
protected $messageClass = '\\Espo\\Core\\Mail\\Mail\\Storage\\Message';
|
||||
|
||||
public function getIdsFromUID($uid)
|
||||
{
|
||||
155
application/Espo/Core/Mail/Mail/Storage/Message.php
Normal file
155
application/Espo/Core/Mail/Mail/Storage/Message.php
Normal file
@@ -0,0 +1,155 @@
|
||||
<?php
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM - Open Source CRM application.
|
||||
* Copyright (C) 2014-2015 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\Mail\Mail\Storage;
|
||||
|
||||
use Espo\Core\Mail\Mail\Headers;
|
||||
use Zend\Mail\Header\HeaderInterface;
|
||||
use Zend\Mime;
|
||||
use Zend\Mail\Storage\Exception;
|
||||
use Zend\Mail\Storage\AbstractStorage;
|
||||
|
||||
class Message extends \Zend\Mail\Storage\Message
|
||||
{
|
||||
public function __construct(array $params)
|
||||
{
|
||||
if (isset($params['file'])) {
|
||||
if (!is_resource($params['file'])) {
|
||||
ErrorHandler::start();
|
||||
$params['raw'] = file_get_contents($params['file']);
|
||||
$error = ErrorHandler::stop();
|
||||
if ($params['raw'] === false) {
|
||||
throw new Exception\RuntimeException('could not open file', 0, $error);
|
||||
}
|
||||
} else {
|
||||
$params['raw'] = stream_get_contents($params['file']);
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($params['flags'])) {
|
||||
// set key and value to the same value for easy lookup
|
||||
$this->flags = array_combine($params['flags'], $params['flags']);
|
||||
}
|
||||
|
||||
if (isset($params['handler'])) {
|
||||
if (!$params['handler'] instanceof AbstractStorage) {
|
||||
throw new Exception\InvalidArgumentException('handler is not a valid mail handler');
|
||||
}
|
||||
if (!isset($params['id'])) {
|
||||
throw new Exception\InvalidArgumentException('need a message id with a handler');
|
||||
}
|
||||
|
||||
$this->mail = $params['handler'];
|
||||
$this->messageNum = $params['id'];
|
||||
}
|
||||
|
||||
$params['strict'] = isset($params['strict']) ? $params['strict'] : false;
|
||||
|
||||
if (isset($params['raw'])) {
|
||||
self::splitMessage($params['raw'], $this->headers, $this->content, Mime\Mime::LINEEND, $params['strict']);
|
||||
} elseif (isset($params['headers'])) {
|
||||
if (is_array($params['headers'])) {
|
||||
$this->headers = new Headers();
|
||||
$this->headers->addHeaders($params['headers']);
|
||||
} else {
|
||||
if ($params['headers'] instanceof \Zend\Mail\Headers) {
|
||||
$this->headers = $params['headers'];
|
||||
} else {
|
||||
if (empty($params['noToplines'])) {
|
||||
self::splitMessage($params['headers'], $this->headers, $this->topLines);
|
||||
} else {
|
||||
$this->headers = Headers::fromString($params['headers']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($params['content'])) {
|
||||
$this->content = $params['content'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function __isset($name)
|
||||
{
|
||||
$headers = $this->getHeaders();
|
||||
if (empty($headers) || !is_object($headers)) {
|
||||
return false;
|
||||
}
|
||||
return $this->getHeaders()->has($name);
|
||||
}
|
||||
|
||||
public function isMultipart()
|
||||
{
|
||||
if (!isset($this->contentType)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
return stripos($this->contentType, 'multipart/') === 0;
|
||||
} catch (Exception\ExceptionInterface $e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static function splitMessage($message, &$headers, &$body, $EOL = Mime\Mime::LINEEND, $strict = false)
|
||||
{
|
||||
if ($message instanceof Headers) {
|
||||
$message = $message->toString();
|
||||
}
|
||||
// check for valid header at first line
|
||||
$firstline = strtok($message, "\n");
|
||||
if (!preg_match('%^[^\s]+[^:]*:%', $firstline)) {
|
||||
$headers = array();
|
||||
// TODO: we're ignoring \r for now - is this function fast enough and is it safe to assume noone needs \r?
|
||||
$body = str_replace(array("\r", "\n"), array('', $EOL), $message);
|
||||
return;
|
||||
}
|
||||
|
||||
// see @ZF2-372, pops the first line off a message if it doesn't contain a header
|
||||
if (!$strict) {
|
||||
$parts = explode(':', $firstline, 2);
|
||||
if (count($parts) != 2) {
|
||||
$message = substr($message, strpos($message, $EOL)+1);
|
||||
}
|
||||
}
|
||||
|
||||
// find an empty line between headers and body
|
||||
// default is set new line
|
||||
if (strpos($message, $EOL . $EOL)) {
|
||||
list($headers, $body) = explode($EOL . $EOL, $message, 2);
|
||||
// next is the standard new line
|
||||
} elseif ($EOL != "\r\n" && strpos($message, "\r\n\r\n")) {
|
||||
list($headers, $body) = explode("\r\n\r\n", $message, 2);
|
||||
// next is the other "standard" new line
|
||||
} elseif ($EOL != "\n" && strpos($message, "\n\n")) {
|
||||
list($headers, $body) = explode("\n\n", $message, 2);
|
||||
// at last resort find anything that looks like a new line
|
||||
} else {
|
||||
ErrorHandler::start(E_NOTICE|E_WARNING);
|
||||
list($headers, $body) = preg_split("%([\r\n]+)\\1%U", $message, 2);
|
||||
ErrorHandler::stop();
|
||||
}
|
||||
|
||||
$headers = Headers::fromString($headers, $EOL);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -68,7 +68,7 @@ class Sender
|
||||
$this->params = $params;
|
||||
|
||||
$this->transport = new SmtpTransport();
|
||||
|
||||
|
||||
$opts = array(
|
||||
'name' => 'admin',
|
||||
'host' => $params['server'],
|
||||
@@ -83,14 +83,14 @@ class Sender
|
||||
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);
|
||||
|
||||
@@ -160,10 +160,10 @@ class Sender
|
||||
} else {
|
||||
$fromName = $config->get('outboundEmailFromName');
|
||||
}
|
||||
|
||||
|
||||
$message->addFrom($fromAddress, $fromName);
|
||||
}
|
||||
|
||||
|
||||
if (!empty($params['replyToAddress'])) {
|
||||
$replyToName = null;
|
||||
if (!empty($params['replyToName'])) {
|
||||
@@ -203,7 +203,6 @@ class Sender
|
||||
}
|
||||
|
||||
$attachmentPartList = array();
|
||||
|
||||
$attachmentCollection = $email->get('attachments');
|
||||
$attachmentInlineCollection = $email->getInlineAttachments();
|
||||
|
||||
@@ -220,7 +219,7 @@ class Sender
|
||||
$attachmentPartList[] = $attachment;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (!empty($attachmentInlineCollection)) {
|
||||
foreach ($attachmentInlineCollection as $a) {
|
||||
$fileName = 'data/upload/' . $a->id;
|
||||
@@ -239,12 +238,12 @@ class Sender
|
||||
$message->setSubject($email->get('name'));
|
||||
|
||||
$body = new MimeMessage();
|
||||
|
||||
|
||||
$textPart = new MimePart($email->getBodyPlainForSending());
|
||||
$textPart->type = 'text/plain';
|
||||
$textPart->encoding = Mime::ENCODING_QUOTEDPRINTABLE;
|
||||
$textPart->charset = 'utf-8';
|
||||
|
||||
|
||||
if ($email->get('isHtml')) {
|
||||
$htmlPart = new MimePart($email->getBodyForSending());
|
||||
$htmlPart->encoding = Mime::ENCODING_QUOTEDPRINTABLE;
|
||||
@@ -285,9 +284,12 @@ class Sender
|
||||
|
||||
$message->setBody($body);
|
||||
|
||||
if ($message->getHeaders()->has('content-type')) {
|
||||
$message->getHeaders()->get('content-type')->setType($messageType);
|
||||
if (!$message->getHeaders()->has('content-type')) {
|
||||
$contentTypeHeader = new \Zend\Mail\Header\ContentType();
|
||||
$message->getHeaders()->addHeader($contentTypeHeader);
|
||||
}
|
||||
$message->getHeaders()->get('content-type')->setType($messageType);
|
||||
|
||||
$message->setEncoding('UTF-8');
|
||||
|
||||
try {
|
||||
@@ -305,7 +307,7 @@ class Sender
|
||||
|
||||
$this->transport->send($message);
|
||||
|
||||
$email->set('messageId', $messageId);
|
||||
$email->set('messageId', '<' . $messageId . '>');
|
||||
$email->set('status', 'Sent');
|
||||
$email->set('dateSent', date("Y-m-d H:i:s"));
|
||||
} catch (\Exception $e) {
|
||||
|
||||
103
application/Espo/Core/Notificators/Base.php
Normal file
103
application/Espo/Core/Notificators/Base.php
Normal file
@@ -0,0 +1,103 @@
|
||||
<?php
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM - Open Source CRM application.
|
||||
* Copyright (C) 2014-2015 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\Notificators;
|
||||
|
||||
use \Espo\Core\Interfaces\Injectable;
|
||||
|
||||
use \Espo\ORM\Entity;
|
||||
|
||||
class Base implements Injectable
|
||||
{
|
||||
protected $dependencies = array(
|
||||
'user',
|
||||
'entityManager',
|
||||
);
|
||||
|
||||
protected $injections = array();
|
||||
|
||||
public static $order = 9;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->init();
|
||||
}
|
||||
|
||||
protected function init()
|
||||
{
|
||||
}
|
||||
|
||||
protected function addDependency($name)
|
||||
{
|
||||
$this->dependencies[] = $name;
|
||||
}
|
||||
|
||||
public function getDependencyList()
|
||||
{
|
||||
return $this->dependencies;
|
||||
}
|
||||
|
||||
protected function getInjection($name)
|
||||
{
|
||||
return $this->injections[$name];
|
||||
}
|
||||
|
||||
public function inject($name, $object)
|
||||
{
|
||||
$this->injections[$name] = $object;
|
||||
}
|
||||
|
||||
protected function getEntityManager()
|
||||
{
|
||||
return $this->injections['entityManager'];
|
||||
}
|
||||
|
||||
protected function getUser()
|
||||
{
|
||||
return $this->injections['user'];
|
||||
}
|
||||
|
||||
public function process(Entity $entity)
|
||||
{
|
||||
if ($entity->has('assignedUserId') && $entity->get('assignedUserId')) {
|
||||
$assignedUserId = $entity->get('assignedUserId');
|
||||
if ($assignedUserId != $this->getUser()->id && $entity->isFieldChanged('assignedUserId')) {
|
||||
$notification = $this->getEntityManager()->getEntity('Notification');
|
||||
$notification->set(array(
|
||||
'type' => 'Assign',
|
||||
'userId' => $assignedUserId,
|
||||
'data' => array(
|
||||
'entityType' => $entity->getEntityType(),
|
||||
'entityId' => $entity->id,
|
||||
'entityName' => $entity->get('name'),
|
||||
'isNew' => $entity->isNew(),
|
||||
'userId' => $this->getUser()->id,
|
||||
'userName' => $this->getUser()->get('name')
|
||||
)
|
||||
));
|
||||
$this->getEntityManager()->saveEntity($notification);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -41,17 +41,20 @@ class Entity extends \Espo\ORM\Entity
|
||||
$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);
|
||||
if ($collection) {
|
||||
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)) {
|
||||
|
||||
@@ -38,6 +38,8 @@ class RDB extends \Espo\ORM\Repositories\RDB implements Injectable
|
||||
|
||||
protected $injections = array();
|
||||
|
||||
private $restoreData = null;
|
||||
|
||||
public function inject($name, $object)
|
||||
{
|
||||
$this->injections[$name] = $object;
|
||||
@@ -79,6 +81,9 @@ class RDB extends \Espo\ORM\Repositories\RDB implements Injectable
|
||||
|
||||
foreach ($defs['fields'] as $field => $d) {
|
||||
if (isset($d['type']) && $d['type'] == 'currency') {
|
||||
if (!empty($d['notStorable'])) {
|
||||
continue;
|
||||
}
|
||||
if (empty($params['customJoin'])) {
|
||||
$params['customJoin'] = '';
|
||||
}
|
||||
@@ -135,55 +140,67 @@ class RDB extends \Espo\ORM\Repositories\RDB implements Injectable
|
||||
}
|
||||
}
|
||||
|
||||
protected function beforeRemove(Entity $entity)
|
||||
protected function beforeRemove(Entity $entity, array $options = array())
|
||||
{
|
||||
parent::beforeRemove($entity);
|
||||
$this->getEntityManager()->getHookManager()->process($this->entityName, 'beforeRemove', $entity);
|
||||
parent::beforeRemove($entity, $options);
|
||||
$this->getEntityManager()->getHookManager()->process($this->entityName, 'beforeRemove', $entity, $options);
|
||||
|
||||
$nowString = date('Y-m-d H:i:s', time());
|
||||
if ($entity->hasField('modifiedAt')) {
|
||||
$entity->set('modifiedAt', $nowString);
|
||||
}
|
||||
if ($entity->hasField('modifiedById')) {
|
||||
$entity->set('modifiedById', $this->getEntityManager()->getUser()->id);
|
||||
}
|
||||
}
|
||||
|
||||
protected function afterRemove(Entity $entity)
|
||||
protected function afterRemove(Entity $entity, array $options = array())
|
||||
{
|
||||
parent::afterRemove($entity);
|
||||
$this->getEntityManager()->getHookManager()->process($this->entityName, 'afterRemove', $entity);
|
||||
parent::afterRemove($entity, $options);
|
||||
$this->getEntityManager()->getHookManager()->process($this->entityName, 'afterRemove', $entity, $options);
|
||||
}
|
||||
|
||||
public function remove(Entity $entity)
|
||||
public function remove(Entity $entity, array $options = array())
|
||||
{
|
||||
$this->getEntityManager()->getHookManager()->process($this->entityName, 'beforeRemove', $entity);
|
||||
$this->getEntityManager()->getHookManager()->process($this->entityName, 'beforeRemove', $entity, $options);
|
||||
|
||||
$result = parent::remove($entity);
|
||||
$result = parent::remove($entity, $options);
|
||||
if ($result) {
|
||||
$this->getEntityManager()->getHookManager()->process($this->entityName, 'afterRemove', $entity);
|
||||
$this->getEntityManager()->getHookManager()->process($this->entityName, 'afterRemove', $entity, $options);
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
protected function beforeSave(Entity $entity)
|
||||
protected function beforeSave(Entity $entity, array $options = array())
|
||||
{
|
||||
parent::beforeSave($entity);
|
||||
parent::beforeSave($entity, $options);
|
||||
|
||||
$this->getEntityManager()->getHookManager()->process($this->entityName, 'beforeSave', $entity);
|
||||
$this->getEntityManager()->getHookManager()->process($this->entityName, 'beforeSave', $entity, $options);
|
||||
}
|
||||
|
||||
protected function afterSave(Entity $entity)
|
||||
protected function afterSave(Entity $entity, array $options = array())
|
||||
{
|
||||
parent::afterSave($entity);
|
||||
if (!empty($this->restoreData)) {
|
||||
$entity->set($this->restoreData);
|
||||
$this->restoreData = null;
|
||||
}
|
||||
parent::afterSave($entity, $options);
|
||||
|
||||
$this->handleEmailAddressSave($entity);
|
||||
$this->handlePhoneNumberSave($entity);
|
||||
$this->handleSpecifiedRelations($entity);
|
||||
|
||||
$this->getEntityManager()->getHookManager()->process($this->entityName, 'afterSave', $entity);
|
||||
$this->getEntityManager()->getHookManager()->process($this->entityName, 'afterSave', $entity, $options);
|
||||
}
|
||||
|
||||
public function save(Entity $entity)
|
||||
public function save(Entity $entity, array $options = array())
|
||||
{
|
||||
$nowString = date('Y-m-d H:i:s', time());
|
||||
$restoreData = array();
|
||||
|
||||
if ($entity->isNew()) {
|
||||
if (!$entity->has('id')) {
|
||||
$entity->set('id', uniqid());
|
||||
$entity->set('id', Util::generateId());
|
||||
}
|
||||
|
||||
if ($entity->hasField('createdAt')) {
|
||||
@@ -204,11 +221,13 @@ class RDB extends \Espo\ORM\Repositories\RDB implements Injectable
|
||||
}
|
||||
$entity->clear('modifiedById');
|
||||
} else {
|
||||
if ($entity->hasField('modifiedAt')) {
|
||||
$entity->set('modifiedAt', $nowString);
|
||||
}
|
||||
if ($entity->hasField('modifiedById')) {
|
||||
$entity->set('modifiedById', $this->entityManager->getUser()->id);
|
||||
if (empty($options['silent'])) {
|
||||
if ($entity->hasField('modifiedAt')) {
|
||||
$entity->set('modifiedAt', $nowString);
|
||||
}
|
||||
if ($entity->hasField('modifiedById')) {
|
||||
$entity->set('modifiedById', $this->entityManager->getUser()->id);
|
||||
}
|
||||
}
|
||||
|
||||
if ($entity->has('createdById')) {
|
||||
@@ -220,11 +239,9 @@ class RDB extends \Espo\ORM\Repositories\RDB implements Injectable
|
||||
$entity->clear('createdById');
|
||||
$entity->clear('createdAt');
|
||||
}
|
||||
$result = parent::save($entity);
|
||||
|
||||
$entity->set($restoreData);
|
||||
|
||||
$this->restoreData = $restoreData;
|
||||
|
||||
$result = parent::save($entity, $options);
|
||||
|
||||
return $result;
|
||||
}
|
||||
@@ -253,6 +270,10 @@ class RDB extends \Espo\ORM\Repositories\RDB implements Injectable
|
||||
|
||||
if ($entity->has($fieldName) || $entity->has($columnsFieldsName)) {
|
||||
|
||||
if ($this->getMetadata()->get("entityDefs." . $entity->getEntityType() . ".fields.{$name}.noSave")) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($entity->has($fieldName)) {
|
||||
$specifiedIds = $entity->get($fieldName);
|
||||
} else {
|
||||
@@ -268,24 +289,36 @@ class RDB extends \Espo\ORM\Repositories\RDB implements Injectable
|
||||
$existingColumnsData = new \stdClass();
|
||||
|
||||
$defs = array();
|
||||
$columns = $this->getMetadata()->get("entityDefs." . $entity->getEntityName() . ".fields.{$name}.columns");
|
||||
$columns = $this->getMetadata()->get("entityDefs." . $entity->getEntityType() . ".fields.{$name}.columns");
|
||||
if (!empty($columns)) {
|
||||
$columnData = $entity->get($columnsFieldsName);
|
||||
$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);
|
||||
$foreignCollection = $entity->get($name, $defs);
|
||||
if ($foreignCollection) {
|
||||
foreach ($foreignCollection 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;
|
||||
$entity->setFetched($columnsFieldsName, $existingColumnsData);
|
||||
}
|
||||
$existingColumnsData->$foreignId = $data;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if ($entity->has($fieldName)) {
|
||||
$entity->setFetched($fieldName, $existingIds);
|
||||
}
|
||||
if ($entity->has($columnsFieldsName) && !empty($columns)) {
|
||||
$entity->setFetched($columnsFieldsName, $existingColumnsData);
|
||||
}
|
||||
|
||||
foreach ($existingIds as $id) {
|
||||
if (!in_array($id, $specifiedIds)) {
|
||||
$toRemoveIds[] = $id;
|
||||
@@ -299,10 +332,12 @@ class RDB extends \Espo\ORM\Repositories\RDB implements Injectable
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
foreach ($specifiedIds as $id) {
|
||||
if (!in_array($id, $existingIds)) {
|
||||
$data = null;
|
||||
if (!empty($columns)) {
|
||||
if (!empty($columns) && isset($columnData->$id)) {
|
||||
$data = $columnData->$id;
|
||||
}
|
||||
$this->relate($entity, $name, $id, $data);
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -29,11 +29,11 @@ use \Espo\Core\Utils\Util;
|
||||
class SelectManagerFactory
|
||||
{
|
||||
private $entityManager;
|
||||
|
||||
|
||||
private $user;
|
||||
|
||||
|
||||
private $acl;
|
||||
|
||||
|
||||
private $metadata;
|
||||
|
||||
public function __construct($entityManager, \Espo\Entities\User $user, Acl $acl, $metadata)
|
||||
@@ -43,26 +43,28 @@ class SelectManagerFactory
|
||||
$this->acl = $acl;
|
||||
$this->metadata = $metadata;
|
||||
}
|
||||
|
||||
|
||||
public function create($entityName)
|
||||
{
|
||||
$className = '\\Espo\\Custom\\SelectManagers\\' . Util::normilizeClassName($entityName);
|
||||
$normalizedName = Util::normilizeClassName($entityName);
|
||||
|
||||
$className = '\\Espo\\Custom\\SelectManagers\\' . $normalizedName;
|
||||
if (!class_exists($className)) {
|
||||
$moduleName = $this->metadata->getScopeModuleName($entityName);
|
||||
if ($moduleName) {
|
||||
$className = '\\Espo\\Modules\\' . $moduleName . '\\SelectManagers\\' . Util::normilizeClassName($entityName);
|
||||
$className = '\\Espo\\Modules\\' . $moduleName . '\\SelectManagers\\' . $normalizedName;
|
||||
} else {
|
||||
$className = '\\Espo\\SelectManagers\\' . Util::normilizeClassName($entityName);
|
||||
}
|
||||
$className = '\\Espo\\SelectManagers\\' . $normalizedName;
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -42,6 +42,8 @@ class Base
|
||||
|
||||
private $seed = null;
|
||||
|
||||
private $userTimeZone = null;
|
||||
|
||||
const MIN_LENGTH_FOR_CONTENT_SEARCH = 4;
|
||||
|
||||
public function __construct($entityManager, \Espo\Entities\User $user, Acl $acl, $metadata)
|
||||
@@ -49,9 +51,20 @@ class Base
|
||||
$this->entityManager = $entityManager;
|
||||
$this->user = $user;
|
||||
$this->acl = $acl;
|
||||
|
||||
$this->metadata = $metadata;
|
||||
}
|
||||
|
||||
protected function getEntityManager()
|
||||
{
|
||||
return $this->entityManager;
|
||||
}
|
||||
|
||||
protected function getUser()
|
||||
{
|
||||
return $this->user;
|
||||
}
|
||||
|
||||
public function setEntityName($entityName)
|
||||
{
|
||||
$this->entityName = $entityName;
|
||||
@@ -100,47 +113,53 @@ class Base
|
||||
return $this->seed;
|
||||
}
|
||||
|
||||
protected function textFilter($value, &$result)
|
||||
{
|
||||
$fieldDefs = $this->getSeed()->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 . '*'] = '%' . $value . '%';
|
||||
} else {
|
||||
$d[$field . '*'] = $value . '%';
|
||||
}
|
||||
}
|
||||
$result['whereClause'][] = array(
|
||||
'OR' => $d
|
||||
);
|
||||
}
|
||||
|
||||
protected function where($params, &$result)
|
||||
{
|
||||
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'])) {
|
||||
if ($item['type'] == 'bool' && !empty($item['value']) && is_array($item['value'])) {
|
||||
foreach ($item['value'] as $filter) {
|
||||
$p = $this->getBoolFilterWhere($filter);
|
||||
if (!empty($p)) {
|
||||
$params['where'][] = $p;
|
||||
}
|
||||
$this->boolFilter($filter, $result);
|
||||
}
|
||||
} else if ($item['type'] == 'textFilter' && !empty($item['value'])) {
|
||||
if (!empty($item['value'])) {
|
||||
if (empty($result['whereClause'])) {
|
||||
$result['whereClause'] = array();
|
||||
}
|
||||
$fieldDefs = $this->getSeed()->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[] = array(
|
||||
'OR' => $d
|
||||
);
|
||||
$this->textFilter($item['value'], $result);
|
||||
}
|
||||
} else if ($item['type'] == 'primary' && !empty($item['value'])) {
|
||||
$this->primaryFilter($item['value'], $result);
|
||||
}
|
||||
}
|
||||
|
||||
$linkedWith = array();
|
||||
$ignoreList = array('linkedWith', 'boolFilters');
|
||||
$ignoreList = array('linkedWith', 'bool', 'primary');
|
||||
foreach ($params['where'] as $item) {
|
||||
if (!in_array($item['type'], $ignoreList)) {
|
||||
$part = $this->getWherePart($item);
|
||||
@@ -171,7 +190,7 @@ class Base
|
||||
$joins[] = $link;
|
||||
if (!empty($defs['relationName']) && !empty($defs['midKeys'])) {
|
||||
$key = $defs['midKeys'][1];
|
||||
$relationName = $defs['relationName'];
|
||||
$relationName = lcfirst($defs['relationName']);
|
||||
$part[$relationName . '.' . $key] = $idsValue;
|
||||
}
|
||||
} else if ($defs['type'] == 'belongsTo') {
|
||||
@@ -191,17 +210,13 @@ class Base
|
||||
|
||||
}
|
||||
|
||||
$result['whereClause'] = $where;
|
||||
$result['whereClause'] = array_merge($result['whereClause'], $where);
|
||||
}
|
||||
}
|
||||
|
||||
protected function q($params, &$result)
|
||||
{
|
||||
if (!empty($params['q'])) {
|
||||
if (empty($result['whereClause'])) {
|
||||
$result['whereClause'] = array();
|
||||
}
|
||||
|
||||
$fieldDefs = $this->getSeed()->getFields();
|
||||
|
||||
$value = $params['q'];
|
||||
@@ -229,33 +244,40 @@ class Base
|
||||
protected function access(&$result)
|
||||
{
|
||||
if ($this->acl->checkReadOnlyOwn($this->entityName)) {
|
||||
|
||||
if (!array_key_exists('whereClause', $result)) {
|
||||
$result['whereClause'] = array();
|
||||
}
|
||||
$result['whereClause']['assignedUserId'] = $this->user->id;
|
||||
$this->accessOnlyOwn($result);
|
||||
}
|
||||
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'][] = array(
|
||||
'OR' => array(
|
||||
'Team.id' => $this->user->get('teamsIds'),
|
||||
'assignedUserId' => $this->user->id
|
||||
)
|
||||
);
|
||||
$this->accessOnlyTeam($result);
|
||||
}
|
||||
}
|
||||
|
||||
protected function accessOnlyOwn(&$result)
|
||||
{
|
||||
if (!$this->getSeed()->hasField('assignedUserId')) {
|
||||
return;
|
||||
}
|
||||
$result['whereClause'][] = array(
|
||||
'assignedUserId' => $this->getUser()->id
|
||||
);
|
||||
}
|
||||
|
||||
protected function accessOnlyTeam(&$result)
|
||||
{
|
||||
if (!$this->getSeed()->hasField('teamsIds')) {
|
||||
return;
|
||||
}
|
||||
$result['distinct'] = true;
|
||||
if (!in_array('teams', $result['joins'])) {
|
||||
$result['leftJoins'][] = 'teams';
|
||||
}
|
||||
$result['whereClause'][] = array(
|
||||
'OR' => array(
|
||||
'teams.id' => $this->user->get('teamsIds'),
|
||||
'assignedUserId' => $this->getUser()->id
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public function getAclParams()
|
||||
{
|
||||
$result = array();
|
||||
@@ -265,7 +287,11 @@ class Base
|
||||
|
||||
public function getSelectParams(array $params, $withAcl = false)
|
||||
{
|
||||
$result = array();
|
||||
$result = array(
|
||||
'joins' => array(),
|
||||
'leftJoins' => array(),
|
||||
'whereClause' => array()
|
||||
);
|
||||
|
||||
$this->order($params, $result);
|
||||
$this->limit($params, $result);
|
||||
@@ -279,10 +305,121 @@ class Base
|
||||
return $result;
|
||||
}
|
||||
|
||||
protected function getUserTimeZone()
|
||||
{
|
||||
if (empty($this->userTimeZone)) {
|
||||
$preferences = $this->getEntityManager()->getEntity('Preferences', $this->getUser()->id);
|
||||
$timeZone = $preferences->get('timeZone');
|
||||
$this->userTimeZone = $timeZone;
|
||||
}
|
||||
|
||||
return $this->userTimeZone;
|
||||
}
|
||||
|
||||
protected function convertDateTimeWhere($item)
|
||||
{
|
||||
$format = 'Y-m-d H:i:s';
|
||||
|
||||
$value = null;
|
||||
$timeZone = 'UTC';
|
||||
|
||||
if (empty($item['field'])) {
|
||||
return null;
|
||||
}
|
||||
if (empty($item['type'])) {
|
||||
return null;
|
||||
}
|
||||
if (!empty($item['value'])) {
|
||||
$value = $item['value'];
|
||||
}
|
||||
if (!empty($item['timeZone'])) {
|
||||
$timeZone = $item['timeZone'];
|
||||
}
|
||||
$type = $item['type'];
|
||||
$field = $item['field'];
|
||||
|
||||
if (empty($value) && in_array($type, array('on', 'before', 'after'))) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$where = array();
|
||||
$where['field'] = $field;
|
||||
|
||||
$dt = new \DateTime('now', new \DateTimeZone($timeZone));
|
||||
|
||||
switch ($type) {
|
||||
case 'today':
|
||||
$where['type'] = 'between';
|
||||
$dt->setTime(0, 0, 0);
|
||||
$dt->setTimezone(new \DateTimeZone('UTC'));
|
||||
$from = $dt->format($format);
|
||||
$dt->modify('+1 day');
|
||||
$to = $dt->format($format);
|
||||
$where['value'] = [$from, $to];
|
||||
break;
|
||||
case 'past':
|
||||
$where['type'] = 'before';
|
||||
$dt->setTimezone(new \DateTimeZone('UTC'));
|
||||
$where['value'] = $dt->format($format);
|
||||
break;
|
||||
case 'future':
|
||||
$where['type'] = 'after';
|
||||
$dt->setTimezone(new \DateTimeZone('UTC'));
|
||||
$where['value'] = $dt->format($format);
|
||||
break;
|
||||
case 'on':
|
||||
$where['type'] = 'between';
|
||||
|
||||
$dt = new \DateTime($value, new \DateTimeZone($timeZone));
|
||||
$dt->setTimezone(new \DateTimeZone('UTC'));
|
||||
$from = $dt->format($format);
|
||||
|
||||
$dt->modify('+1 day');
|
||||
$to = $dt->format($format);
|
||||
$where['value'] = [$from, $to];
|
||||
break;
|
||||
case 'before':
|
||||
$where['type'] = 'before';
|
||||
$dt = new \DateTime($value, new \DateTimeZone($timeZone));
|
||||
$dt->setTimezone(new \DateTimeZone('UTC'));
|
||||
$where['value'] = $dt->format($format);
|
||||
break;
|
||||
case 'after':
|
||||
$where['type'] = 'after';
|
||||
$dt = new \DateTime($value, new \DateTimeZone($timeZone));
|
||||
$dt->setTimezone(new \DateTimeZone('UTC'));
|
||||
$where['value'] = $dt->format($format);
|
||||
break;
|
||||
case 'between':
|
||||
$where['type'] = 'between';
|
||||
if (is_array($value)) {
|
||||
$dt = new \DateTime($value[0], new \DateTimeZone($timeZone));
|
||||
$dt->setTimezone(new \DateTimeZone('UTC'));
|
||||
$from = $dt->format($format);
|
||||
|
||||
$dt = new \DateTime($value[1], new \DateTimeZone($timeZone));
|
||||
$dt->setTimezone(new \DateTimeZone('UTC'));
|
||||
$to = $dt->format($format);
|
||||
|
||||
$where['value'] = [$from, $to];
|
||||
}
|
||||
break;
|
||||
default:
|
||||
$where['type'] = $type;
|
||||
}
|
||||
$result = $this->getWherePart($where);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
protected function getWherePart($item)
|
||||
{
|
||||
$part = array();
|
||||
|
||||
if (!empty($item['dateTime'])) {
|
||||
return $this->convertDateTimeWhere($item);
|
||||
}
|
||||
|
||||
if (!empty($item['type'])) {
|
||||
switch ($item['type']) {
|
||||
case 'or':
|
||||
@@ -344,7 +481,7 @@ class Base
|
||||
$part[$item['field'] . '<'] = date('Y-m-d');
|
||||
break;
|
||||
case 'future':
|
||||
$part[$item['field'] . '>'] = date('Y-m-d');
|
||||
$part[$item['field'] . '>='] = date('Y-m-d');
|
||||
break;
|
||||
case 'currentMonth':
|
||||
$dt = new \DateTime();
|
||||
@@ -411,6 +548,22 @@ class Base
|
||||
return $part;
|
||||
}
|
||||
|
||||
protected function boolFilter($filterName, &$result)
|
||||
{
|
||||
$method = 'boolFilter' . ucfirst($filterName);
|
||||
if (method_exists($this, $method)) {
|
||||
$this->$method($result);
|
||||
}
|
||||
}
|
||||
|
||||
protected function primaryFilter($filterName, &$result)
|
||||
{
|
||||
$method = 'filter' . ucfirst($filterName);
|
||||
if (method_exists($this, $method)) {
|
||||
$this->$method($result);
|
||||
}
|
||||
}
|
||||
|
||||
protected function getBoolFilterWhere($filterName)
|
||||
{
|
||||
$method = 'getBoolFilterWhere' . ucfirst($filterName);
|
||||
@@ -419,12 +572,10 @@ class Base
|
||||
}
|
||||
}
|
||||
|
||||
protected function getBoolFilterWhereOnlyMy()
|
||||
protected function boolFilterOnlyMy(&$result)
|
||||
{
|
||||
return array(
|
||||
'type' => 'equals',
|
||||
'field' => 'assignedUserId',
|
||||
'value' => $this->user->id,
|
||||
$result['whereClause'][] = array(
|
||||
'assignedUserId' => $this->getUser()->id
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,31 +48,6 @@ class ServiceFactory
|
||||
$this->container = $container;
|
||||
}
|
||||
|
||||
protected function init()
|
||||
{
|
||||
$config = $this->getContainer()->get('config');
|
||||
|
||||
if (file_exists($this->cacheFile) && $config->get('useCache')) {
|
||||
$this->data = $this->getFileManager()->getPhpContents($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));
|
||||
}
|
||||
|
||||
$this->data = array_merge($this->data, $this->getClassNameHash($this->paths['customPath']));
|
||||
|
||||
if ($config->get('useCache')) {
|
||||
$result = $this->getFileManager()->putPhpContents($this->cacheFile, $this->data);
|
||||
if ($result == false) {
|
||||
throw new \Espo\Core\Exceptions\Error();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected function getFileManager()
|
||||
{
|
||||
return $this->container->get('fileManager');
|
||||
@@ -83,15 +58,19 @@ class ServiceFactory
|
||||
return $this->container;
|
||||
}
|
||||
|
||||
protected function init()
|
||||
{
|
||||
$classParser = $this->getContainer()->get('classParser');
|
||||
$classParser->setAllowedMethods(null);
|
||||
$this->data = $classParser->getData($this->paths, $this->cacheFile);
|
||||
}
|
||||
|
||||
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];
|
||||
}
|
||||
@@ -127,28 +106,5 @@ class ServiceFactory
|
||||
}
|
||||
throw new Error("Class '$className' does not exist");
|
||||
}
|
||||
|
||||
// TODO delegate to another class
|
||||
protected function getClassNameHash($dirs)
|
||||
{
|
||||
if (is_string($dirs)) {
|
||||
$dirs = (array) $dirs;
|
||||
}
|
||||
|
||||
$data = array();
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -53,6 +53,11 @@ abstract class Base implements Injectable
|
||||
return $this->injections[$name];
|
||||
}
|
||||
|
||||
protected function addDependency($name)
|
||||
{
|
||||
$this->dependencies[] = $name;
|
||||
}
|
||||
|
||||
public function getDependencyList()
|
||||
{
|
||||
return $this->dependencies;
|
||||
|
||||
30
application/Espo/Core/Templates/Controllers/Base.php
Normal file
30
application/Espo/Core/Templates/Controllers/Base.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM - Open Source CRM application.
|
||||
* Copyright (C) 2014-2015 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\Templates\Controllers;
|
||||
|
||||
|
||||
class Base extends \Espo\Core\Controllers\Record
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
30
application/Espo/Core/Templates/Controllers/Person.php
Normal file
30
application/Espo/Core/Templates/Controllers/Person.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM - Open Source CRM application.
|
||||
* Copyright (C) 2014-2015 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\Templates\Controllers;
|
||||
|
||||
|
||||
class Person extends \Espo\Core\Controllers\Record
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
29
application/Espo/Core/Templates/Entities/Base.php
Normal file
29
application/Espo/Core/Templates/Entities/Base.php
Normal file
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM - Open Source CRM application.
|
||||
* Copyright (C) 2014-2015 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\Templates\Entities;
|
||||
|
||||
class Base extends \Espo\Core\ORM\Entity
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
29
application/Espo/Core/Templates/Entities/Person.php
Normal file
29
application/Espo/Core/Templates/Entities/Person.php
Normal file
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM - Open Source CRM application.
|
||||
* Copyright (C) 2014-2015 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\Templates\Entities;
|
||||
|
||||
class Person extends \Espo\Core\Entities\Person
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"controller": "Controllers.Record",
|
||||
"boolFilterList": ["onlyMy"]
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
{
|
||||
"fields": {
|
||||
"name": {
|
||||
"type": "varchar",
|
||||
"required": true
|
||||
},
|
||||
"description": {
|
||||
"type": "text"
|
||||
},
|
||||
"createdAt": {
|
||||
"type": "datetime",
|
||||
"readOnly": true
|
||||
},
|
||||
"modifiedAt": {
|
||||
"type": "datetime",
|
||||
"readOnly": true
|
||||
},
|
||||
"createdBy": {
|
||||
"type": "link",
|
||||
"readOnly": true
|
||||
},
|
||||
"modifiedBy": {
|
||||
"type": "link",
|
||||
"readOnly": true
|
||||
},
|
||||
"assignedUser": {
|
||||
"type": "link",
|
||||
"required": true
|
||||
},
|
||||
"teams": {
|
||||
"type": "linkMultiple"
|
||||
}
|
||||
},
|
||||
"links": {
|
||||
"createdBy": {
|
||||
"type": "belongsTo",
|
||||
"entity": "User"
|
||||
},
|
||||
"modifiedBy": {
|
||||
"type": "belongsTo",
|
||||
"entity": "User"
|
||||
},
|
||||
"assignedUser": {
|
||||
"type": "belongsTo",
|
||||
"entity": "User"
|
||||
},
|
||||
"teams": {
|
||||
"type": "hasMany",
|
||||
"entity": "Team",
|
||||
"relationName": "EntityTeam",
|
||||
"layoutRelationshipsDisabled": true
|
||||
}
|
||||
},
|
||||
"collection": {
|
||||
"sortBy": "createdAt",
|
||||
"asc": false
|
||||
},
|
||||
"indexes": {
|
||||
"name": {
|
||||
"columns": ["name", "deleted"]
|
||||
},
|
||||
"assignedUser": {
|
||||
"columns": ["assignedUserId", "deleted"]
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"controller": "Controllers.Record",
|
||||
"boolFilterList": ["onlyMy"]
|
||||
}
|
||||
111
application/Espo/Core/Templates/Metadata/Person/entityDefs.json
Normal file
111
application/Espo/Core/Templates/Metadata/Person/entityDefs.json
Normal file
@@ -0,0 +1,111 @@
|
||||
{
|
||||
"fields": {
|
||||
"name": {
|
||||
"type": "personName"
|
||||
},
|
||||
"salutationName": {
|
||||
"type": "enum",
|
||||
"options": ["", "Mr.", "Mrs.", "Ms.", "Dr."]
|
||||
},
|
||||
"firstName": {
|
||||
"type": "varchar",
|
||||
"maxLength": 100,
|
||||
"default": ""
|
||||
},
|
||||
"lastName": {
|
||||
"type": "varchar",
|
||||
"maxLength": 100,
|
||||
"required": true,
|
||||
"default": ""
|
||||
},
|
||||
"description": {
|
||||
"type": "text"
|
||||
},
|
||||
"createdAt": {
|
||||
"type": "datetime",
|
||||
"readOnly": true
|
||||
},
|
||||
"emailAddress": {
|
||||
"type": "email"
|
||||
},
|
||||
"phoneNumber": {
|
||||
"type": "phone",
|
||||
"typeList": ["Mobile", "Office", "Home", "Fax", "Other"],
|
||||
"defaultType": "Mobile"
|
||||
},
|
||||
"address": {
|
||||
"type": "address"
|
||||
},
|
||||
"addressStreet": {
|
||||
"type": "text",
|
||||
"maxLength": 255,
|
||||
"dbType": "varchar"
|
||||
},
|
||||
"addressCity": {
|
||||
"type": "varchar"
|
||||
},
|
||||
"addressState": {
|
||||
"type": "varchar"
|
||||
},
|
||||
"addressCountry": {
|
||||
"type": "varchar"
|
||||
},
|
||||
"addressPostalCode": {
|
||||
"type": "varchar"
|
||||
},
|
||||
"modifiedAt": {
|
||||
"type": "datetime",
|
||||
"readOnly": true
|
||||
},
|
||||
"createdBy": {
|
||||
"type": "link",
|
||||
"readOnly": true
|
||||
},
|
||||
"modifiedBy": {
|
||||
"type": "link",
|
||||
"readOnly": true
|
||||
},
|
||||
"assignedUser": {
|
||||
"type": "link",
|
||||
"required": true
|
||||
},
|
||||
"teams": {
|
||||
"type": "linkMultiple"
|
||||
}
|
||||
},
|
||||
"links": {
|
||||
"createdBy": {
|
||||
"type": "belongsTo",
|
||||
"entity": "User"
|
||||
},
|
||||
"modifiedBy": {
|
||||
"type": "belongsTo",
|
||||
"entity": "User"
|
||||
},
|
||||
"assignedUser": {
|
||||
"type": "belongsTo",
|
||||
"entity": "User"
|
||||
},
|
||||
"teams": {
|
||||
"type": "hasMany",
|
||||
"entity": "Team",
|
||||
"relationName": "EntityTeam",
|
||||
"layoutRelationshipsDisabled": true
|
||||
}
|
||||
},
|
||||
"collection": {
|
||||
"sortBy": "createdAt",
|
||||
"asc": false
|
||||
},
|
||||
"indexes": {
|
||||
"firstName": {
|
||||
"columns": ["firstName", "deleted"]
|
||||
},
|
||||
"name": {
|
||||
"columns": ["firstName", "lastName"]
|
||||
},
|
||||
"assignedUser": {
|
||||
"columns": ["assignedUserId", "deleted"]
|
||||
}
|
||||
}
|
||||
}
|
||||
30
application/Espo/Core/Templates/Repositories/Base.php
Normal file
30
application/Espo/Core/Templates/Repositories/Base.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM - Open Source CRM application.
|
||||
* Copyright (C) 2014-2015 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\Templates\Repositories;
|
||||
|
||||
|
||||
class Base extends \Espo\Core\ORM\Repositories\RDB
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
30
application/Espo/Core/Templates/Repositories/Person.php
Normal file
30
application/Espo/Core/Templates/Repositories/Person.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM - Open Source CRM application.
|
||||
* Copyright (C) 2014-2015 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\Templates\Repositories;
|
||||
|
||||
|
||||
class Person extends \Espo\Core\ORM\Repositories\RDB
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
30
application/Espo/Core/Templates/Services/Base.php
Normal file
30
application/Espo/Core/Templates/Services/Base.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM - Open Source CRM application.
|
||||
* Copyright (C) 2014-2015 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\Templates\Services;
|
||||
|
||||
|
||||
class Base extends \Espo\Services\Record
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
30
application/Espo/Core/Templates/Services/Person.php
Normal file
30
application/Espo/Core/Templates/Services/Person.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM - Open Source CRM application.
|
||||
* Copyright (C) 2014-2015 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\Templates\Services;
|
||||
|
||||
|
||||
class Person extends \Espo\Services\Record
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@@ -30,6 +30,7 @@ class UpgradeManager extends Upgrades\Base
|
||||
|
||||
protected $params = array(
|
||||
'packagePath' => 'data/upload/upgrades',
|
||||
'backupPath' => 'data/.backup/upgrades',
|
||||
|
||||
'scriptNames' => array(
|
||||
'before' => 'BeforeUpgrade',
|
||||
|
||||
@@ -22,9 +22,11 @@
|
||||
|
||||
namespace Espo\Core\Upgrades\Actions;
|
||||
|
||||
use Espo\Core\Utils\Util,
|
||||
Espo\Core\Utils\Json,
|
||||
Espo\Core\Exceptions\Error;
|
||||
use Espo\Core\Utils\Util;
|
||||
use Espo\Core\Utils\System;
|
||||
use Espo\Core\Utils\Json;
|
||||
use Espo\Core\Exceptions\Error;
|
||||
use vierbergenlars\SemVer;
|
||||
|
||||
abstract class Base
|
||||
{
|
||||
@@ -32,6 +34,8 @@ abstract class Base
|
||||
|
||||
private $entityManager;
|
||||
|
||||
private $helper;
|
||||
|
||||
protected $data;
|
||||
|
||||
protected $params = null;
|
||||
@@ -129,7 +133,7 @@ abstract class Base
|
||||
return $this->config;
|
||||
}
|
||||
|
||||
protected function getEntityManager()
|
||||
public function getEntityManager()
|
||||
{
|
||||
if (!isset($this->entityManager)) {
|
||||
$this->entityManager = $this->getContainer()->get('entityManager');
|
||||
@@ -179,46 +183,60 @@ abstract class Base
|
||||
*/
|
||||
protected function isAcceptable()
|
||||
{
|
||||
$manifest = $this->getManifest();
|
||||
|
||||
$res = $this->checkPackageType();
|
||||
$res &= $this->checkVersions();
|
||||
|
||||
//check php version
|
||||
if (isset($manifest['php'])) {
|
||||
$res &= $this->checkVersions($manifest['php'], System::getPhpVersion(), 'Your PHP version does not support this installation package.');
|
||||
}
|
||||
|
||||
//check acceptableVersions
|
||||
if (isset($manifest['acceptableVersions'])) {
|
||||
$res &= $this->checkVersions($manifest['acceptableVersions'], $this->getConfig()->get('version'), 'Your EspoCRM version doesn\'t match for this installation package.');
|
||||
}
|
||||
|
||||
//check dependencies
|
||||
if (!empty($manifest['dependencies'])) {
|
||||
$res &= $this->checkDependencies($manifest['dependencies']);
|
||||
}
|
||||
|
||||
return (bool) $res;
|
||||
}
|
||||
|
||||
protected function checkVersions()
|
||||
public function checkVersions($versionList, $currentVersion, $errorMessage = '')
|
||||
{
|
||||
$manifest = $this->getManifest();
|
||||
|
||||
/** check acceptable versions */
|
||||
$version = $manifest['acceptableVersions'];
|
||||
if (empty($version)) {
|
||||
if (empty($versionList)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$currentVersion = $this->getConfig()->get('version');
|
||||
|
||||
if (is_string($version)) {
|
||||
$version = (array) $version;
|
||||
if (is_string($versionList)) {
|
||||
$versionList = (array) $versionList;
|
||||
}
|
||||
|
||||
foreach ($version as $strVersion) {
|
||||
try {
|
||||
$semver = new SemVer\version($currentVersion);
|
||||
} catch (\Exception $e) {
|
||||
$GLOBALS['log']->error('Cannot recognize currentVersion ['.$currentVersion.'], error: '.$e->getMessage().'.');
|
||||
return false;
|
||||
}
|
||||
|
||||
$strVersion = trim($strVersion);
|
||||
foreach ($versionList as $version) {
|
||||
|
||||
if ($strVersion == $currentVersion) {
|
||||
return true;
|
||||
$isInRange = false;
|
||||
try {
|
||||
$isInRange = $semver->satisfies(new SemVer\expression($version));
|
||||
} catch (\Exception $e) {
|
||||
$GLOBALS['log']->error('Version identification error: '.$e->getMessage().'.');
|
||||
}
|
||||
|
||||
$strVersion = str_replace('\\', '', $strVersion);
|
||||
$strVersion = preg_quote($strVersion);
|
||||
$strVersion = str_replace('\\*', '+', $strVersion);
|
||||
|
||||
if (preg_match('/^'.$strVersion.'/', $currentVersion)) {
|
||||
if ($isInRange) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
$this->throwErrorAndRemovePackage('Your EspoCRM version doesn\'t match for this installation package.');
|
||||
$this->throwErrorAndRemovePackage($errorMessage);
|
||||
}
|
||||
|
||||
protected function checkPackageType()
|
||||
@@ -240,6 +258,11 @@ abstract class Base
|
||||
return true;
|
||||
}
|
||||
|
||||
protected function checkDependencies($dependencyList)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Run scripts by type
|
||||
* @param string $type Ex. "before", "after"
|
||||
@@ -293,7 +316,7 @@ abstract class Base
|
||||
/**
|
||||
* Get a list of files defined in manifest.json
|
||||
*
|
||||
* @return [type] [description]
|
||||
* @return array
|
||||
*/
|
||||
protected function getDeleteFileList()
|
||||
{
|
||||
@@ -341,6 +364,18 @@ abstract class Base
|
||||
return $this->data['fileList'];
|
||||
}
|
||||
|
||||
protected function getRestoreFileList()
|
||||
{
|
||||
if (!isset($this->data['restoreFileList'])) {
|
||||
$backupPath = $this->getPath('backupPath');
|
||||
$backupFilePath = Util::concatPath($backupPath, self::FILES);
|
||||
|
||||
$this->data['restoreFileList'] = $this->getFileManager()->getFileList($backupFilePath, true, '', true, true);
|
||||
}
|
||||
|
||||
return $this->data['restoreFileList'];
|
||||
}
|
||||
|
||||
protected function copy($sourcePath, $destPath, $recursively = false, array $fileList = null, $copyOnlyFiles = false)
|
||||
{
|
||||
try {
|
||||
@@ -467,18 +502,31 @@ abstract class Base
|
||||
/**
|
||||
* Execute an action. For ex., execute uninstall action in install
|
||||
*
|
||||
* @param [type] $actionName [description]
|
||||
* @param [type] $data [description]
|
||||
* @return [type] [description]
|
||||
* @param string $actionName
|
||||
* @param string $data
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function executeAction($actionName, $data)
|
||||
{
|
||||
$currentAction = $this->getActionManager()->getAction();
|
||||
$actionManager = $this->getActionManager();
|
||||
|
||||
$this->getActionManager()->setAction($actionName);
|
||||
$this->getActionManager()->run($data);
|
||||
$currentAction = $actionManager->getAction();
|
||||
|
||||
$actionManager->setAction($actionName);
|
||||
$actionManager->run($data);
|
||||
|
||||
$actionManager->setAction($currentAction);
|
||||
}
|
||||
|
||||
protected function initialize()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
protected function finalize()
|
||||
{
|
||||
|
||||
$this->getActionManager()->setAction($currentAction);
|
||||
}
|
||||
|
||||
protected function beforeRunAction()
|
||||
@@ -491,5 +539,38 @@ abstract class Base
|
||||
|
||||
}
|
||||
|
||||
protected function clearCache()
|
||||
{
|
||||
return $this->getContainer()->get('dataManager')->clearCache();
|
||||
}
|
||||
|
||||
}
|
||||
protected function checkIsWritable()
|
||||
{
|
||||
$fullFileList = array_merge($this->getDeleteFileList(), $this->getCopyFileList());
|
||||
|
||||
$result = $this->getFileManager()->isWritableList($fullFileList);
|
||||
if (!$result) {
|
||||
$permissionDeniedList = $this->getFileManager()->getLastPermissionDeniedList();
|
||||
throw new Error("Permission denied for <br>". implode(", <br>", $permissionDeniedList));
|
||||
}
|
||||
}
|
||||
|
||||
protected function backupExistingFiles()
|
||||
{
|
||||
$fullFileList = array_merge($this->getDeleteFileList(), $this->getCopyFileList());
|
||||
|
||||
$backupPath = $this->getPath('backupPath');
|
||||
return $this->copy('', array($backupPath, self::FILES), false, $fullFileList);
|
||||
}
|
||||
|
||||
protected function getHelper()
|
||||
{
|
||||
if (!isset($this->helper)) {
|
||||
$this->helper = new Helper();
|
||||
}
|
||||
|
||||
$this->helper->setActionObject($this);
|
||||
|
||||
return $this->helper;
|
||||
}
|
||||
}
|
||||
@@ -24,14 +24,18 @@ namespace Espo\Core\Upgrades\Actions\Base;
|
||||
|
||||
class Delete extends \Espo\Core\Upgrades\Actions\Base
|
||||
{
|
||||
public function run($processId)
|
||||
public function run($data)
|
||||
{
|
||||
$processId = $data['id'];
|
||||
|
||||
$GLOBALS['log']->debug('Delete package process ['.$processId.']: start run.');
|
||||
|
||||
if (empty($processId)) {
|
||||
throw new Error('Delete package package ID was not specified.');
|
||||
}
|
||||
|
||||
$this->initialize();
|
||||
|
||||
$this->setProcessId($processId);
|
||||
|
||||
$this->beforeRunAction();
|
||||
@@ -41,6 +45,8 @@ class Delete extends \Espo\Core\Upgrades\Actions\Base
|
||||
|
||||
$this->afterRunAction();
|
||||
|
||||
$this->finalize();
|
||||
|
||||
$GLOBALS['log']->debug('Delete package process ['.$processId.']: end run.');
|
||||
}
|
||||
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
namespace Espo\Core\Upgrades\Actions\Base;
|
||||
|
||||
use Espo\Core\Exceptions\Error;
|
||||
use Espo\Core\Utils\Util;
|
||||
|
||||
class Install extends \Espo\Core\Upgrades\Actions\Base
|
||||
{
|
||||
@@ -39,8 +40,10 @@ class Install extends \Espo\Core\Upgrades\Actions\Base
|
||||
* @param string $processId Upgrade/Extension ID, gotten in upload stage
|
||||
* @return bool
|
||||
*/
|
||||
public function run($processId)
|
||||
public function run($data)
|
||||
{
|
||||
$processId = $data['id'];
|
||||
|
||||
$GLOBALS['log']->debug('Installation process ['.$processId.']: start run.');
|
||||
|
||||
if (empty($processId)) {
|
||||
@@ -49,6 +52,8 @@ class Install extends \Espo\Core\Upgrades\Actions\Base
|
||||
|
||||
$this->setProcessId($processId);
|
||||
|
||||
$this->initialize();
|
||||
|
||||
$this->isCopied = false;
|
||||
|
||||
/** check if an archive is unzipped, if no then unzip */
|
||||
@@ -58,22 +63,25 @@ class Install extends \Espo\Core\Upgrades\Actions\Base
|
||||
$this->isAcceptable();
|
||||
}
|
||||
|
||||
//check permissions copied and deleted files
|
||||
$this->checkIsWritable();
|
||||
|
||||
$this->backupExistingFiles();
|
||||
|
||||
$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;
|
||||
|
||||
/* remove files defined in a manifest */
|
||||
$this->deleteFiles(true);
|
||||
|
||||
if (!$this->systemRebuild()) {
|
||||
$this->throwErrorAndRemovePackage('Error occurred while EspoCRM rebuild.');
|
||||
}
|
||||
@@ -83,23 +91,37 @@ class Install extends \Espo\Core\Upgrades\Actions\Base
|
||||
|
||||
$this->afterRunAction();
|
||||
|
||||
$this->clearCache();
|
||||
|
||||
/* delete unziped files */
|
||||
$this->deletePackageFiles();
|
||||
|
||||
$this->finalize();
|
||||
|
||||
$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');
|
||||
if (!$this->isCopied) {
|
||||
return;
|
||||
}
|
||||
|
||||
$res &= $this->getFileManager()->removeInDir($backupPath, true);
|
||||
$GLOBALS['log']->info('Installer: Restore previous files.');
|
||||
|
||||
$backupPath = $this->getPath('backupPath');
|
||||
$backupFilePath = Util::concatPath($backupPath, self::FILES);
|
||||
|
||||
$backupFileList = $this->getRestoreFileList();
|
||||
$copyFileList = $this->getCopyFileList();
|
||||
$deleteFileList = array_diff($copyFileList, $backupFileList);
|
||||
|
||||
$res = $this->copy($backupFilePath, '', true);
|
||||
$res &= $this->getFileManager()->remove($deleteFileList, null, true);
|
||||
|
||||
if ($res) {
|
||||
$this->getFileManager()->removeInDir($backupPath, true);
|
||||
}
|
||||
|
||||
return $res;
|
||||
}
|
||||
|
||||
@@ -22,13 +22,16 @@
|
||||
|
||||
namespace Espo\Core\Upgrades\Actions\Base;
|
||||
|
||||
use Espo\Core\Exceptions\Error,
|
||||
Espo\Core\Utils\Util;
|
||||
use Espo\Core\Exceptions\Error;
|
||||
use Espo\Core\Utils\Util;
|
||||
use Espo\Core\Utils\Json;
|
||||
|
||||
class Uninstall extends \Espo\Core\Upgrades\Actions\Base
|
||||
{
|
||||
public function run($processId)
|
||||
public function run($data)
|
||||
{
|
||||
$processId = $data['id'];
|
||||
|
||||
$GLOBALS['log']->debug('Uninstallation process ['.$processId.']: start run.');
|
||||
|
||||
if (empty($processId)) {
|
||||
@@ -37,44 +40,50 @@ class Uninstall extends \Espo\Core\Upgrades\Actions\Base
|
||||
|
||||
$this->setProcessId($processId);
|
||||
|
||||
$this->initialize();
|
||||
|
||||
$this->checkIsWritable();
|
||||
|
||||
$this->beforeRunAction();
|
||||
|
||||
/* run before install script */
|
||||
$this->runScript('beforeUninstall');
|
||||
if (!isset($data['isNotRunScriptBefore']) || !$data['isNotRunScriptBefore']) {
|
||||
$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.');
|
||||
throw new $this->throwErrorAndRemovePackage('Cannot copy files.');
|
||||
}
|
||||
|
||||
/* remove extension files, saved in fileList */
|
||||
if (!$this->deleteFiles(true)) {
|
||||
throw new $this->throwErrorAndRemovePackage('Permission denied to delete files.');
|
||||
}
|
||||
}
|
||||
|
||||
if (!$this->systemRebuild()) {
|
||||
throw new Error('Error occurred while EspoCRM rebuild.');
|
||||
throw new $this->throwErrorAndRemovePackage('Error occurred while EspoCRM rebuild.');
|
||||
}
|
||||
|
||||
/* run before install script */
|
||||
$this->runScript('afterUninstall');
|
||||
/* run after uninstall script */
|
||||
if (!isset($data['isNotRunScriptAfter']) || !$data['isNotRunScriptAfter']) {
|
||||
$this->runScript('afterUninstall');
|
||||
}
|
||||
|
||||
$this->afterRunAction();
|
||||
|
||||
$this->clearCache();
|
||||
|
||||
/* delete backup files */
|
||||
$this->deletePackageFiles();
|
||||
|
||||
$GLOBALS['log']->debug('Uninstallation process ['.$processId.']: end run.');
|
||||
}
|
||||
$this->finalize();
|
||||
|
||||
protected function getDeleteFileList()
|
||||
{
|
||||
$extensionEntity = $this->getExtensionEntity();
|
||||
return $extensionEntity->get('fileList');
|
||||
$GLOBALS['log']->debug('Uninstallation process ['.$processId.']: end run.');
|
||||
}
|
||||
|
||||
protected function restoreFiles()
|
||||
@@ -87,6 +96,13 @@ class Uninstall extends \Espo\Core\Upgrades\Actions\Base
|
||||
}
|
||||
|
||||
$res = $this->copy($filesPath, '', true);
|
||||
|
||||
$manifestJson = $this->getFileManager()->getContents(array($packagePath, $this->manifestName));
|
||||
$manifest = Json::decode($manifestJson, true);
|
||||
if (!empty($manifest['delete'])) {
|
||||
$res &= $this->getFileManager()->remove($manifest['delete'], null, true);
|
||||
}
|
||||
|
||||
$res &= $this->getFileManager()->removeInDir($packagePath, true);
|
||||
|
||||
return $res;
|
||||
@@ -129,4 +145,41 @@ class Uninstall extends \Espo\Core\Upgrades\Actions\Base
|
||||
throw new Error($errorMessage);
|
||||
}
|
||||
|
||||
protected function getCopyFileList()
|
||||
{
|
||||
if (!isset($this->data['fileList'])) {
|
||||
$backupPath = $this->getPath('backupPath');
|
||||
$filesPath = Util::concatPath($backupPath, self::FILES);
|
||||
|
||||
$this->data['fileList'] = $this->getFileManager()->getFileList($filesPath, true, '', true, true);
|
||||
}
|
||||
|
||||
return $this->data['fileList'];
|
||||
}
|
||||
|
||||
protected function getRestoreFileList()
|
||||
{
|
||||
if (!isset($this->data['restoreFileList'])) {
|
||||
$packagePath = $this->getPackagePath();
|
||||
$filesPath = Util::concatPath($packagePath, self::FILES);
|
||||
|
||||
if (!file_exists($filesPath)) {
|
||||
$this->unzipArchive($packagePath);
|
||||
}
|
||||
|
||||
$this->data['restoreFileList'] = $this->getFileManager()->getFileList($filesPath, true, '', true, true);
|
||||
}
|
||||
|
||||
return $this->data['restoreFileList'];
|
||||
}
|
||||
|
||||
protected function getDeleteFileList()
|
||||
{
|
||||
$packageFileList = $this->getRestoreFileList();
|
||||
$backupFileList = $this->getCopyFileList();
|
||||
|
||||
$deleteFileList = array_diff($packageFileList, $backupFileList);
|
||||
|
||||
return $deleteFileList;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,6 +38,10 @@ class Upload extends \Espo\Core\Upgrades\Actions\Base
|
||||
|
||||
$GLOBALS['log']->debug('Installation process ['.$processId.']: start upload the package.');
|
||||
|
||||
$this->initialize();
|
||||
|
||||
$this->beforeRunAction();
|
||||
|
||||
$packagePath = $this->getPackagePath();
|
||||
$packageArchivePath = $this->getPackagePath(true);
|
||||
|
||||
@@ -55,6 +59,10 @@ class Upload extends \Espo\Core\Upgrades\Actions\Base
|
||||
|
||||
$this->isAcceptable();
|
||||
|
||||
$this->afterRunAction();
|
||||
|
||||
$this->finalize();
|
||||
|
||||
$GLOBALS['log']->debug('Installation process ['.$processId.']: end upload the package.');
|
||||
|
||||
return $processId;
|
||||
|
||||
@@ -35,29 +35,15 @@ class Delete extends \Espo\Core\Upgrades\Actions\Base\Delete
|
||||
*/
|
||||
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.');
|
||||
if (!isset($this->extensionEntity)) {
|
||||
$processId = $this->getProcessId();
|
||||
$this->extensionEntity = $this->getEntityManager()->getEntity('Extension', $processId);
|
||||
if (!isset($this->extensionEntity)) {
|
||||
throw new Error('Extension Entity not found.');
|
||||
}
|
||||
}
|
||||
$this->setExtensionEntity($extensionEntity);
|
||||
|
||||
return $this->extensionEntity;
|
||||
}
|
||||
|
||||
protected function afterRunAction()
|
||||
|
||||
@@ -37,8 +37,6 @@ class Install extends \Espo\Core\Upgrades\Actions\Base\Install
|
||||
$this->uninstallExtension();
|
||||
$this->deleteExtension();
|
||||
}
|
||||
|
||||
$this->copyExistingFiles();
|
||||
}
|
||||
|
||||
protected function afterRunAction()
|
||||
@@ -51,12 +49,11 @@ class Install extends \Espo\Core\Upgrades\Actions\Base\Install
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function copyExistingFiles()
|
||||
protected function backupExistingFiles()
|
||||
{
|
||||
$fileList = $this->getCopyFileList();
|
||||
$backupPath = $this->getPath('backupPath');
|
||||
parent::backupExistingFiles();
|
||||
|
||||
$res = $this->copy('', array($backupPath, self::FILES), false, $fileList);
|
||||
$backupPath = $this->getPath('backupPath');
|
||||
|
||||
/** copy scripts files */
|
||||
$packagePath = $this->getPackagePath();
|
||||
@@ -65,19 +62,6 @@ class Install extends \Espo\Core\Upgrades\Actions\Base\Install
|
||||
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();
|
||||
@@ -154,7 +138,7 @@ class Install extends \Espo\Core\Upgrades\Actions\Base\Install
|
||||
|
||||
$data = array(
|
||||
'id' => $this->getProcessId(),
|
||||
'name' => $manifest['name'],
|
||||
'name' => trim($manifest['name']),
|
||||
'isInstalled' => true,
|
||||
'version' => $manifest['version'],
|
||||
'fileList' => $fileList,
|
||||
@@ -187,8 +171,8 @@ class Install extends \Espo\Core\Upgrades\Actions\Base\Install
|
||||
* Throw an exception and remove package files.
|
||||
* Redeclared to prevent of deleting a package of installed extension.
|
||||
*
|
||||
* @param string $errorMessage [description]
|
||||
* @return [type] [description]
|
||||
* @param string $errorMessage
|
||||
* @return void
|
||||
*/
|
||||
protected function throwErrorAndRemovePackage($errorMessage = '')
|
||||
{
|
||||
@@ -208,7 +192,11 @@ class Install extends \Espo\Core\Upgrades\Actions\Base\Install
|
||||
{
|
||||
$extensionEntity = $this->getExtensionEntity();
|
||||
|
||||
$this->executeAction(ExtensionManager::UNINSTALL, $extensionEntity->get('id'));
|
||||
$this->executeAction(ExtensionManager::UNINSTALL, array(
|
||||
'id' => $extensionEntity->get('id'),
|
||||
'isNotRunScriptAfter' => true,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -220,10 +208,11 @@ class Install extends \Espo\Core\Upgrades\Actions\Base\Install
|
||||
{
|
||||
$extensionEntity = $this->getExtensionEntity();
|
||||
|
||||
$this->executeAction(ExtensionManager::DELETE, $extensionEntity->get('id'));
|
||||
$this->executeAction(ExtensionManager::DELETE, array('id' => $extensionEntity->get('id')));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
protected function checkDependencies($dependencyList)
|
||||
{
|
||||
return $this->getHelper()->checkDependencies($dependencyList);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,29 +35,15 @@ class Uninstall extends \Espo\Core\Upgrades\Actions\Base\Uninstall
|
||||
*/
|
||||
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.');
|
||||
if (!isset($this->extensionEntity)) {
|
||||
$processId = $this->getProcessId();
|
||||
$this->extensionEntity = $this->getEntityManager()->getEntity('Extension', $processId);
|
||||
if (!isset($this->extensionEntity)) {
|
||||
throw new Error('Extension Entity not found.');
|
||||
}
|
||||
}
|
||||
$this->setExtensionEntity($extensionEntity);
|
||||
|
||||
return $this->extensionEntity;
|
||||
}
|
||||
|
||||
protected function afterRunAction()
|
||||
@@ -68,4 +54,14 @@ class Uninstall extends \Espo\Core\Upgrades\Actions\Base\Uninstall
|
||||
$extensionEntity->set('isInstalled', false);
|
||||
$this->getEntityManager()->saveEntity($extensionEntity);
|
||||
}
|
||||
|
||||
protected function getRestoreFileList()
|
||||
{
|
||||
if (!isset($this->data['restoreFileList'])) {
|
||||
$extensionEntity = $this->getExtensionEntity();
|
||||
$this->data['restoreFileList'] = $extensionEntity->get('fileList');
|
||||
}
|
||||
|
||||
return $this->data['restoreFileList'];
|
||||
}
|
||||
}
|
||||
@@ -24,5 +24,8 @@ namespace Espo\Core\Upgrades\Actions\Extension;
|
||||
|
||||
class Upload extends \Espo\Core\Upgrades\Actions\Base\Upload
|
||||
{
|
||||
|
||||
protected function checkDependencies($dependencyList)
|
||||
{
|
||||
return $this->getHelper()->checkDependencies($dependencyList);
|
||||
}
|
||||
}
|
||||
77
application/Espo/Core/Upgrades/Actions/Helper.php
Normal file
77
application/Espo/Core/Upgrades/Actions/Helper.php
Normal file
@@ -0,0 +1,77 @@
|
||||
<?php
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM - Open Source CRM application.
|
||||
* Copyright (C) 2014-2015 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\Exceptions\Error;
|
||||
|
||||
class Helper
|
||||
{
|
||||
private $actionObject;
|
||||
|
||||
public function __construct($actionObject = null)
|
||||
{
|
||||
if (isset($actionObject)) {
|
||||
$this->setActionObject($actionObject);
|
||||
}
|
||||
}
|
||||
|
||||
public function setActionObject(\Espo\Core\Upgrades\Actions\Base $actionObject)
|
||||
{
|
||||
$this->actionObject = $actionObject;
|
||||
}
|
||||
|
||||
protected function getActionObject()
|
||||
{
|
||||
return $this->actionObject;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check dependencies
|
||||
*
|
||||
* @param array | string $dependencyList
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function checkDependencies($dependencyList)
|
||||
{
|
||||
if (!is_array($dependencyList)) {
|
||||
$dependencyList = (array) $dependencyList;
|
||||
}
|
||||
|
||||
$actionObject = $this->getActionObject();
|
||||
|
||||
foreach ($dependencyList as $extensionName => $extensionVersion) {
|
||||
$dependencyExtensionEntity = $actionObject->getEntityManager()->getRepository('Extension')->where(array(
|
||||
'name' => trim($extensionName),
|
||||
'isInstalled' => true,
|
||||
))->findOne();
|
||||
|
||||
$errorMessage = 'Dependency Error: The extension "'.$extensionName.'" with version "'.$extensionVersion.'" is missing.';
|
||||
if (!isset($dependencyExtensionEntity) || !$actionObject->checkVersions($extensionVersion, $dependencyExtensionEntity->get('version'), $errorMessage)) {
|
||||
throw new Error($errorMessage);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -24,17 +24,12 @@ namespace Espo\Core\Upgrades\Actions\Upgrade;
|
||||
|
||||
class Install extends \Espo\Core\Upgrades\Actions\Base\Install
|
||||
{
|
||||
protected function systemRebuild()
|
||||
protected function finalize()
|
||||
{
|
||||
$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;
|
||||
$this->getConfig()->set('version', $manifest['version']);
|
||||
$this->getConfig()->save();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -67,7 +67,9 @@ class Output
|
||||
$currentRoute = $this->getSlim()->router()->getCurrentRoute();
|
||||
|
||||
if (isset($currentRoute)) {
|
||||
$GLOBALS['log']->error('API ['.$this->getSlim()->request()->getMethod().']:'.$currentRoute->getPattern().', Params:'.print_r($currentRoute->getParams(), true).', InputData: '.$this->getSlim()->request()->getBody().' - '.$message);
|
||||
$inputData = $this->getSlim()->request()->getBody();
|
||||
$inputData = $this->clearPasswords($inputData);
|
||||
$GLOBALS['log']->error('API ['.$this->getSlim()->request()->getMethod().']:'.$currentRoute->getPattern().', Params:'.print_r($currentRoute->getParams(), true).', InputData: '.$inputData.' - '.$message);
|
||||
}
|
||||
|
||||
$this->displayError($message, $code, $isPrint);
|
||||
@@ -118,5 +120,17 @@ class Output
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear passwords for inputData
|
||||
*
|
||||
* @param string $inputData
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function clearPasswords($inputData)
|
||||
{
|
||||
return preg_replace('/"(.*?password.*?)":".*?"/i', '"$1":"*****"', $inputData);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
namespace Espo\Core\Utils;
|
||||
|
||||
use \Espo\Core\Exceptions\Error;
|
||||
use \Espo\Core\Exceptions\Forbidden;
|
||||
|
||||
class Auth
|
||||
{
|
||||
@@ -44,6 +45,8 @@ class Auth
|
||||
$authenticationMethod = $this->config->get('authenticationMethod', 'Espo');
|
||||
$authenticationClassName = "\\Espo\\Core\\Utils\\Authentication\\" . $authenticationMethod;
|
||||
$this->authentication = new $authenticationClassName($this->config, $this->entityManager, $this);
|
||||
|
||||
$this->request = $this->container->get('slim')->request();
|
||||
}
|
||||
|
||||
public function useNoAuth($isAdmin = false)
|
||||
@@ -63,8 +66,6 @@ class Auth
|
||||
|
||||
public function login($username, $password)
|
||||
{
|
||||
$GLOBALS['log']->debug('AUTH: Try to authenticate');
|
||||
|
||||
$entityManager = $this->entityManager;
|
||||
|
||||
$authToken = $entityManager->getRepository('AuthToken')->where(array('token' => $password))->findOne();
|
||||
@@ -72,24 +73,28 @@ class Auth
|
||||
$user = $this->authentication->login($username, $password, $authToken);
|
||||
|
||||
if ($user) {
|
||||
if (!$user->isActive()) {
|
||||
$GLOBALS['log']->debug("AUTH: Trying to login as user '".$user->get('userName')."' which is not active.");
|
||||
return false;
|
||||
}
|
||||
$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);
|
||||
if ($this->request->headers->get('HTTP_ESPO_AUTHORIZATION')) {
|
||||
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'));
|
||||
}
|
||||
|
||||
$authToken->set('lastAccess', date('Y-m-d H:i:s'));
|
||||
|
||||
$entityManager->saveEntity($authToken);
|
||||
$user->set('token', $authToken->get('token'));
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -262,7 +262,7 @@ class Config
|
||||
}
|
||||
|
||||
if (empty($this->adminItems)) {
|
||||
$this->adminItems= Util::merge($data['systemItems'], $data['adminItems']);
|
||||
$this->adminItems = array_merge($data['systemItems'], $data['adminItems']);
|
||||
}
|
||||
|
||||
return $this->adminItems;
|
||||
|
||||
@@ -58,6 +58,7 @@ class Job
|
||||
{
|
||||
/** Mark Failed old jobs and remove pending duplicates */
|
||||
$this->markFailedJobs();
|
||||
$this->markJobAttempts();
|
||||
$this->removePendingJobDuplicates();
|
||||
|
||||
$jobList = $this->getActiveJobs();
|
||||
@@ -87,12 +88,11 @@ class Job
|
||||
$jobConfigs = $this->getConfig()->get('cron');
|
||||
|
||||
$currentTime = time();
|
||||
$periodTime = $currentTime - intval($jobConfigs['jobPeriod']);
|
||||
$limit = empty($jobConfigs['maxJobNumber']) ? '' : 'LIMIT '.$jobConfigs['maxJobNumber'];
|
||||
|
||||
$query = "SELECT " . $displayColumns . " FROM job WHERE
|
||||
`status` = '" . $status . "'
|
||||
AND execute_time BETWEEN '".date('Y-m-d H:i:s', $periodTime)."' AND '".date('Y-m-d H:i:s', $currentTime)."'
|
||||
AND execute_time <= '".date('Y-m-d H:i:s', $currentTime)."'
|
||||
AND deleted = 0
|
||||
ORDER BY execute_time ASC ".$limit;
|
||||
|
||||
@@ -109,15 +109,18 @@ class Job
|
||||
* Get Jobs by ScheduledJobId and date
|
||||
*
|
||||
* @param string $scheduledJobId
|
||||
* @param string $date
|
||||
* @param string $time
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getJobByScheduledJob($scheduledJobId, $date)
|
||||
public function getJobByScheduledJob($scheduledJobId, $time)
|
||||
{
|
||||
$dateObj = new \DateTime($time);
|
||||
$timeWithoutSeconds = $dateObj->format('Y-m-d H:i:');
|
||||
|
||||
$query = "SELECT * FROM job WHERE
|
||||
scheduled_job_id = '".$scheduledJobId."'
|
||||
AND execute_time = '".$date."'
|
||||
AND execute_time LIKE '".$timeWithoutSeconds."%'
|
||||
AND deleted = 0
|
||||
LIMIT 1";
|
||||
|
||||
@@ -143,7 +146,7 @@ class Job
|
||||
$periodTime = $currentTime - intval($jobConfigs['jobPeriod']);
|
||||
|
||||
$update = "UPDATE job SET `status` = '" . CronManager::FAILED ."' WHERE
|
||||
(`status` = '" . CronManager::PENDING ."' OR `status` = '" . CronManager::RUNNING ."')
|
||||
(`status` = '" . CronManager::RUNNING ."')
|
||||
AND execute_time < '".date('Y-m-d H:i:s', $periodTime)."' ";
|
||||
|
||||
$pdo = $this->getEntityManager()->getPDO();
|
||||
@@ -158,10 +161,22 @@ class Job
|
||||
*/
|
||||
protected function removePendingJobDuplicates()
|
||||
{
|
||||
$duplicateJobs = $this->getActiveJobs('DISTINCT scheduled_job_id');
|
||||
|
||||
$pdo = $this->getEntityManager()->getPDO();
|
||||
|
||||
$query = "SELECT scheduled_job_id FROM job
|
||||
WHERE
|
||||
scheduled_job_id IS NOT NULL
|
||||
AND `status` = '".CronManager::PENDING."'
|
||||
AND execute_time <= '".date('Y-m-d H:i:s')."'
|
||||
AND deleted = 0
|
||||
GROUP BY scheduled_job_id
|
||||
HAVING count( * ) > 1
|
||||
ORDER BY execute_time ASC";
|
||||
$sth = $pdo->prepare($query);
|
||||
$sth->execute();
|
||||
|
||||
$duplicateJobs = $sth->fetchAll(PDO::FETCH_ASSOC);
|
||||
|
||||
foreach ($duplicateJobs as $row) {
|
||||
if (!empty($row['scheduled_job_id'])) {
|
||||
|
||||
@@ -182,4 +197,41 @@ class Job
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Mark job attempts
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function markJobAttempts()
|
||||
{
|
||||
$query = "SELECT * FROM job WHERE
|
||||
`status` = '" . CronManager::FAILED . "'
|
||||
AND deleted = 0
|
||||
AND execute_time <= '".date('Y-m-d H:i:s')."'
|
||||
AND attempts > 0";
|
||||
|
||||
$pdo = $this->getEntityManager()->getPDO();
|
||||
$sth = $pdo->prepare($query);
|
||||
$sth->execute();
|
||||
|
||||
$rows = $sth->fetchAll(PDO::FETCH_ASSOC);
|
||||
if ($rows) {
|
||||
foreach ($rows as $row) {
|
||||
$row['failed_attempts'] = isset($row['failed_attempts']) ? $row['failed_attempts'] : 0;
|
||||
|
||||
$attempts = $row['attempts'] - 1;
|
||||
$failedAttempts = $row['failed_attempts'] + 1;
|
||||
|
||||
$update = "UPDATE job SET
|
||||
`status` = '" . CronManager::PENDING ."',
|
||||
attempts = '".$attempts."',
|
||||
failed_attempts = '".$failedAttempts."'
|
||||
WHERE
|
||||
id = '".$row['id']."'
|
||||
";
|
||||
$pdo->prepare($update)->execute();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -158,6 +158,7 @@ class Converter
|
||||
}
|
||||
|
||||
$ormMeta[$entityName]['fields'] = $this->convertFields($entityName, $entityMeta);
|
||||
$ormMeta = $this->correctFields($entityName, $ormMeta);
|
||||
|
||||
$convertedLinks = $this->convertLinks($entityName, $entityMeta, $ormMeta);
|
||||
|
||||
@@ -168,47 +169,6 @@ class Converter
|
||||
|
||||
public function afterProcess(array $ormMeta)
|
||||
{
|
||||
$entityDefs = $this->getEntityDefs();
|
||||
|
||||
$currentOrmMeta = $ormMeta;
|
||||
//load custom field definitions and customCodes
|
||||
foreach($currentOrmMeta as $entityName => $entityParams) {
|
||||
foreach($entityParams['fields'] as $fieldName => $fieldParams) {
|
||||
|
||||
//load custom field definitions
|
||||
$fieldType = ucfirst($fieldParams['type']);
|
||||
$className = '\Espo\Custom\Core\Utils\Database\Orm\Fields\\'.$fieldType;
|
||||
if (!class_exists($className)) {
|
||||
$className = '\Espo\Core\Utils\Database\Orm\Fields\\'.$fieldType;
|
||||
}
|
||||
|
||||
if (class_exists($className) && method_exists($className, 'load')) {
|
||||
$helperClass = new $className($this->metadata, $ormMeta, $entityDefs);
|
||||
$fieldResult = $helperClass->process( $fieldName, $entityName );
|
||||
if (isset($fieldResult['unset'])) {
|
||||
$ormMeta = Util::unsetInArray($ormMeta, $fieldResult['unset']);
|
||||
unset($fieldResult['unset']);
|
||||
}
|
||||
|
||||
$ormMeta = Util::merge($ormMeta, $fieldResult);
|
||||
|
||||
} //END: load custom field definitions
|
||||
|
||||
//todo move to separate file
|
||||
//add a field 'isFollowed' for scopes with 'stream => true'
|
||||
$scopeDefs = $this->getMetadata()->get('scopes.'.$entityName);
|
||||
if (isset($scopeDefs['stream']) && $scopeDefs['stream']) {
|
||||
if (!isset($entityParams['fields']['isFollowed'])) {
|
||||
$ormMeta[$entityName]['fields']['isFollowed'] = array(
|
||||
'type' => 'varchar',
|
||||
'notStorable' => true,
|
||||
);
|
||||
}
|
||||
} //END: add a field 'isFollowed' for stream => true
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
foreach($ormMeta as $entityName => &$entityParams) {
|
||||
foreach($entityParams['fields'] as $fieldName => &$fieldParams) {
|
||||
|
||||
@@ -226,7 +186,9 @@ class Converter
|
||||
|
||||
case 'foreignType':
|
||||
$fieldParams['dbType'] = Entity::VARCHAR;
|
||||
$fieldParams['len'] = $this->defaultLength['varchar'];
|
||||
if (empty($fieldParams['len'])) {
|
||||
$fieldParams['len'] = $this->defaultLength['varchar'];
|
||||
}
|
||||
break;
|
||||
|
||||
case 'bool':
|
||||
@@ -234,7 +196,6 @@ class Converter
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return $ormMeta;
|
||||
@@ -308,6 +269,56 @@ class Converter
|
||||
return $outputMeta;
|
||||
}
|
||||
|
||||
/**
|
||||
* Correct fields defenitions based on \Espo\Custom\Core\Utils\Database\Orm\Fields
|
||||
*
|
||||
* @param array $ormMeta
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function correctFields($entityName, array $ormMeta)
|
||||
{
|
||||
$entityDefs = $this->getEntityDefs();
|
||||
|
||||
$entityMeta = $ormMeta[$entityName];
|
||||
//load custom field definitions and customCodes
|
||||
foreach($entityMeta['fields'] as $fieldName => $fieldParams) {
|
||||
|
||||
//load custom field definitions
|
||||
$fieldType = ucfirst($fieldParams['type']);
|
||||
$className = '\Espo\Custom\Core\Utils\Database\Orm\Fields\\' . $fieldType;
|
||||
if (!class_exists($className)) {
|
||||
$className = '\Espo\Core\Utils\Database\Orm\Fields\\' . $fieldType;
|
||||
}
|
||||
|
||||
if (class_exists($className) && method_exists($className, 'load')) {
|
||||
$helperClass = new $className($this->metadata, $ormMeta, $entityDefs);
|
||||
$fieldResult = $helperClass->process( $fieldName, $entityName );
|
||||
if (isset($fieldResult['unset'])) {
|
||||
$ormMeta = Util::unsetInArray($ormMeta, $fieldResult['unset']);
|
||||
unset($fieldResult['unset']);
|
||||
}
|
||||
|
||||
$ormMeta = Util::merge($ormMeta, $fieldResult);
|
||||
|
||||
} //END: load custom field definitions
|
||||
}
|
||||
|
||||
//todo move to separate file
|
||||
//add a field 'isFollowed' for scopes with 'stream => true'
|
||||
$scopeDefs = $this->getMetadata()->get('scopes.'.$entityName);
|
||||
if (isset($scopeDefs['stream']) && $scopeDefs['stream']) {
|
||||
if (!isset($entityMeta['fields']['isFollowed'])) {
|
||||
$ormMeta[$entityName]['fields']['isFollowed'] = array(
|
||||
'type' => 'varchar',
|
||||
'notStorable' => true,
|
||||
);
|
||||
}
|
||||
} //END: add a field 'isFollowed' for stream => true
|
||||
|
||||
return $ormMeta;
|
||||
}
|
||||
|
||||
protected function convertField($entityName, $fieldName, array $fieldParams, $fieldTypeMeta = null)
|
||||
{
|
||||
/** set default type if exists */
|
||||
|
||||
@@ -34,30 +34,38 @@ class Currency extends Base
|
||||
|
||||
$alias = Util::toUnderScore($fieldName) . "_currency_alias";
|
||||
|
||||
return array(
|
||||
$d = array(
|
||||
$entityName => array(
|
||||
'fields' => array(
|
||||
$fieldName => array(
|
||||
"type" => "float",
|
||||
"orderBy" => $converedFieldName . " {direction}"
|
||||
),
|
||||
$fieldName . 'Converted' => array(
|
||||
'type' => 'float',
|
||||
'select' => Util::toUnderScore($entityName) . "." . $currencyColumnName . " * {$alias}.rate" ,
|
||||
'where' =>
|
||||
array (
|
||||
"=" => Util::toUnderScore($entityName) . "." . $currencyColumnName . " * {$alias}.rate = {value}",
|
||||
">" => Util::toUnderScore($entityName) . "." . $currencyColumnName . " * {$alias}.rate > {value}",
|
||||
"<" => Util::toUnderScore($entityName) . "." . $currencyColumnName . " * {$alias}.rate < {value}",
|
||||
">=" => Util::toUnderScore($entityName) . "." . $currencyColumnName . " * {$alias}.rate >= {value}",
|
||||
"<=" => Util::toUnderScore($entityName) . "." . $currencyColumnName . " * {$alias}.rate <= {value}",
|
||||
"<>" => Util::toUnderScore($entityName) . "." . $currencyColumnName . " * {$alias}.rate <> {value}"
|
||||
),
|
||||
'notStorable' => true,
|
||||
'orderBy' => $converedFieldName . " {direction}"
|
||||
),
|
||||
)
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
$params = $this->getFieldParams($fieldName);
|
||||
if (!empty($params['notStorable'])) {
|
||||
$d[$entityName]['fields'][$fieldName]['notStorable'] = true;
|
||||
} else {
|
||||
$d[$entityName]['fields'][$fieldName . 'Converted'] = array(
|
||||
'type' => 'float',
|
||||
'select' => Util::toUnderScore($entityName) . "." . $currencyColumnName . " * {$alias}.rate" ,
|
||||
'where' =>
|
||||
array (
|
||||
"=" => Util::toUnderScore($entityName) . "." . $currencyColumnName . " * {$alias}.rate = {value}",
|
||||
">" => Util::toUnderScore($entityName) . "." . $currencyColumnName . " * {$alias}.rate > {value}",
|
||||
"<" => Util::toUnderScore($entityName) . "." . $currencyColumnName . " * {$alias}.rate < {value}",
|
||||
">=" => Util::toUnderScore($entityName) . "." . $currencyColumnName . " * {$alias}.rate >= {value}",
|
||||
"<=" => Util::toUnderScore($entityName) . "." . $currencyColumnName . " * {$alias}.rate <= {value}",
|
||||
"<>" => Util::toUnderScore($entityName) . "." . $currencyColumnName . " * {$alias}.rate <> {value}"
|
||||
),
|
||||
'notStorable' => true,
|
||||
'orderBy' => $converedFieldName . " {direction}"
|
||||
);
|
||||
}
|
||||
|
||||
return $d;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ class Email extends Base
|
||||
$entityName => array(
|
||||
'fields' => array(
|
||||
$fieldName => array(
|
||||
'select' => 'email_address.name',
|
||||
'select' => 'emailAddresses.name',
|
||||
'where' =>
|
||||
array (
|
||||
'LIKE' => \Espo\Core\Utils\Util::toUnderScore($entityName) . ".id IN (
|
||||
@@ -58,7 +58,7 @@ class Email extends Base
|
||||
email_address.deleted = 0 AND email_address.name <> {value}
|
||||
)"
|
||||
),
|
||||
'orderBy' => 'email_address.name {direction}',
|
||||
'orderBy' => 'emailAddresses.name {direction}',
|
||||
),
|
||||
$fieldName .'Data' => array(
|
||||
'type' => 'text',
|
||||
|
||||
57
application/Espo/Core/Utils/Database/Orm/Fields/Link.php
Normal file
57
application/Espo/Core/Utils/Database/Orm/Fields/Link.php
Normal file
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM - Open Source CRM application.
|
||||
* Copyright (C) 2014-2015 Yuri Kuznetsov, Taras Machyshyn, Oleksiy Avramenko
|
||||
* Website: http://www.espocrm.com
|
||||
*
|
||||
* EspoCRM is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* EspoCRM is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with EspoCRM. If not, see http://www.gnu.org/licenses/.
|
||||
************************************************************************/
|
||||
|
||||
namespace Espo\Core\Utils\Database\Orm\Fields;
|
||||
|
||||
class Link extends Base
|
||||
{
|
||||
protected function load($fieldName, $entityName)
|
||||
{
|
||||
$fieldParams = $this->getFieldParams();
|
||||
|
||||
$data = array(
|
||||
$entityName => array (
|
||||
'fields' => array(
|
||||
$fieldName.'Id' => array(
|
||||
'type' => 'foreignId',
|
||||
'index' => $fieldName,
|
||||
),
|
||||
$fieldName.'Name' => array(
|
||||
'type' => 'varchar',
|
||||
'notStorable' => true,
|
||||
),
|
||||
),
|
||||
),
|
||||
'unset' => array(
|
||||
$entityName => array(
|
||||
'fields.'.$fieldName,
|
||||
),
|
||||
),
|
||||
);
|
||||
if (!empty($fieldParams['notStorable'])) {
|
||||
$data[$entityName]['fields'][$fieldName.'Id']['notStorable'] = true;
|
||||
}
|
||||
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
@@ -44,6 +44,11 @@ class LinkParent extends Base
|
||||
),
|
||||
),
|
||||
),
|
||||
'unset' => array(
|
||||
$entityName => array(
|
||||
'fields.'.$fieldName,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -30,7 +30,7 @@ class Phone extends Base
|
||||
$entityName => array(
|
||||
'fields' => array(
|
||||
$fieldName => array(
|
||||
'select' => 'phone_number.name',
|
||||
'select' => 'phoneNumbers.name',
|
||||
'where' =>
|
||||
array (
|
||||
'LIKE' => \Espo\Core\Utils\Util::toUnderScore($entityName) . ".id IN (
|
||||
@@ -58,7 +58,7 @@ class Phone extends Base
|
||||
phone_number.deleted = 0 AND phone_number.name <> {value}
|
||||
)"
|
||||
),
|
||||
'orderBy' => 'phone_number.name {direction}',
|
||||
'orderBy' => 'phoneNumbers.name {direction}',
|
||||
),
|
||||
$fieldName .'Data' => array(
|
||||
'type' => 'text',
|
||||
|
||||
@@ -36,6 +36,7 @@ class Base extends \Espo\Core\Utils\Database\Orm\Base
|
||||
'conditions',
|
||||
'additionalColumns',
|
||||
'midKeys',
|
||||
'noJoin'
|
||||
);
|
||||
|
||||
protected function getParams()
|
||||
|
||||
@@ -26,16 +26,30 @@ class BelongsTo extends Base
|
||||
{
|
||||
protected function load($linkName, $entityName)
|
||||
{
|
||||
$linkParams = $this->getLinkParams();
|
||||
|
||||
$foreignEntityName = $this->getForeignEntityName();
|
||||
|
||||
if (!empty($linkParams['noJoin'])) {
|
||||
$fieldNameDefs = array(
|
||||
'type' => 'varchar',
|
||||
'notStorable' => true,
|
||||
'relation' => $linkName,
|
||||
'foreign' => $this->getForeignField('name', $foreignEntityName),
|
||||
);
|
||||
} else {
|
||||
$fieldNameDefs = array(
|
||||
'type' => 'foreign',
|
||||
'relation' => $linkName,
|
||||
'foreign' => $this->getForeignField('name', $foreignEntityName),
|
||||
'notStorable' => false,
|
||||
);
|
||||
}
|
||||
|
||||
return array (
|
||||
$entityName => array (
|
||||
'fields' => array(
|
||||
$linkName.'Name' => array(
|
||||
'type' => 'foreign',
|
||||
'relation' => $linkName,
|
||||
'foreign' => $this->getForeignField('name', $foreignEntityName),
|
||||
),
|
||||
$linkName.'Name' => $fieldNameDefs,
|
||||
$linkName.'Id' => array(
|
||||
'type' => 'foreignId',
|
||||
'index' => true,
|
||||
@@ -46,7 +60,7 @@ class BelongsTo extends Base
|
||||
'type' => 'belongsTo',
|
||||
'entity' => $foreignEntityName,
|
||||
'key' => $linkName.'Id',
|
||||
'foreignKey' => 'id', //????
|
||||
'foreignKey' => 'id',
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM - Open Source CRM application.
|
||||
* Copyright (C) 2014-2015 Yuri Kuznetsov, Taras Machyshyn, Oleksiy Avramenko
|
||||
* Website: http://www.espocrm.com
|
||||
*
|
||||
* EspoCRM is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* EspoCRM is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with EspoCRM. If not, see http://www.gnu.org/licenses/.
|
||||
************************************************************************/
|
||||
|
||||
namespace Espo\Core\Utils\Database\Orm\Relations;
|
||||
|
||||
class BelongsToParent extends Base
|
||||
{
|
||||
protected function load($linkName, $entityName)
|
||||
{
|
||||
$linkParams = $this->getLinkParams();
|
||||
|
||||
return array(
|
||||
$entityName => array (
|
||||
'fields' => array(
|
||||
$linkName.'Id' => array(
|
||||
'type' => 'foreignId',
|
||||
'index' => $linkName,
|
||||
),
|
||||
$linkName.'Type' => array(
|
||||
'type' => 'foreignType',
|
||||
'notNull' => false,
|
||||
'index' => $linkName,
|
||||
'len' => 100
|
||||
),
|
||||
$linkName.'Name' => array(
|
||||
'type' => 'varchar',
|
||||
'notStorable' => true,
|
||||
),
|
||||
),
|
||||
'relations' => array(
|
||||
$linkName => array(
|
||||
'type' => 'belongsToParent',
|
||||
'key' => $linkName.'Id',
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -241,16 +241,19 @@ class Converter
|
||||
$table->addColumn('id', 'int', array('length'=>$this->defaultLength['int'], 'autoincrement' => true, 'notnull' => true,)); //'unique' => true,
|
||||
|
||||
//add midKeys to a schema
|
||||
$uniqueIndex = array();
|
||||
foreach($relationParams['midKeys'] as $index => $midKey) {
|
||||
|
||||
$usMidKey = Util::toUnderScore($midKey);
|
||||
$table->addColumn($usMidKey, $this->idParams['dbType'], array('length'=>$this->idParams['len']));
|
||||
$table->addIndex(array($usMidKey));
|
||||
$columnName = Util::toUnderScore($midKey);
|
||||
$table->addColumn($columnName, $this->idParams['dbType'], array('length'=>$this->idParams['len']));
|
||||
$table->addIndex(array($columnName));
|
||||
|
||||
} //END: add midKeys to a schema
|
||||
$uniqueIndex[] = $columnName;
|
||||
}
|
||||
//END: add midKeys to a schema
|
||||
|
||||
//add additionalColumns
|
||||
if (isset($relationParams['additionalColumns'])) {
|
||||
if (!empty($relationParams['additionalColumns'])) {
|
||||
foreach($relationParams['additionalColumns'] as $fieldName => $fieldParams) {
|
||||
|
||||
if (!isset($fieldParams['type'])) {
|
||||
@@ -264,6 +267,17 @@ class Converter
|
||||
}
|
||||
} //END: add additionalColumns
|
||||
|
||||
//add unique indexes
|
||||
if (!empty($relationParams['conditions'])) {
|
||||
foreach ($relationParams['conditions'] as $fieldName => $fieldParams) {
|
||||
$uniqueIndex[] = Util::toUnderScore($fieldName);
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($uniqueIndex)) {
|
||||
$table->addUniqueIndex($uniqueIndex);
|
||||
}
|
||||
//END: add unique indexes
|
||||
|
||||
$table->addColumn('deleted', 'bool', array('default' => 0));
|
||||
$table->setPrimaryKey(array("id"));
|
||||
@@ -271,7 +285,6 @@ class Converter
|
||||
return $table;
|
||||
}
|
||||
|
||||
|
||||
protected function getDbFieldParams($fieldParams)
|
||||
{
|
||||
$dbFieldParams = array();
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM - Open Source CRM application.
|
||||
* Copyright (C) 2014-2015 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/.
|
||||
************************************************************************/
|
||||
|
||||
return array(
|
||||
|
||||
'Autofollow' => array(
|
||||
'fields' => array(
|
||||
'id' => array(
|
||||
'type' => 'id',
|
||||
'dbType' => 'int',
|
||||
'len' => '11',
|
||||
'autoincrement' => true,
|
||||
'unique' => true,
|
||||
),
|
||||
'entityType' => array(
|
||||
'type' => 'varchar',
|
||||
'len' => '100',
|
||||
'index' => 'entityType',
|
||||
),
|
||||
'userId' => array(
|
||||
'type' => 'varchar',
|
||||
'len' => '24',
|
||||
'index' => true,
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
);
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM - Open Source CRM application.
|
||||
* Copyright (C) 2014-2015 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/.
|
||||
************************************************************************/
|
||||
|
||||
return array(
|
||||
|
||||
'ImportEntity' => array(
|
||||
'fields' => array(
|
||||
'id' => array(
|
||||
'type' => 'id',
|
||||
'dbType' => 'int',
|
||||
'len' => '11',
|
||||
'autoincrement' => true,
|
||||
'unique' => true
|
||||
),
|
||||
'entityId' => array(
|
||||
'type' => 'varchar',
|
||||
'len' => '24',
|
||||
'index' => 'entity'
|
||||
),
|
||||
'entityType' => array(
|
||||
'type' => 'varchar',
|
||||
'len' => '100',
|
||||
'index' => 'entity'
|
||||
),
|
||||
'importId' => array(
|
||||
'type' => 'varchar',
|
||||
'len' => '24',
|
||||
'index' => true
|
||||
),
|
||||
'isImported' => array(
|
||||
'type' => 'bool'
|
||||
),
|
||||
'isUpdated' => array(
|
||||
'type' => 'bool'
|
||||
),
|
||||
'isDuplicate' => array(
|
||||
'type' => 'bool'
|
||||
),
|
||||
),
|
||||
"indexes" => array(
|
||||
"entityImport" => array(
|
||||
"columns" => ["importId", "entityType"]
|
||||
)
|
||||
)
|
||||
),
|
||||
|
||||
);
|
||||
|
||||
@@ -25,42 +25,56 @@ namespace Espo\Core\Utils;
|
||||
class DateTime
|
||||
{
|
||||
protected $dataFormat;
|
||||
|
||||
|
||||
protected $timeFormat;
|
||||
|
||||
|
||||
protected $timezone;
|
||||
|
||||
|
||||
protected $internalDateTimeFormat = 'Y-m-d H:i:s';
|
||||
|
||||
protected $internalDateFormat = 'Y-m-d';
|
||||
|
||||
protected $dateFormats = array(
|
||||
'MM/DD/YYYY' => 'm/d/Y',
|
||||
'YYYY-MM-DD' => 'Y-m-d',
|
||||
'DD.MM.YYYY' => 'd.m.Y',
|
||||
);
|
||||
|
||||
|
||||
protected $timeFormats = array(
|
||||
'HH:mm' => 'H:i',
|
||||
'hh:mm A' => 'h:i A',
|
||||
'hh:mm a' => 'h:ia',
|
||||
'hh:mmA' => 'h:iA',
|
||||
);
|
||||
|
||||
|
||||
public function __construct($dateFormat = 'YYYY-MM-DD', $timeFormat = 'HH:mm', $timeZone = 'UTC')
|
||||
{
|
||||
$this->dateFormat = $dateFormat;
|
||||
$this->timeFormat = $timeFormat;
|
||||
|
||||
|
||||
$this->timezone = new \DateTimeZone($timeZone);
|
||||
}
|
||||
|
||||
|
||||
public function getInternalDateTimeFormat()
|
||||
{
|
||||
return $this->internalDateTimeFormat;
|
||||
}
|
||||
|
||||
public function getInternalDateFormat()
|
||||
{
|
||||
return $this->internalDateFormat;
|
||||
}
|
||||
|
||||
protected function getPhpDateFormat()
|
||||
{
|
||||
return $this->dateFormats[$this->dateFormat];
|
||||
}
|
||||
|
||||
|
||||
protected function getPhpDateTimeFormat()
|
||||
{
|
||||
return $this->dateFormats[$this->dateFormat] . ' ' . $this->timeFormats[$this->timeFormat];
|
||||
}
|
||||
|
||||
|
||||
public function convertSystemDateToGlobal($string)
|
||||
{
|
||||
$dateTime = \DateTime::createFromFormat('Y-m-d', $string);
|
||||
@@ -69,7 +83,7 @@ class DateTime
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public function convertSystemDateTimeToGlobal($string)
|
||||
{
|
||||
$dateTime = \DateTime::createFromFormat('Y-m-d H:i:s', $string);
|
||||
|
||||
421
application/Espo/Core/Utils/EntityManager.php
Normal file
421
application/Espo/Core/Utils/EntityManager.php
Normal file
@@ -0,0 +1,421 @@
|
||||
<?php
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM - Open Source CRM application.
|
||||
* Copyright (C) 2014-2015 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;
|
||||
|
||||
use \Espo\Core\Exceptions\Error;
|
||||
use \Espo\Core\Exceptions\Forbidden;
|
||||
use \Espo\Core\Exceptions\Conflict;
|
||||
use \Espo\Core\Utils\Json;
|
||||
|
||||
class EntityManager
|
||||
{
|
||||
private $metadata;
|
||||
|
||||
private $language;
|
||||
|
||||
private $fileManager;
|
||||
|
||||
private $metadataUtils;
|
||||
|
||||
public function __construct(Metadata $metadata, Language $language, File\Manager $fileManager)
|
||||
{
|
||||
$this->metadata = $metadata;
|
||||
$this->language = $language;
|
||||
$this->fileManager = $fileManager;
|
||||
|
||||
$this->metadataUtils = new \Espo\Core\Utils\Metadata\Utils($this->metadata);
|
||||
}
|
||||
|
||||
protected function getMetadata()
|
||||
{
|
||||
return $this->metadata;
|
||||
}
|
||||
|
||||
protected function getLanguage()
|
||||
{
|
||||
return $this->language;
|
||||
}
|
||||
|
||||
protected function getFileManager()
|
||||
{
|
||||
return $this->fileManager;
|
||||
}
|
||||
|
||||
protected function getMetadataUtils()
|
||||
{
|
||||
return $this->metadataUtils;
|
||||
}
|
||||
|
||||
public function create($name, $type, $params = array())
|
||||
{
|
||||
if ($this->getMetadata()->get('scopes.' . $name)) {
|
||||
throw new Conflict('Entity ['.$name.'] already exists.');
|
||||
}
|
||||
if (empty($name) || empty($type)) {
|
||||
throw new Error();
|
||||
}
|
||||
|
||||
$normalizedName = Util::normilizeClassName($name);
|
||||
|
||||
$contents = "<" . "?" . "php\n".
|
||||
"namespace Espo\Custom\Entities;\n".
|
||||
"class {$normalizedName} extends \Espo\Core\Templates\Entities\\{$type}\n".
|
||||
"{\n".
|
||||
" protected \$entityType = \"$name\";\n".
|
||||
"}\n";
|
||||
|
||||
$filePath = "custom/Espo/Custom/Entities/{$normalizedName}.php";
|
||||
$this->getFileManager()->putContents($filePath, $contents);
|
||||
|
||||
$contents = "<" . "?" . "php\n".
|
||||
"namespace Espo\Custom\Controllers;\n".
|
||||
"class {$normalizedName} extends \Espo\Core\Templates\Controllers\\{$type}\n".
|
||||
"{\n".
|
||||
"}\n";
|
||||
$filePath = "custom/Espo/Custom/Controllers/{$normalizedName}.php";
|
||||
$this->getFileManager()->putContents($filePath, $contents);
|
||||
|
||||
$contents = "<" . "?" . "php\n".
|
||||
"namespace Espo\Custom\Services;\n".
|
||||
"class {$normalizedName} extends \Espo\Core\Templates\Services\\{$type}\n".
|
||||
"{\n".
|
||||
"}\n";
|
||||
$filePath = "custom/Espo/Custom/Services/{$normalizedName}.php";
|
||||
$this->getFileManager()->putContents($filePath, $contents);
|
||||
|
||||
$contents = "<" . "?" . "php\n".
|
||||
"namespace Espo\Custom\Repositories;\n".
|
||||
"class {$normalizedName} extends \Espo\Core\Templates\Repositories\\{$type}\n".
|
||||
"{\n".
|
||||
"}\n";
|
||||
|
||||
$filePath = "custom/Espo/Custom/Repositories/{$normalizedName}.php";
|
||||
$this->getFileManager()->putContents($filePath, $contents);
|
||||
|
||||
$stream = false;
|
||||
if (!empty($params['stream'])) {
|
||||
$stream = $params['stream'];
|
||||
}
|
||||
$labelSingular = $name;
|
||||
if (!empty($params['labelSingular'])) {
|
||||
$labelSingular = $params['labelSingular'];
|
||||
}
|
||||
$labelPlural = $name;
|
||||
if (!empty($params['labelPlural'])) {
|
||||
$labelPlural = $params['labelPlural'];
|
||||
}
|
||||
$labelCreate = $this->getLanguage()->translate('Create') . ' ' . $labelSingular;
|
||||
|
||||
$scopeData = array(
|
||||
'entity' => true,
|
||||
'layouts' => true,
|
||||
'tab' => true,
|
||||
'acl' => true,
|
||||
'module' => 'Custom',
|
||||
'isCustom' => true,
|
||||
'customizable' => true,
|
||||
'importable' => true,
|
||||
'type' => $type,
|
||||
'stream' => $stream,
|
||||
'notifications' => true
|
||||
);
|
||||
$this->getMetadata()->set('scopes', $name, $scopeData);
|
||||
|
||||
$filePath = "application/Espo/Core/Templates/Metadata/{$type}/entityDefs.json";
|
||||
$entityDefsData = Json::decode($this->getFileManager()->getContents($filePath), true);
|
||||
$this->getMetadata()->set('entityDefs', $name, $entityDefsData);
|
||||
|
||||
$filePath = "application/Espo/Core/Templates/Metadata/{$type}/clientDefs.json";
|
||||
$clientDefsData = Json::decode($this->getFileManager()->getContents($filePath), true);
|
||||
$this->getMetadata()->set('clientDefs', $name, $clientDefsData);
|
||||
|
||||
$this->getLanguage()->set('Global', 'scopeNames', $name, $labelSingular);
|
||||
$this->getLanguage()->set('Global', 'scopeNamesPlural', $name, $labelPlural);
|
||||
$this->getLanguage()->set($name, 'labels', 'Create ' . $name, $labelCreate);
|
||||
|
||||
$this->getMetadata()->save();
|
||||
$this->getLanguage()->save();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function update($name, $data)
|
||||
{
|
||||
if (!$this->getMetadata()->get('scopes.' . $name)) {
|
||||
throw new Error('Entity ['.$name.'] does not exist.');
|
||||
}
|
||||
|
||||
if (isset($data['stream'])) {
|
||||
$scopeData = array(
|
||||
'stream' => (true == $data['stream'])
|
||||
);
|
||||
$this->getMetadata()->set('scopes', $name, $scopeData);
|
||||
}
|
||||
|
||||
if (!empty($data['labelSingular'])) {
|
||||
$labelSingular = $data['labelSingular'];
|
||||
$this->getLanguage()->set('Global', 'scopeNames', $name, $labelSingular);
|
||||
$labelCreate = $this->getLanguage()->translate('Create') . ' ' . $labelSingular;
|
||||
$this->getLanguage()->set($name, 'labels', 'Create ' . $name, $labelCreate);
|
||||
}
|
||||
|
||||
if (!empty($data['labelPlural'])) {
|
||||
$labelPlural = $data['labelPlural'];
|
||||
$this->getLanguage()->set('Global', 'scopeNamesPlural', $name, $labelPlural);
|
||||
}
|
||||
|
||||
$this->getMetadata()->save();
|
||||
$this->getLanguage()->save();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function delete($name)
|
||||
{
|
||||
if (!$this->isCustom($name)) {
|
||||
throw new Forbidden;
|
||||
}
|
||||
|
||||
$normalizedName = Util::normilizeClassName($name);
|
||||
|
||||
$unsets = array(
|
||||
'entityDefs',
|
||||
'clientDefs',
|
||||
'scopes'
|
||||
);
|
||||
$res = $this->getMetadata()->delete('entityDefs', $name);
|
||||
$res = $this->getMetadata()->delete('clientDefs', $name);
|
||||
$res = $this->getMetadata()->delete('scopes', $name);
|
||||
|
||||
$this->getFileManager()->removeFile("custom/Espo/Custom/Resources/metadata/entityDefs/{$name}.json");
|
||||
$this->getFileManager()->removeFile("custom/Espo/Custom/Resources/metadata/clientDefs/{$name}.json");
|
||||
$this->getFileManager()->removeFile("custom/Espo/Custom/Resources/metadata/scopes/{$name}.json");
|
||||
|
||||
$this->getFileManager()->removeFile("custom/Espo/Custom/Entities/{$normalizedName}.php");
|
||||
$this->getFileManager()->removeFile("custom/Espo/Custom/Services/{$normalizedName}.php");
|
||||
$this->getFileManager()->removeFile("custom/Espo/Custom/Controllers/{$normalizedName}.php");
|
||||
$this->getFileManager()->removeFile("custom/Espo/Custom/Repositories/{$normalizedName}.php");
|
||||
|
||||
try {
|
||||
$this->getLanguage()->delete('Global', 'scopeNames', $name);
|
||||
$this->getLanguage()->delete('Global', 'scopeNamesPlural', $name);
|
||||
} catch (\Exception $e) {}
|
||||
|
||||
$this->getMetadata()->save();
|
||||
$this->getLanguage()->save();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
protected function isCustom($name)
|
||||
{
|
||||
return $this->getMetadata()->get('scopes.' . $name . '.isCustom');
|
||||
}
|
||||
|
||||
public function createLink(array $params)
|
||||
{
|
||||
$linkType = $params['linkType'];
|
||||
|
||||
$entity = $params['entity'];
|
||||
$link = $params['link'];
|
||||
$entityForeign = $params['entityForeign'];
|
||||
$linkForeign = $params['linkForeign'];
|
||||
|
||||
$label = $params['label'];
|
||||
$labelForeign = $params['labelForeign'];
|
||||
|
||||
if (empty($linkType)) {
|
||||
throw new Error();
|
||||
}
|
||||
if (empty($entity) || empty($entityForeign)) {
|
||||
throw new Error();
|
||||
}
|
||||
if (empty($entityForeign) || empty($linkForeign)) {
|
||||
throw new Error();
|
||||
}
|
||||
|
||||
if ($this->getMetadata()->get('entityDefs.' . $entity . '.links.' . $link)) {
|
||||
throw new Conflict('Link ['.$entity.'::'.$link.'] already exists.');
|
||||
}
|
||||
if ($this->getMetadata()->get('entityDefs.' . $entityForeign . '.links.' . $linkForeign)) {
|
||||
throw new Conflict('Link ['.$entityForeign.'::'.$linkForeign.'] already exists.');
|
||||
}
|
||||
|
||||
switch ($linkType) {
|
||||
case 'oneToMany':
|
||||
if ($this->getMetadata()->get('entityDefs.' . $entityForeign . '.field.' . $linkForeign)) {
|
||||
throw new Conflict('Field ['.$entityForeign.'::'.$linkForeign.'] already exists.');
|
||||
}
|
||||
$dataLeft = array(
|
||||
'links' => array(
|
||||
$link => array(
|
||||
'type' => 'hasMany',
|
||||
'foreign' => $linkForeign,
|
||||
'entity' => $entityForeign,
|
||||
'isCustom' => true
|
||||
)
|
||||
)
|
||||
);
|
||||
$dataRight = array(
|
||||
'fields' => array(
|
||||
$linkForeign => array(
|
||||
'type' => 'link'
|
||||
)
|
||||
),
|
||||
'links' => array(
|
||||
$linkForeign => array(
|
||||
'type' => 'belongsTo',
|
||||
'foreign' => $link,
|
||||
'entity' => $entity,
|
||||
'isCustom' => true
|
||||
)
|
||||
)
|
||||
);
|
||||
break;
|
||||
case 'manyToOne':
|
||||
if ($this->getMetadata()->get('entityDefs.' . $entity . '.field.' . $link)) {
|
||||
throw new Conflict('Field ['.$entity.'::'.$link.'] already exists.');
|
||||
}
|
||||
$dataLeft = array(
|
||||
'fields' => array(
|
||||
$link => array(
|
||||
'type' => 'link'
|
||||
)
|
||||
),
|
||||
'links' => array(
|
||||
$link => array(
|
||||
'type' => 'belongsTo',
|
||||
'foreign' => $linkForeign,
|
||||
'entity' => $entityForeign,
|
||||
'isCustom' => true
|
||||
)
|
||||
)
|
||||
);
|
||||
$dataRight = array(
|
||||
'links' => array(
|
||||
$linkForeign => array(
|
||||
'type' => 'hasMany',
|
||||
'foreign' => $link,
|
||||
'entity' => $entity,
|
||||
'isCustom' => true
|
||||
)
|
||||
)
|
||||
);
|
||||
break;
|
||||
case 'manyToMany':
|
||||
$dataLeft = array(
|
||||
'links' => array(
|
||||
$link => array(
|
||||
'type' => 'hasMany',
|
||||
'foreign' => $linkForeign,
|
||||
'entity' => $entityForeign,
|
||||
'isCustom' => true
|
||||
)
|
||||
)
|
||||
);
|
||||
$dataRight = array(
|
||||
'links' => array(
|
||||
$linkForeign => array(
|
||||
'type' => 'hasMany',
|
||||
'foreign' => $link,
|
||||
'entity' => $entity,
|
||||
'isCustom' => true
|
||||
)
|
||||
)
|
||||
);
|
||||
break;
|
||||
}
|
||||
|
||||
$this->getMetadata()->set('entityDefs', $entity, $dataLeft);
|
||||
$this->getMetadata()->set('entityDefs', $entityForeign, $dataRight);
|
||||
$this->getMetadata()->save();
|
||||
|
||||
$this->getLanguage()->set($entity, 'fields', $link, $label);
|
||||
$this->getLanguage()->set($entity, 'links', $link, $label);
|
||||
$this->getLanguage()->set($entityForeign, 'fields', $linkForeign, $labelForeign);
|
||||
$this->getLanguage()->set($entityForeign, 'links', $linkForeign, $labelForeign);
|
||||
|
||||
$this->getLanguage()->save();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function updateLink(array $params)
|
||||
{
|
||||
$entity = $params['entity'];
|
||||
$link = $params['link'];
|
||||
$entityForeign = $params['entityForeign'];
|
||||
$linkForeign = $params['linkForeign'];
|
||||
|
||||
$label = $params['label'];
|
||||
$labelForeign = $params['labelForeign'];
|
||||
|
||||
if (empty($entity) || empty($entityForeign)) {
|
||||
throw new Error();
|
||||
}
|
||||
if (empty($entityForeign) || empty($linkForeign)) {
|
||||
throw new Error();
|
||||
}
|
||||
|
||||
$this->getLanguage()->set($entity, 'fields', $link, $label);
|
||||
$this->getLanguage()->set($entity, 'links', $link, $label);
|
||||
$this->getLanguage()->set($entityForeign, 'fields', $linkForeign, $labelForeign);
|
||||
$this->getLanguage()->set($entityForeign, 'links', $linkForeign, $labelForeign);
|
||||
|
||||
$this->getLanguage()->save();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function deleteLink(array $params)
|
||||
{
|
||||
$entity = $params['entity'];
|
||||
$link = $params['link'];
|
||||
|
||||
if (!$this->getMetadata()->get("entityDefs.{$entity}.links.{$link}.isCustom")) {
|
||||
throw new Error();
|
||||
}
|
||||
|
||||
$entityForeign = $this->getMetadata()->get("entityDefs.{$entity}.links.{$link}.entity");
|
||||
$linkForeign = $this->getMetadata()->get("entityDefs.{$entity}.links.{$link}.foreign");
|
||||
|
||||
if (empty($entity) || empty($entityForeign)) {
|
||||
throw new Error();
|
||||
}
|
||||
if (empty($entityForeign) || empty($linkForeign)) {
|
||||
throw new Error();
|
||||
}
|
||||
|
||||
$this->getMetadata()->delete('entityDefs', $entity, array(
|
||||
'fields.' . $link,
|
||||
'links.' . $link
|
||||
));
|
||||
$this->getMetadata()->delete('entityDefs', $entityForeign, array(
|
||||
'fields.' . $linkForeign,
|
||||
'links.' . $linkForeign
|
||||
));
|
||||
$this->getMetadata()->save();
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -151,6 +151,7 @@ class FieldManager
|
||||
protected function deleteLabel($name, $scope)
|
||||
{
|
||||
$this->getLanguage()->delete($scope, 'fields', $name);
|
||||
$this->getLanguage()->delete($scope, 'options', $name);
|
||||
return $this->getLanguage()->save();
|
||||
}
|
||||
|
||||
@@ -177,6 +178,7 @@ class FieldManager
|
||||
$unnecessaryFields = array(
|
||||
'name',
|
||||
'label',
|
||||
'translatedOptions',
|
||||
);
|
||||
|
||||
foreach ($unnecessaryFields as $fieldName) {
|
||||
|
||||
@@ -60,7 +60,7 @@ class ClassParser
|
||||
return $this->metadata;
|
||||
}
|
||||
|
||||
public function setAllowedMethods(array $methods)
|
||||
public function setAllowedMethods($methods)
|
||||
{
|
||||
$this->allowedMethods = $methods;
|
||||
}
|
||||
@@ -129,11 +129,18 @@ class ClassParser
|
||||
$filePath = Util::concatPath($dir, $file);
|
||||
$className = Util::getClassName($filePath);
|
||||
$fileName = $this->getFileManager()->getFileName($filePath);
|
||||
$fileName = ucfirst($fileName);
|
||||
|
||||
$scopeName = ucfirst($fileName);
|
||||
$normalizedScopeName = Util::normilizeScopeName($scopeName);
|
||||
|
||||
if (empty($this->allowedMethods)) {
|
||||
$data[$normalizedScopeName] = $className;
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach ($this->allowedMethods as $methodName) {
|
||||
if (method_exists($className, $methodName)) {
|
||||
$data[$fileName] = $className;
|
||||
$data[$normalizedScopeName] = $className;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -29,6 +29,8 @@ class Manager
|
||||
{
|
||||
private $permission;
|
||||
|
||||
private $permissionDeniedList = array();
|
||||
|
||||
public function __construct(\Espo\Core\Utils\Config $config = null)
|
||||
{
|
||||
$params = null;
|
||||
@@ -60,12 +62,14 @@ class Manager
|
||||
*/
|
||||
public function getFileList($path, $recursively = false, $filter = '', $onlyFileType = null, $isReturnSingleArray = false)
|
||||
{
|
||||
if (!file_exists($path)) {
|
||||
return false;
|
||||
}
|
||||
$path = $this->concatPaths($path);
|
||||
|
||||
$result = array();
|
||||
|
||||
if (!file_exists($path) || !is_dir($path)) {
|
||||
return $result;
|
||||
}
|
||||
|
||||
$cdir = scandir($path);
|
||||
foreach ($cdir as $key => $value)
|
||||
{
|
||||
@@ -201,7 +205,7 @@ class Manager
|
||||
$fullPath = $this->concatPaths($path); //todo remove after changing the params
|
||||
|
||||
if ($this->checkCreateFile($fullPath) === false) {
|
||||
throw new Error('Permission denied in '. $fullPath);
|
||||
throw new Error('Permission denied for '. $fullPath);
|
||||
}
|
||||
|
||||
$res = (file_put_contents($fullPath, $data, $flags, $context) !== FALSE);
|
||||
@@ -319,7 +323,7 @@ class Manager
|
||||
* Unset some element of content data
|
||||
*
|
||||
* @param string | array $path
|
||||
* @param array | string $unsets [description]
|
||||
* @param array | string $unsets
|
||||
* @return bool
|
||||
*/
|
||||
public function unsetContents($path, $unsets, $isJSON = true)
|
||||
@@ -332,7 +336,12 @@ class Manager
|
||||
|
||||
$currentDataArray = Utils\Json::getArrayData($currentData);
|
||||
|
||||
$unsettedData = Utils\Util::unsetInArray($currentDataArray, $unsets);
|
||||
$unsettedData = Utils\Util::unsetInArray($currentDataArray, $unsets, true);
|
||||
|
||||
if (is_null($unsettedData) || (is_array($unsettedData) && empty($unsettedData))) {
|
||||
$fullPath = $this->concatPaths($path);
|
||||
return $this->unlink($fullPath);
|
||||
}
|
||||
|
||||
if ($isJSON) {
|
||||
return $this->putContentsJson($path, $unsettedData);
|
||||
@@ -366,9 +375,11 @@ class Manager
|
||||
*
|
||||
* @param string | array $path
|
||||
* @param int $permission - ex. 0755
|
||||
* @param bool $recursive
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function mkdir($path, $permission = null)
|
||||
public function mkdir($path, $permission = null, $recursive = false)
|
||||
{
|
||||
$fullPath = $this->concatPaths($path);
|
||||
|
||||
@@ -376,14 +387,23 @@ class Manager
|
||||
return true;
|
||||
}
|
||||
|
||||
$defaultPermissions = $this->getPermissionUtils()->getDefaultPermissions();
|
||||
|
||||
if (!isset($permission)) {
|
||||
$defaultPermissions = $this->getPermissionUtils()->getDefaultPermissions();
|
||||
$permission = (string) $defaultPermissions['dir'];
|
||||
$permission = base_convert($permission, 8, 10);
|
||||
}
|
||||
|
||||
try {
|
||||
$result = mkdir($fullPath, $permission, true);
|
||||
|
||||
if (!empty($defaultPermissions['user'])) {
|
||||
$this->getPermissionUtils()->chown($fullPath);
|
||||
}
|
||||
|
||||
if (!empty($defaultPermissions['group'])) {
|
||||
$this->getPermissionUtils()->chgrp($fullPath);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
$GLOBALS['log']->critical('Permission denied: unable to create the folder on the server - '.$fullPath);
|
||||
}
|
||||
@@ -439,7 +459,7 @@ class Manager
|
||||
|
||||
if (!empty($permissionDeniedList)) {
|
||||
$betterPermissionList = $this->getPermissionUtils()->arrangePermissionList($permissionDeniedList);
|
||||
throw new Error("Permission denied in <br>". implode(", <br>", $betterPermissionList));
|
||||
throw new Error("Permission denied for <br>". implode(", <br>", $betterPermissionList));
|
||||
}
|
||||
|
||||
$res = true;
|
||||
@@ -466,7 +486,7 @@ class Manager
|
||||
* @param string $filePath
|
||||
* @return string
|
||||
*/
|
||||
protected function checkCreateFile($filePath)
|
||||
public function checkCreateFile($filePath)
|
||||
{
|
||||
$defaultPermissions = $this->getPermissionUtils()->getDefaultPermissions();
|
||||
|
||||
@@ -483,8 +503,8 @@ class Manager
|
||||
$dirPermission = $defaultPermissions['dir'];
|
||||
$dirPermission = is_string($dirPermission) ? base_convert($dirPermission,8,10) : $dirPermission;
|
||||
|
||||
if (!mkdir($pathParts['dirname'], $dirPermission, true)) {
|
||||
throw new Error('Permission denied: unable to create a folder on the server - '.$pathParts['dirname']);
|
||||
if (!$this->mkdir($pathParts['dirname'], $dirPermission, true)) {
|
||||
throw new Error('Permission denied: unable to create a folder on the server - ' . $pathParts['dirname']);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -593,6 +613,24 @@ class Manager
|
||||
$items = (array) $items;
|
||||
}
|
||||
|
||||
$permissionDeniedList = array();
|
||||
foreach ($items as $item) {
|
||||
if (isset($dirPath)) {
|
||||
$item = Utils\Util::concatPath($dirPath, $item);
|
||||
}
|
||||
|
||||
if (!is_writable($item)) {
|
||||
$permissionDeniedList[] = $item;
|
||||
} else if (!is_writable(dirname($item))) {
|
||||
$permissionDeniedList[] = dirname($item);
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($permissionDeniedList)) {
|
||||
$betterPermissionList = $this->getPermissionUtils()->arrangePermissionList($permissionDeniedList);
|
||||
throw new Error("Permission denied for <br>". implode(", <br>", $betterPermissionList));
|
||||
}
|
||||
|
||||
$result = true;
|
||||
foreach ($items as $item) {
|
||||
if (isset($dirPath)) {
|
||||
@@ -751,5 +789,73 @@ return '.var_export($content, true).';
|
||||
?>';
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if $paths are writable. Permission denied list are defined in getLastPermissionDeniedList()
|
||||
*
|
||||
* @param array $paths
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function isWritableList(array $paths)
|
||||
{
|
||||
$permissionDeniedList = array();
|
||||
|
||||
$result = true;
|
||||
foreach ($paths as $path) {
|
||||
$rowResult = $this->isWritable($path);
|
||||
if (!$rowResult) {
|
||||
$permissionDeniedList[] = $path;
|
||||
}
|
||||
$result &= $rowResult;
|
||||
}
|
||||
|
||||
if (!empty($permissionDeniedList)) {
|
||||
$this->permissionDeniedList = $this->getPermissionUtils()->arrangePermissionList($permissionDeniedList);
|
||||
}
|
||||
|
||||
return (bool) $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get last permission denied list
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getLastPermissionDeniedList()
|
||||
{
|
||||
return $this->permissionDeniedList;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if $path is writable
|
||||
*
|
||||
* @param string | array $path
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function isWritable($path)
|
||||
{
|
||||
$existFile = $this->getExistsPath($path);
|
||||
|
||||
return is_writable($existFile);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get exists path. Ex. if check /var/www/espocrm/custom/someFile.php and this file doesn't extist, result will be /var/www/espocrm/custom
|
||||
*
|
||||
* @param string | array $path
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getExistsPath($path)
|
||||
{
|
||||
$fullPath = $this->concatPaths($path);
|
||||
|
||||
if (!file_exists($fullPath)) {
|
||||
$fullPath = $this->getExistsPath(pathinfo($fullPath, PATHINFO_DIRNAME));
|
||||
}
|
||||
|
||||
return $fullPath;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -92,7 +92,6 @@ class Permission
|
||||
return $this->params;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get default settings
|
||||
*
|
||||
@@ -137,7 +136,6 @@ class Permission
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get current permissions
|
||||
*
|
||||
@@ -216,7 +214,6 @@ class Permission
|
||||
return $this->chmodRecurse($path, $permission['file'], $permission['dir']);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Change permissions recursive
|
||||
*
|
||||
@@ -232,27 +229,20 @@ class Permission
|
||||
return false;
|
||||
}
|
||||
|
||||
if (is_file($path)) {
|
||||
if (!is_dir($path)) {
|
||||
return $this->chmodReal($path, $fileOctal);
|
||||
}
|
||||
|
||||
if (is_dir($path)) {
|
||||
$allFiles = $this->getFileManager()->getFileList($path);
|
||||
$result = $this->chmodReal($path, $dirOctal);
|
||||
|
||||
foreach ($items as $item) {
|
||||
$this->chmodRecurse($path. Utils\Util::getSeparator() .$item, $fileOctal, $dirOctal);
|
||||
}
|
||||
|
||||
return $this->chmodReal($path, $dirOctal);
|
||||
$allFiles = $this->getFileManager()->getFileList($path);
|
||||
foreach ($allFiles as $item) {
|
||||
$result &= $this->chmodRecurse($path . Utils\Util::getSeparator() . $item, $fileOctal, $dirOctal);
|
||||
}
|
||||
|
||||
return false;
|
||||
return (bool) $result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Change owner permission
|
||||
*
|
||||
@@ -262,7 +252,7 @@ class Permission
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function chown($path, $user='', $recurse=false)
|
||||
public function chown($path, $user = '', $recurse = false)
|
||||
{
|
||||
if (!file_exists($path)) {
|
||||
return false;
|
||||
@@ -295,13 +285,18 @@ class Permission
|
||||
return false;
|
||||
}
|
||||
|
||||
$allFiles = $this->getFileManager()->getFileList($path);
|
||||
|
||||
foreach ($items as $item) {
|
||||
$this->chownRecurse($path. Utils\Util::getSeparator() .$item, $user);
|
||||
if (!is_dir($path)) {
|
||||
return $this->chownReal($path, $user);
|
||||
}
|
||||
|
||||
return $this->chownReal($path, $user);
|
||||
$result = $this->chownReal($path, $user);
|
||||
|
||||
$allFiles = $this->getFileManager()->getFileList($path);
|
||||
foreach ($allFiles as $item) {
|
||||
$result &= $this->chownRecurse($path . Utils\Util::getSeparator() . $item, $user);
|
||||
}
|
||||
|
||||
return (bool) $result;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -347,15 +342,19 @@ class Permission
|
||||
return false;
|
||||
}
|
||||
|
||||
$allFiles = $this->getFileManager()->getFileList($path);
|
||||
|
||||
foreach ($items as $item) {
|
||||
$this->chgrpRecurse($path. Utils\Util::getSeparator() .$item, $group);
|
||||
if (!is_dir($path)) {
|
||||
return $this->chgrpReal($path, $group);
|
||||
}
|
||||
|
||||
return $this->chgrpReal($path, $group);
|
||||
}
|
||||
$result = $this->chgrpReal($path, $group);
|
||||
|
||||
$allFiles = $this->getFileManager()->getFileList($path);
|
||||
foreach ($allFiles as $item) {
|
||||
$result &= $this->chgrpRecurse($path . Utils\Util::getSeparator() . $item, $group);
|
||||
}
|
||||
|
||||
return (bool) $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change permissions recursive
|
||||
|
||||
@@ -136,7 +136,7 @@ class Layout
|
||||
}
|
||||
|
||||
$layoutPath = $this->getLayoutPath($controllerName, true);
|
||||
$data = Json::encode($layoutData);
|
||||
$data = Json::encode($layoutData, \JSON_PRETTY_PRINT);
|
||||
|
||||
$result &= $this->getFileManager()->putContents(array($layoutPath, $layoutName.'.json'), $data);
|
||||
}
|
||||
|
||||
@@ -51,9 +51,15 @@ class StreamHandler extends \Monolog\Handler\StreamHandler
|
||||
|
||||
$this->errorMessage = null;
|
||||
|
||||
set_error_handler(array($this, 'customErrorHandler'));
|
||||
$this->getFileManager()->appendContents($this->url, $this->pruneMessage($record));
|
||||
restore_error_handler();
|
||||
if (!is_writable($this->url)) {
|
||||
$this->getFileManager()->checkCreateFile($this->url);
|
||||
}
|
||||
|
||||
if (is_writable($this->url)) {
|
||||
set_error_handler(array($this, 'customErrorHandler'));
|
||||
$this->getFileManager()->appendContents($this->url, $this->pruneMessage($record));
|
||||
restore_error_handler();
|
||||
}
|
||||
|
||||
if (isset($this->errorMessage)) {
|
||||
throw new \UnexpectedValueException(sprintf('The stream or file "%s" could not be opened: '.$this->errorMessage, $this->url));
|
||||
|
||||
@@ -41,6 +41,13 @@ class Metadata
|
||||
*/
|
||||
private $name = 'metadata';
|
||||
|
||||
/**
|
||||
* Path to modules
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $pathToModules = 'application/Espo/Modules';
|
||||
|
||||
private $cacheFile = 'data/cache/application/metadata.php';
|
||||
|
||||
private $paths = array(
|
||||
@@ -369,6 +376,8 @@ class Metadata
|
||||
|
||||
public function setOrmMetadata(array $ormMeta)
|
||||
{
|
||||
$result = true;
|
||||
|
||||
if ($this->getConfig()->get('useCache')) {
|
||||
$result = $this->getFileManager()->putPhpContents($this->ormCacheFile, $ormMeta);
|
||||
if ($result == false) {
|
||||
@@ -404,30 +413,27 @@ class Metadata
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Scopes
|
||||
* Load modules
|
||||
*
|
||||
* @return array
|
||||
* @return void
|
||||
*/
|
||||
public function getScopes()
|
||||
protected function loadModuleList()
|
||||
{
|
||||
if (!empty($this->scopes)) {
|
||||
return $this->scopes;
|
||||
}
|
||||
$modules = $this->getFileManager()->getFileList($this->pathToModules, false, '', false);
|
||||
|
||||
$scopeList = $this->get('scopes');
|
||||
if (!is_array($scopeList)) {
|
||||
$this->init(true);
|
||||
$scopeList = $this->get('scopes');
|
||||
}
|
||||
|
||||
$scopes = array();
|
||||
if (is_array($scopeList)) {
|
||||
foreach ($scopeList as $name => $details) {
|
||||
$scopes[$name] = isset($details['module']) ? $details['module'] : false;
|
||||
$modulesToSort = array();
|
||||
if (is_array($modules)) {
|
||||
foreach ($modules as $moduleName) {
|
||||
if (!empty($moduleName) && !isset($modulesToSort[$moduleName])) {
|
||||
$modulesToSort[$moduleName] = $this->getModuleConfig()->get($moduleName . '.order', $this->defaultModuleOrder);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $this->scopes = $scopes;
|
||||
krsort($modulesToSort);
|
||||
asort($modulesToSort);
|
||||
|
||||
$this->moduleList = array_keys($modulesToSort);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -437,24 +443,10 @@ class Metadata
|
||||
*/
|
||||
public function getModuleList()
|
||||
{
|
||||
if (!empty($this->moduleList)) {
|
||||
return $this->moduleList;
|
||||
if (!isset($this->moduleList)) {
|
||||
$this->loadModuleList();
|
||||
}
|
||||
|
||||
$scopes = $this->getScopes();
|
||||
|
||||
$modulesToSort = array();
|
||||
foreach ($scopes as $moduleName) {
|
||||
if (!empty($moduleName) && !isset($modulesToSort[$moduleName])) {
|
||||
$modulesToSort[$moduleName] = $this->getModuleConfig()->get($moduleName . '.order', $this->defaultModuleOrder);
|
||||
}
|
||||
}
|
||||
|
||||
krsort($modulesToSort);
|
||||
asort($modulesToSort);
|
||||
|
||||
$this->moduleList = array_keys($modulesToSort);
|
||||
|
||||
return $this->moduleList;
|
||||
}
|
||||
|
||||
@@ -490,26 +482,4 @@ class Metadata
|
||||
|
||||
return $path;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if scope exists
|
||||
*
|
||||
* @param string $scopeName
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isScopeExists($scopeName)
|
||||
{
|
||||
$scopeModuleMap = $this->getScopes();
|
||||
|
||||
$lowerEntityName = strtolower($scopeName);
|
||||
foreach($scopeModuleMap as $rowEntityName => $rowModuleName) {
|
||||
if ($lowerEntityName == strtolower($rowEntityName)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -101,4 +101,20 @@ class System
|
||||
{
|
||||
return (defined("PHP_BINDIR"))? PHP_BINDIR.DIRECTORY_SEPARATOR.'php' : 'php';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get php version (only digits and dots)
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function getPhpVersion()
|
||||
{
|
||||
$version = phpversion();
|
||||
|
||||
if (preg_match('/^[0-9\.]+[0-9]/', $version, $matches)) {
|
||||
return $matches[0];
|
||||
}
|
||||
|
||||
return $version;
|
||||
}
|
||||
}
|
||||
@@ -159,7 +159,7 @@ class Util
|
||||
if ($appendKey !== false) {
|
||||
unset($newValue[$appendKey]);
|
||||
$newValue = array_merge($currentArray[$newName], $newValue);
|
||||
} else if (!static::isSingleArray($newValue)) {
|
||||
} else if (!static::isSingleArray($newValue) || !static::isSingleArray($currentArray[$newName])) {
|
||||
$newValue = static::merge($currentArray[$newName], $newValue);
|
||||
}
|
||||
|
||||
@@ -288,6 +288,23 @@ class Util
|
||||
return $name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove 'Obj' if name is reserved PHP word.
|
||||
*
|
||||
* @param string $name
|
||||
* @return string
|
||||
*/
|
||||
public static function normilizeScopeName($name)
|
||||
{
|
||||
foreach (self::$reservedWords as $reservedWord) {
|
||||
if ($reservedWord.'Obj' == $name) {
|
||||
return $reservedWord;
|
||||
}
|
||||
}
|
||||
|
||||
return $name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Naming according to prefix or postfix type
|
||||
*
|
||||
@@ -351,10 +368,11 @@ class Util
|
||||
* array('EntityName1.unset1', 'EntityName1.unset2', .....)
|
||||
* OR
|
||||
* 'EntityName1.unset1'
|
||||
* @param bool $unsetParentEmptyArray - If unset empty parent array after unsets
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function unsetInArray(array $content, $unsets)
|
||||
public static function unsetInArray(array $content, $unsets, $unsetParentEmptyArray = false)
|
||||
{
|
||||
if (empty($unsets)) {
|
||||
return $content;
|
||||
@@ -379,11 +397,19 @@ class Util
|
||||
|
||||
$unsetElem = $currVal . "['{$lastKey}']";
|
||||
|
||||
$currVal = "
|
||||
$evalString = "
|
||||
if (isset({$unsetElem}) || ( is_array({$currVal}) && array_key_exists('{$lastKey}', {$currVal}) )) {
|
||||
unset({$unsetElem});
|
||||
} ";
|
||||
eval($currVal);
|
||||
eval($evalString);
|
||||
|
||||
if ($unsetParentEmptyArray) {
|
||||
$evalString = "
|
||||
if (is_array({$currVal}) && empty({$currVal})) {
|
||||
unset({$currVal});
|
||||
} ";
|
||||
eval($evalString);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -484,6 +510,11 @@ class Util
|
||||
return true;
|
||||
}
|
||||
|
||||
public static function generateId()
|
||||
{
|
||||
return uniqid() . substr(md5(rand()), 0, 4);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -69,6 +69,7 @@ return array (
|
||||
'ru_RU',
|
||||
'pl_PL',
|
||||
'pt_BR',
|
||||
'uk_UA',
|
||||
'vi_VN'
|
||||
),
|
||||
'language' => 'en_US',
|
||||
@@ -82,18 +83,23 @@ return array (
|
||||
'authenticationMethod' => 'Espo',
|
||||
'globalSearchEntityList' =>
|
||||
array (
|
||||
0 => 'Account',
|
||||
1 => 'Contact',
|
||||
2 => 'Lead',
|
||||
3 => 'Opportunity',
|
||||
'Account',
|
||||
'Contact',
|
||||
'Lead',
|
||||
'Opportunity',
|
||||
),
|
||||
"tabList" => array("Account", "Contact", "Lead", "Opportunity", "Calendar", "Meeting", "Call", "Task", "Case", "Email"),
|
||||
"tabList" => array("Account", "Contact", "Lead", "Opportunity", "Calendar", "Meeting", "Call", "Task", "Case", "Email", "Document", "Campaign"),
|
||||
"quickCreateList" => array("Account", "Contact", "Lead", "Opportunity", "Meeting", "Call", "Task", "Case"),
|
||||
'calendarDefaultEntity' => 'Meeting',
|
||||
'disableExport' => false,
|
||||
'assignmentEmailNotifications' => false,
|
||||
'assignmentEmailNotificationsEntityList' => array('Lead', 'Opportunity', 'Task', 'Case'),
|
||||
'assignmentNotificationsEntityList' => array('Meeting', 'Call', 'Task', 'Email'),
|
||||
'emailMessageMaxSize' => 10,
|
||||
'notificationsCheckInterval' => 10,
|
||||
'disabledCountQueryEntityList' => array('Email'),
|
||||
'maxEmailAccountCount' => 2,
|
||||
'followCreatedEntities' => false,
|
||||
'isInstalled' => false,
|
||||
);
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[{
|
||||
"label":"Overview",
|
||||
"rows": [
|
||||
[{"name":"name"}]
|
||||
[{"name":"name"}, false]
|
||||
]
|
||||
}]
|
||||
|
||||
@@ -54,6 +54,7 @@ return array (
|
||||
'maxJobNumber' => 15, /** Max number of jobs per one execution */
|
||||
'jobPeriod' => 7800, /** Period for jobs, ex. if cron executed at 15:35, it will execute all pending jobs for times from 14:05 to 15:35 */
|
||||
'minExecutionTime' => 50, /** to avoid too frequency execution **/
|
||||
'attempts' => 3, /** attempts to run jobs **/
|
||||
),
|
||||
'crud' => array(
|
||||
'get' => 'read',
|
||||
@@ -115,6 +116,7 @@ return array (
|
||||
'ldapTryUsernameSplit',
|
||||
'ldapOptReferrals',
|
||||
'ldapCreateEspoUser',
|
||||
'maxEmailAccountCount'
|
||||
),
|
||||
'isInstalled' => false,
|
||||
);
|
||||
|
||||
@@ -18,23 +18,22 @@
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with EspoCRM. If not, see http://www.gnu.org/licenses/.
|
||||
************************************************************************/
|
||||
************************************************************************/
|
||||
|
||||
namespace Espo\Entities;
|
||||
|
||||
class Email extends \Espo\Core\ORM\Entity
|
||||
{
|
||||
|
||||
protected function _getSubject()
|
||||
{
|
||||
return $this->get('name');
|
||||
}
|
||||
|
||||
|
||||
protected function _setSubject($value)
|
||||
{
|
||||
return $this->set('name', $value);
|
||||
}
|
||||
|
||||
|
||||
public function addAttachment(\Espo\Entities\Attachment $attachment)
|
||||
{
|
||||
if (!empty($this->id)) {
|
||||
@@ -45,16 +44,16 @@ class Email extends \Espo\Core\ORM\Entity
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function getBodyPlain()
|
||||
{
|
||||
$bodyPlain = $this->get('bodyPlain');
|
||||
$bodyPlain = $this->get('bodyPlain');
|
||||
if (!empty($bodyPlain)) {
|
||||
return $bodyPlain;
|
||||
}
|
||||
|
||||
$body = $this->get('body');
|
||||
|
||||
|
||||
$breaks = array("<br />","<br>","<br/>","<br />","<br />","<br/>","<br>");
|
||||
$body = str_ireplace($breaks, "\r\n", $body);
|
||||
$body = strip_tags($body);
|
||||
@@ -65,7 +64,7 @@ class Email extends \Espo\Core\ORM\Entity
|
||||
{
|
||||
return $this->getBodyPlain();
|
||||
}
|
||||
|
||||
|
||||
public function getBodyForSending()
|
||||
{
|
||||
$body = $this->get('body');
|
||||
@@ -75,19 +74,19 @@ class Email extends \Espo\Core\ORM\Entity
|
||||
$body = str_replace("?entryPoint=attachment&id={$attachment->id}", "cid:{$attachment->id}", $body);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$body = str_replace("<table class=\"table table-bordered\">", "<table class=\"table table-bordered\" width=\"100%\">", $body);
|
||||
|
||||
|
||||
return $body;
|
||||
}
|
||||
|
||||
|
||||
public function getInlineAttachments()
|
||||
{
|
||||
$attachmentList = array();
|
||||
$body = $this->get('body');
|
||||
if (!empty($body)) {
|
||||
if (preg_match_all("/\?entryPoint=attachment&id=([^&=\"']+)/", $body, $matches)) {
|
||||
if (!empty($matches[1]) && is_array($matches[1])) {
|
||||
if (preg_match_all("/\?entryPoint=attachment&id=([^&=\"']+)/", $body, $matches)) {
|
||||
if (!empty($matches[1]) && is_array($matches[1])) {
|
||||
foreach($matches[1] as $id) {
|
||||
$attachment = $this->entityManager->getEntity('Attachment', $id);
|
||||
if ($attachment) {
|
||||
@@ -96,7 +95,7 @@ class Email extends \Espo\Core\ORM\Entity
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
return $attachmentList;
|
||||
}
|
||||
|
||||
28
application/Espo/Entities/Import.php
Normal file
28
application/Espo/Entities/Import.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM - Open Source CRM application.
|
||||
* Copyright (C) 2014-2015 Yuri Kuznetsov, Taras Machyshyn, Oleksiy Avramenko
|
||||
* Website: http://www.espocrm.com
|
||||
*
|
||||
* EspoCRM is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* EspoCRM is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with EspoCRM. If not, see http://www.gnu.org/licenses/.
|
||||
************************************************************************/
|
||||
|
||||
namespace Espo\Entities;
|
||||
|
||||
class Import extends \Espo\Core\ORM\Entity
|
||||
{
|
||||
|
||||
}
|
||||
@@ -18,14 +18,19 @@
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with EspoCRM. If not, see http://www.gnu.org/licenses/.
|
||||
************************************************************************/
|
||||
************************************************************************/
|
||||
|
||||
namespace Espo\Entities;
|
||||
|
||||
class User extends \Espo\Core\Entities\Person
|
||||
{
|
||||
{
|
||||
public function isAdmin()
|
||||
{
|
||||
return $this->get('isAdmin');
|
||||
}
|
||||
|
||||
public function isActive()
|
||||
{
|
||||
return $this->get('isActive');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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\EntryPoints;
|
||||
|
||||
@@ -29,45 +29,51 @@ use \Espo\Core\Exceptions\BadRequest;
|
||||
class Download extends \Espo\Core\EntryPoints\Base
|
||||
{
|
||||
public static $authRequired = true;
|
||||
|
||||
|
||||
protected $fileTypesToShowInline = array(
|
||||
'application/pdf',
|
||||
'application/vnd.ms-word',
|
||||
'application/vnd.ms-excel',
|
||||
'application/vnd.oasis.opendocument.text',
|
||||
'application/vnd.oasis.opendocument.spreadsheet',
|
||||
'text/plain',
|
||||
'application/msword',
|
||||
'application/msexcel'
|
||||
);
|
||||
|
||||
|
||||
public function run()
|
||||
{
|
||||
{
|
||||
$id = $_GET['id'];
|
||||
if (empty($id)) {
|
||||
throw new BadRequest();
|
||||
}
|
||||
|
||||
|
||||
$attachment = $this->getEntityManager()->getEntity('Attachment', $id);
|
||||
|
||||
|
||||
if (!$attachment) {
|
||||
throw new NotFound();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if ($attachment->get('parentId') && $attachment->get('parentType')) {
|
||||
$parent = $this->getEntityManager()->getEntity($attachment->get('parentType'), $attachment->get('parentId'));
|
||||
$parent = $this->getEntityManager()->getEntity($attachment->get('parentType'), $attachment->get('parentId'));
|
||||
if (!$this->getAcl()->check($parent)) {
|
||||
throw new Forbidden();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$fileName = "data/upload/{$attachment->id}";
|
||||
|
||||
|
||||
if (!file_exists($fileName)) {
|
||||
throw new NotFound();
|
||||
}
|
||||
|
||||
|
||||
$type = $attachment->get('type');
|
||||
|
||||
|
||||
$disposition = 'attachment';
|
||||
if (in_array($type, $this->fileTypesToShowInline)) {
|
||||
$disposition = 'inline';
|
||||
}
|
||||
|
||||
|
||||
|
||||
header('Content-Description: File Transfer');
|
||||
if ($type) {
|
||||
header('Content-Type: ' . $type);
|
||||
@@ -80,7 +86,7 @@ class Download extends \Espo\Core\EntryPoints\Base
|
||||
ob_clean();
|
||||
flush();
|
||||
readfile($fileName);
|
||||
exit;
|
||||
}
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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\EntryPoints;
|
||||
|
||||
@@ -30,23 +30,23 @@ use \Espo\Core\Exceptions\Error;
|
||||
class LogoImage extends Image
|
||||
{
|
||||
public static $authRequired = false;
|
||||
|
||||
|
||||
public function run()
|
||||
{
|
||||
$this->imageSizes['small-logo'] = array(173, 38);
|
||||
|
||||
{
|
||||
$this->imageSizes['small-logo'] = array(181, 44);
|
||||
|
||||
$id = $this->getConfig()->get('companyLogoId');
|
||||
|
||||
|
||||
if (empty($id)) {
|
||||
throw new NotFound();
|
||||
}
|
||||
|
||||
$size = null;
|
||||
|
||||
$size = null;
|
||||
if (!empty($_GET['size'])) {
|
||||
$size = $_GET['size'];
|
||||
}
|
||||
|
||||
$this->show($id, $size);
|
||||
}
|
||||
|
||||
$this->show($id, $size);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -18,23 +18,24 @@
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with EspoCRM. If not, see http://www.gnu.org/licenses/.
|
||||
************************************************************************/
|
||||
************************************************************************/
|
||||
|
||||
namespace Espo\Hooks\Common;
|
||||
|
||||
use Espo\ORM\Entity;
|
||||
|
||||
class AssignmentEmailNotification extends \Espo\Core\Hooks\Base
|
||||
{
|
||||
|
||||
{
|
||||
public function afterSave(Entity $entity)
|
||||
{
|
||||
if (
|
||||
$this->getConfig()->get('assignmentEmailNotifications')
|
||||
&&
|
||||
&&
|
||||
$entity->has('assignedUserId')
|
||||
&&
|
||||
in_array($entity->getEntityName(), $this->getConfig()->get('assignmentEmailNotificationsEntityList', array()))
|
||||
) {
|
||||
|
||||
) {
|
||||
|
||||
$userId = $entity->get('assignedUserId');
|
||||
if (!empty($userId) && $userId != $this->getUser()->id && $entity->isFieldChanged('assignedUserId')) {
|
||||
$job = $this->getEntityManager()->getEntity('Job');
|
||||
@@ -50,7 +51,7 @@ class AssignmentEmailNotification extends \Espo\Core\Hooks\Base
|
||||
'executeTime' => date('Y-m-d H:i:s'),
|
||||
));
|
||||
$this->getEntityManager()->saveEntity($job);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
106
application/Espo/Hooks/Common/Notifications.php
Normal file
106
application/Espo/Hooks/Common/Notifications.php
Normal file
@@ -0,0 +1,106 @@
|
||||
<?php
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM - Open Source CRM application.
|
||||
* Copyright (C) 2014-2015 Yuri Kuznetsov, Taras Machyshyn, Oleksiy Avramenko
|
||||
* Website: http://www.espocrm.com
|
||||
*
|
||||
* EspoCRM is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* EspoCRM is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with EspoCRM. If not, see http://www.gnu.org/licenses/.
|
||||
************************************************************************/
|
||||
|
||||
namespace Espo\Hooks\Common;
|
||||
|
||||
use Espo\ORM\Entity;
|
||||
use Espo\Core\Utils\Util;
|
||||
|
||||
class Notifications extends \Espo\Core\Hooks\Base
|
||||
{
|
||||
public static $order = 10;
|
||||
|
||||
protected $noticatorsHash = array();
|
||||
|
||||
protected function init()
|
||||
{
|
||||
$this->dependencies[] = 'container';
|
||||
$this->dependencies[] = 'metadata';
|
||||
}
|
||||
|
||||
private $hasStreamCache = array();
|
||||
|
||||
protected function getContainer()
|
||||
{
|
||||
return $this->getInjection('container');
|
||||
}
|
||||
|
||||
protected function getMetadata()
|
||||
{
|
||||
return $this->getInjection('metadata');
|
||||
}
|
||||
|
||||
protected function checkHasStream($entityType)
|
||||
{
|
||||
if (!array_key_exists($entityType, $this->hasStreamCache)) {
|
||||
$this->hasStreamCache[$entityType] = $this->getMetadata()->get("scopes.{$entityType}.stream");
|
||||
}
|
||||
return $this->hasStreamCache[$entityType];
|
||||
}
|
||||
|
||||
protected function getNotificator($entityType)
|
||||
{
|
||||
if (empty($this->noticatorsHash[$entityType])) {
|
||||
$normalizedName = Util::normilizeClassName($entityType);
|
||||
|
||||
$className = '\\Espo\\Custom\\Notificators\\' . $normalizedName;
|
||||
if (!class_exists($className)) {
|
||||
$moduleName = $this->getMetadata()->getScopeModuleName($entityType);
|
||||
if ($moduleName) {
|
||||
$className = '\\Espo\\Modules\\' . $moduleName . '\\Notificators\\' . $normalizedName;
|
||||
} else {
|
||||
$className = '\\Espo\\Notificators\\' . $normalizedName;
|
||||
}
|
||||
if (!class_exists($className)) {
|
||||
$className = '\\Espo\\Core\\Notificators\\Base';
|
||||
}
|
||||
}
|
||||
|
||||
$notificator = new $className();
|
||||
$dependencies = $notificator->getDependencyList();
|
||||
foreach ($dependencies as $name) {
|
||||
$notificator->inject($name, $this->getContainer()->get($name));
|
||||
}
|
||||
|
||||
$this->noticatorsHash[$entityType] = $notificator;
|
||||
}
|
||||
return $this->noticatorsHash[$entityType];
|
||||
}
|
||||
|
||||
public function afterSave(Entity $entity, array $options = array())
|
||||
{
|
||||
$entityType = $entity->getEntityType();
|
||||
|
||||
if (!empty($options['silent']) && !empty($options['noNotifications'])) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!$this->checkHasStream($entityType)) {
|
||||
if (in_array($entityType, $this->getConfig()->get('assignmentNotificationsEntityList', []))) {
|
||||
$notificator = $this->getNotificator($entityType);
|
||||
$notificator->process($entity);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -34,11 +34,9 @@ class Stream extends \Espo\Core\Hooks\Base
|
||||
|
||||
protected $isLinkObservableInStreamCache = array();
|
||||
|
||||
protected $statusDefs = array(
|
||||
'Lead' => 'status',
|
||||
'Case' => 'status',
|
||||
'Opportunity' => 'stage',
|
||||
);
|
||||
protected $statusFields = null;
|
||||
|
||||
public static $order = 9;
|
||||
|
||||
protected function init()
|
||||
{
|
||||
@@ -131,51 +129,115 @@ class Stream extends \Espo\Core\Hooks\Base
|
||||
}
|
||||
}
|
||||
|
||||
public function afterSave(Entity $entity)
|
||||
protected function getAutofollowUserIdList(Entity $entity, array $ignoreList = array())
|
||||
{
|
||||
$entityType = $entity->getEntityName();
|
||||
$pdo = $this->getEntityManager()->getPDO();
|
||||
$userIdList = [];
|
||||
|
||||
$sql = "
|
||||
SELECT user_id AS 'userId' FROM autofollow WHERE entity_type = ".$pdo->quote($entityType)."
|
||||
";
|
||||
$sth = $pdo->prepare($sql);
|
||||
$sth->execute();
|
||||
$rows = $sth->fetchAll();
|
||||
foreach ($rows as $row) {
|
||||
$userId = $row['userId'];
|
||||
if (in_array($userId, $ignoreList)) {
|
||||
continue;
|
||||
}
|
||||
$userIdList[] = $userId;
|
||||
}
|
||||
|
||||
return $userIdList;
|
||||
}
|
||||
|
||||
public function afterSave(Entity $entity, array $options = array())
|
||||
{
|
||||
$entityName = $entity->getEntityName();
|
||||
|
||||
if ($this->checkHasStream($entity)) {
|
||||
if ($entity->isNew()) {
|
||||
$userIdList = [];
|
||||
|
||||
$assignedUserId = $entity->get('assignedUserId');
|
||||
$createdById = $entity->get('createdById');
|
||||
|
||||
if (!empty($createdById)) {
|
||||
$this->getStreamService()->followEntity($entity, $createdById);
|
||||
if ($this->getConfig()->get('followCreatedEntities') && !empty($createdById)) {
|
||||
$userIdList[] = $createdById;
|
||||
}
|
||||
if (!empty($assignedUserId) && !in_array($assignedUserId, $userIdList)) {
|
||||
$userIdList[] = $assignedUserId;
|
||||
}
|
||||
|
||||
if (!empty($assignedUserId) && $createdById != $assignedUserId) {
|
||||
$this->getStreamService()->followEntity($entity, $assignedUserId);
|
||||
if (!empty($userIdList)) {
|
||||
$this->getStreamService()->followEntityMass($entity, $userIdList);
|
||||
}
|
||||
$this->getStreamService()->noteCreate($entity);
|
||||
|
||||
} else {
|
||||
if ($entity->isFieldChanged('assignedUserId')) {
|
||||
$assignedUserId = $entity->get('assignedUserId');
|
||||
if (!empty($assignedUserId)) {
|
||||
$this->getStreamService()->followEntity($entity, $assignedUserId);
|
||||
$this->getStreamService()->noteAssign($entity);
|
||||
if (empty($options['noStream'])) {
|
||||
$this->getStreamService()->noteCreate($entity);
|
||||
}
|
||||
|
||||
$autofollowUserIdList = $this->getAutofollowUserIdList($entity, $userIdList);
|
||||
foreach ($autofollowUserIdList as $i => $userId) {
|
||||
if (in_array($userId, $userIdList)) {
|
||||
unset($autofollowUserIdList[$i]);
|
||||
}
|
||||
}
|
||||
$this->getStreamService()->handleAudited($entity);
|
||||
$autofollowUserIdList = array_values($autofollowUserIdList);
|
||||
|
||||
if (array_key_exists($entityName, $this->statusDefs)) {
|
||||
$field = $this->statusDefs[$entityName];
|
||||
$value = $entity->get($field);
|
||||
if (!empty($value) && $value != $entity->getFetched($field)) {
|
||||
$this->getStreamService()->noteStatus($entity, $field);
|
||||
if (!empty($autofollowUserIdList)) {
|
||||
$job = $this->getEntityManager()->getEntity('Job');
|
||||
$job->set(array(
|
||||
'serviceName' => 'Stream',
|
||||
'method' => 'afterRecordCreatedJob',
|
||||
'data' => array(
|
||||
'userIdList' => $autofollowUserIdList,
|
||||
'entityType' => $entity->getEntityType(),
|
||||
'entityId' => $entity->id
|
||||
)
|
||||
));
|
||||
$this->getEntityManager()->saveEntity($job);
|
||||
}
|
||||
|
||||
} else {
|
||||
if (empty($options['noStream'])) {
|
||||
if ($entity->isFieldChanged('assignedUserId')) {
|
||||
$assignedUserId = $entity->get('assignedUserId');
|
||||
if (!empty($assignedUserId)) {
|
||||
$this->getStreamService()->followEntity($entity, $assignedUserId);
|
||||
$this->getStreamService()->noteAssign($entity);
|
||||
}
|
||||
}
|
||||
$this->getStreamService()->handleAudited($entity);
|
||||
|
||||
$statusFields = $this->getStatusFields();
|
||||
|
||||
if (array_key_exists($entityName, $this->statusFields)) {
|
||||
$field = $this->statusFields[$entityName];
|
||||
$value = $entity->get($field);
|
||||
if (!empty($value) && $value != $entity->getFetched($field)) {
|
||||
$this->getStreamService()->noteStatus($entity, $field);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if ($entity->isNew() && $this->getMetadata()->get("scopes.{$entityName}.tab")) {
|
||||
if ($entity->isNew() && empty($options['noStream']) && $this->getMetadata()->get("scopes.{$entityName}.tab")) {
|
||||
$this->handleCreateRelated($entity);
|
||||
}
|
||||
}
|
||||
|
||||
protected function getStatusFields()
|
||||
{
|
||||
if (is_null($this->statusFields)) {
|
||||
$this->statusFields = $this->getMetadata()->get("entityDefs.Note.statusFields", array());
|
||||
}
|
||||
return $this->statusFields;
|
||||
}
|
||||
|
||||
protected function getStreamService()
|
||||
{
|
||||
if (empty($this->streamService)) {
|
||||
|
||||
@@ -40,7 +40,7 @@ class Notifications extends \Espo\Core\Hooks\Base
|
||||
return $this->getInjection('serviceFactory');
|
||||
}
|
||||
|
||||
protected function getMentionedUserList($entity)
|
||||
protected function getMentionedUserIdList($entity)
|
||||
{
|
||||
$mentionedUserList = array();
|
||||
$data = $entity->get('data');
|
||||
@@ -53,43 +53,49 @@ class Notifications extends \Espo\Core\Hooks\Base
|
||||
return $mentionedUserList;
|
||||
}
|
||||
|
||||
protected function getSubscriberIdList($parentType, $parentId)
|
||||
{
|
||||
$pdo = $this->getEntityManager()->getPDO();
|
||||
$sql = "
|
||||
SELECT user_id AS userId
|
||||
FROM subscription
|
||||
WHERE entity_id = " . $pdo->quote($parentId) . " AND entity_type = " . $pdo->quote($parentType);
|
||||
$sth = $pdo->prepare($sql);
|
||||
$sth->execute();
|
||||
$userIdList = [];
|
||||
while ($row = $sth->fetch(\PDO::FETCH_ASSOC)) {
|
||||
if ($this->getUser()->id != $row['userId']) {
|
||||
$userIdList[] = $row['userId'];
|
||||
}
|
||||
}
|
||||
return $userIdList;
|
||||
}
|
||||
|
||||
public function afterSave(Entity $entity)
|
||||
{
|
||||
if ($entity->isNew()) {
|
||||
|
||||
$parentType = $entity->get('parentType');
|
||||
$parentId = $entity->get('parentId');
|
||||
|
||||
$superParentType = $entity->get('superParentType');
|
||||
$superParentTypeId = $entity->get('superParentTypeId');
|
||||
|
||||
$userIdList = [];
|
||||
|
||||
if ($parentType && $parentId) {
|
||||
$userIdList = array_merge($userIdList, $this->getSubscriberIdList($parentType, $parentId));
|
||||
}
|
||||
|
||||
$mentionedUserList = $this->getMentionedUserList($entity);
|
||||
if ($superParentType && $superParentTypeId) {
|
||||
$userIdList = array_merge($userIdList, $this->getSubscriberIdList($superParentType, $superParentTypeId));
|
||||
}
|
||||
|
||||
$pdo = $this->getEntityManager()->getPDO();
|
||||
$sql = "
|
||||
SELECT user_id AS userId
|
||||
FROM subscription
|
||||
WHERE entity_id = " . $pdo->quote($parentId) . " AND entity_type = " . $pdo->quote($parentType);
|
||||
$sth = $pdo->prepare($sql);
|
||||
$sth->execute();
|
||||
$userIdList = array();
|
||||
while ($row = $sth->fetch(\PDO::FETCH_ASSOC)) {
|
||||
if ($this->getUser()->id != $row['userId'] && !in_array($row['userId'], $mentionedUserList)) {
|
||||
$userIdList[] = $row['userId'];
|
||||
}
|
||||
}
|
||||
if (!empty($userIdList)) {
|
||||
$job = $this->getEntityManager()->getEntity('Job');
|
||||
$job->set(array(
|
||||
'serviceName' => 'Notification',
|
||||
'method' => 'notifyAboutNoteFromJob',
|
||||
'data' => array(
|
||||
'userIdList' => $userIdList,
|
||||
'noteId' => $entity->id
|
||||
),
|
||||
'executeTime' => date('Y-m-d H:i:s'),
|
||||
));
|
||||
$this->getEntityManager()->saveEntity($job);
|
||||
}
|
||||
//$userIdList = array_merge($userIdList, $this->getMentionedUserIdList($entity));
|
||||
|
||||
$userIdList = array_unique($userIdList);
|
||||
|
||||
if (!empty($userIdList)) {
|
||||
$this->getNotificationService()->notifyAboutNote($userIdList, $entity);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,6 +32,10 @@ class Cleanup extends \Espo\Core\Jobs\Base
|
||||
{
|
||||
$this->cleanupJobs();
|
||||
$this->cleanupScheduledJobLog();
|
||||
$this->cleanupAttachments();
|
||||
$this->cleanupEmails();
|
||||
$this->cleanupNotes();
|
||||
$this->cleanupNotifications();
|
||||
}
|
||||
|
||||
protected function cleanupJobs()
|
||||
@@ -68,5 +72,87 @@ class Cleanup extends \Espo\Core\Jobs\Base
|
||||
$datetime->modify($this->period);
|
||||
return $datetime->format($format);
|
||||
}
|
||||
|
||||
protected function cleanupAttachments()
|
||||
{
|
||||
$pdo = $this->getEntityManager()->getPDO();
|
||||
|
||||
$dateBefore = date('Y-m-d H:i:s', time() - 3600 * 24);
|
||||
|
||||
$collection = $this->getEntityManager()->getRepository('Attachment')->where(array(
|
||||
'role' => ['Export File'],
|
||||
'createdAt<' => $dateBefore
|
||||
))->limit(0, 100)->find();
|
||||
|
||||
foreach ($collection as $e) {
|
||||
$this->getEntityManager()->removeEntity($e);
|
||||
}
|
||||
|
||||
$sql = "DELETE FROM attachment WHERE deleted = 1 AND created_at < ".$pdo->quote($dateBefore);
|
||||
$sth = $pdo->query($sql);
|
||||
}
|
||||
|
||||
protected function cleanupEmails()
|
||||
{
|
||||
$pdo = $this->getEntityManager()->getPDO();
|
||||
|
||||
$dateBefore = date('Y-m-d H:i:s', time() - 3600 * 24 * 20);
|
||||
|
||||
$sql = "SELECT * FROM email WHERE deleted = 1 AND created_at < ".$pdo->quote($dateBefore);
|
||||
$sth = $pdo->prepare($sql);
|
||||
$sth->execute();
|
||||
while ($row = $sth->fetch(\PDO::FETCH_ASSOC)) {
|
||||
$id = $row['id'];
|
||||
$attachments = $this->getEntityManager()->getRepository('Attachment')->where(array(
|
||||
'parentId' => $id,
|
||||
'parentType' => 'Email'
|
||||
))->find();
|
||||
foreach ($attachments as $attachment) {
|
||||
$this->getEntityManager()->removeEntity($attachment);
|
||||
}
|
||||
$sqlDel = "DELETE FROM email WHERE deleted = 1 AND id = ".$pdo->quote($id);
|
||||
$pdo->query($sqlDel);
|
||||
$sqlDel = "DELETE FROM email_user WHERE email_id = ".$pdo->quote($id);
|
||||
$pdo->query($sqlDel);
|
||||
}
|
||||
}
|
||||
|
||||
protected function cleanupNotes()
|
||||
{
|
||||
$pdo = $this->getEntityManager()->getPDO();
|
||||
|
||||
$dateBefore = date('Y-m-d H:i:s', time() - 3600 * 24 * 20);
|
||||
|
||||
$sql = "SELECT * FROM `note` WHERE deleted = 1 AND created_at < ".$pdo->quote($dateBefore);
|
||||
$sth = $pdo->prepare($sql);
|
||||
$sth->execute();
|
||||
while ($row = $sth->fetch(\PDO::FETCH_ASSOC)) {
|
||||
$id = $row['id'];
|
||||
$attachments = $this->getEntityManager()->getRepository('Attachment')->where(array(
|
||||
'parentId' => $id,
|
||||
'parentType' => 'Note'
|
||||
))->find();
|
||||
foreach ($attachments as $attachment) {
|
||||
$this->getEntityManager()->removeEntity($attachment);
|
||||
}
|
||||
$sqlDel = "DELETE FROM `note` WHERE deleted = 1 AND id = ".$pdo->quote($id);
|
||||
$pdo->query($sqlDel);
|
||||
}
|
||||
}
|
||||
|
||||
protected function cleanupNotifications()
|
||||
{
|
||||
$pdo = $this->getEntityManager()->getPDO();
|
||||
|
||||
$dateBefore = date('Y-m-d H:i:s', time() - 3600 * 24 * 50);
|
||||
|
||||
$sql = "SELECT * FROM `notification` WHERE created_at < ".$pdo->quote($dateBefore);
|
||||
$sth = $pdo->prepare($sql);
|
||||
$sth->execute();
|
||||
while ($row = $sth->fetch(\PDO::FETCH_ASSOC)) {
|
||||
$id = $row['id'];
|
||||
$this->getEntityManager()->getRepository('Notification')->deleteFromDb($id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<?php
|
||||
<?php
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
@@ -27,21 +27,21 @@ use \Espo\ORM\Entity;
|
||||
class Invitations
|
||||
{
|
||||
protected $entityManager;
|
||||
|
||||
|
||||
protected $smtpParams;
|
||||
|
||||
protected $mailSender;
|
||||
|
||||
|
||||
protected $config;
|
||||
|
||||
|
||||
protected $dateTime;
|
||||
|
||||
|
||||
protected $language;
|
||||
|
||||
|
||||
protected $fileManager;
|
||||
|
||||
|
||||
protected $ics;
|
||||
|
||||
|
||||
public function __construct($entityManager, $smtpParams, $mailSender, $config, $dateTime, $language, $fileManager)
|
||||
{
|
||||
$this->entityManager = $entityManager;
|
||||
@@ -52,17 +52,17 @@ class Invitations
|
||||
$this->language = $language;
|
||||
$this->fileManager = $fileManager;
|
||||
}
|
||||
|
||||
|
||||
protected function getEntityManager()
|
||||
{
|
||||
return $this->entityManager;
|
||||
}
|
||||
|
||||
|
||||
protected function parseInvitationTemplate($contents, $entity, $invitee = null, $uid = null)
|
||||
{
|
||||
|
||||
|
||||
$contents = str_replace('{eventType}', strtolower($this->language->translate($entity->getEntityName(), 'scopeNames')), $contents);
|
||||
|
||||
|
||||
foreach ($entity->getFields() as $field => $d) {
|
||||
if (empty($d['type'])) continue;
|
||||
$key = '{'.$field.'}';
|
||||
@@ -97,6 +97,7 @@ class Invitations
|
||||
if ($uid) {
|
||||
$contents = str_replace('{acceptLink}', $siteUrl . '?entryPoint=eventConfirmation&action=accept&uid=' . $uid->get('name'), $contents);
|
||||
$contents = str_replace('{declineLink}', $siteUrl . '?entryPoint=eventConfirmation&action=decline&uid=' . $uid->get('name'), $contents);
|
||||
$contents = str_replace('{tentativeLink}', $siteUrl . '?entryPoint=eventConfirmation&action=tentativeLink&uid=' . $uid->get('name'), $contents);
|
||||
}
|
||||
return $contents;
|
||||
}
|
||||
@@ -118,7 +119,7 @@ class Invitations
|
||||
|
||||
return file_get_contents($fileName);
|
||||
}
|
||||
|
||||
|
||||
public function sendInvitation(Entity $entity, Entity $invitee, $link)
|
||||
{
|
||||
$uid = $this->getEntityManager()->getEntity('UniqueId');
|
||||
@@ -144,14 +145,14 @@ class Invitations
|
||||
|
||||
$subject = $this->parseInvitationTemplate($subjectTpl, $entity, $invitee, $uid);
|
||||
$subject = str_replace(array("\n", "\r"), '', $subject);
|
||||
|
||||
|
||||
$body = $this->parseInvitationTemplate($bodyTpl, $entity, $invitee, $uid);
|
||||
|
||||
$email->set('subject', $subject);
|
||||
$email->set('body', $body);
|
||||
$email->set('isHtml', true);
|
||||
$this->getEntityManager()->saveEntity($email);
|
||||
|
||||
|
||||
$attachmentName = ucwords($this->language->translate($entity->getEntityName(), 'scopeNames')).'.ics';
|
||||
$attachment = $this->getEntityManager()->getEntity('Attachment');
|
||||
$attachment->set(array(
|
||||
@@ -159,7 +160,7 @@ class Invitations
|
||||
'type' => 'text/calendar',
|
||||
'contents' => $this->getIscContents($entity),
|
||||
));
|
||||
|
||||
|
||||
$email->addAttachment($attachment);
|
||||
|
||||
$emailSender = $this->mailSender;
|
||||
@@ -168,21 +169,21 @@ class Invitations
|
||||
$emailSender->useSmtp($this->smtpParams);
|
||||
}
|
||||
$emailSender->send($email);
|
||||
|
||||
|
||||
$this->getEntityManager()->removeEntity($email);
|
||||
}
|
||||
|
||||
|
||||
protected function getIscContents(Entity $entity)
|
||||
{
|
||||
$user = $entity->get('assignedUser');
|
||||
|
||||
|
||||
$who = '';
|
||||
$email = '';
|
||||
if ($user) {
|
||||
$who = $user->get('name');
|
||||
$email = $user->get('emailAddress');
|
||||
}
|
||||
|
||||
|
||||
$ics = new Ics('//EspoCRM//EspoCRM Calendar//EN', array(
|
||||
'startDate' => strtotime($entity->get('dateStart')),
|
||||
'endDate' => strtotime($entity->get('dateEnd')),
|
||||
@@ -192,9 +193,9 @@ class Invitations
|
||||
'email' => $email,
|
||||
'description' => $entity->get('description'),
|
||||
));
|
||||
|
||||
|
||||
return $ics->get();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -18,11 +18,11 @@
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with EspoCRM. If not, see http://www.gnu.org/licenses/.
|
||||
************************************************************************/
|
||||
************************************************************************/
|
||||
|
||||
namespace Espo\Modules\Crm\Controllers;
|
||||
|
||||
class Contract extends \Espo\Core\Controllers\Record
|
||||
class Campaign extends \Espo\Core\Controllers\Record
|
||||
{
|
||||
|
||||
}
|
||||
@@ -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\Modules\Crm\Controllers;
|
||||
|
||||
@@ -30,9 +30,9 @@ class InboundEmail extends \Espo\Core\Controllers\Record
|
||||
throw new Forbidden();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function actionGetFolders($params, $data, $request)
|
||||
{
|
||||
{
|
||||
return $this->getRecordService()->getFolders(array(
|
||||
'host' => $request->get('host'),
|
||||
'port' => $request->get('port'),
|
||||
@@ -41,7 +41,23 @@ class InboundEmail extends \Espo\Core\Controllers\Record
|
||||
'password' => $request->get('password'),
|
||||
'id' => $request->get('id')
|
||||
));
|
||||
}
|
||||
|
||||
public function actionTestConnection($params, $data, $request)
|
||||
{
|
||||
if (!$request->isPost()) {
|
||||
throw new BadRequest();
|
||||
}
|
||||
|
||||
if (is_null($data['password'])) {
|
||||
$inboundEmail = $this->getEntityManager()->getEntity('InboundEmail', $data['id']);
|
||||
if (!$inboundEmail) {
|
||||
throw new Error();
|
||||
}
|
||||
$data['password'] = $this->getContainer()->get('crypt')->decrypt($inboundEmail->get('password'));
|
||||
}
|
||||
|
||||
return $this->getRecordService()->testConnection($data);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user