mirror of
https://github.com/espocrm/espocrm.git
synced 2026-03-03 23:37:01 +00:00
Compare commits
1749 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
344da24b5e | ||
|
|
23ef028cb4 | ||
|
|
492d4869c2 | ||
|
|
56e45c32f8 | ||
|
|
cb41c55e7a | ||
|
|
7d63eaf3e0 | ||
|
|
1538b08fd9 | ||
|
|
82a8914848 | ||
|
|
2d5bf843d5 | ||
|
|
f22f6d54aa | ||
|
|
d609e4f70b | ||
|
|
8f56769e14 | ||
|
|
fa5b2da69e | ||
|
|
937202784d | ||
|
|
07424df41a | ||
|
|
e960ac472e | ||
|
|
84113356b5 | ||
|
|
3844946dc0 | ||
|
|
9ecdf5713c | ||
|
|
f1abd22512 | ||
|
|
c963058571 | ||
|
|
7e264780ec | ||
|
|
0750a89f74 | ||
|
|
5b52668359 | ||
|
|
3c91f8450d | ||
|
|
f820168283 | ||
|
|
bdb90a0016 | ||
|
|
521fa42bf1 | ||
|
|
1b272ea0c7 | ||
|
|
b055adfd87 | ||
|
|
42ea6e0d7c | ||
|
|
20b21622ed | ||
|
|
34c61a2fc5 | ||
|
|
cf8198dc98 | ||
|
|
c57fd2c55e | ||
|
|
3669bf4e11 | ||
|
|
b6bbdada06 | ||
|
|
804a618408 | ||
|
|
a1192474d9 | ||
|
|
dd28642370 | ||
|
|
b92295cbb1 | ||
|
|
d186cd2b1a | ||
|
|
9ebee47d5c | ||
|
|
3fdc7c8cf7 | ||
|
|
b298b26bab | ||
|
|
0a38857e64 | ||
|
|
2497e9bd88 | ||
|
|
bee44612e5 | ||
|
|
8946b4ad11 | ||
|
|
d4b78b9977 | ||
|
|
f9614385df | ||
|
|
7352abebe9 | ||
|
|
5c57b34893 | ||
|
|
0d873b7302 | ||
|
|
ccca6a8f55 | ||
|
|
bad9cc848f | ||
|
|
e3ab16a7bf | ||
|
|
6db068e625 | ||
|
|
64b1ac3ccf | ||
|
|
ca038970ff | ||
|
|
4d852c8515 | ||
|
|
b96ea5100b | ||
|
|
fd86727bfc | ||
|
|
8dacf66242 | ||
|
|
bbb4271dd1 | ||
|
|
8b72499c19 | ||
|
|
0a9a5a47af | ||
|
|
4304724315 | ||
|
|
8dc3c146e0 | ||
|
|
7cefff04a7 | ||
|
|
dd6d6995b9 | ||
|
|
3606dc39e3 | ||
|
|
03fef2fc8c | ||
|
|
704e548654 | ||
|
|
6120d5501d | ||
|
|
3f8c338265 | ||
|
|
ec07b23af8 | ||
|
|
cc349ca545 | ||
|
|
b16ec66eb3 | ||
|
|
22667e17f1 | ||
|
|
5741834d53 | ||
|
|
0df39cdc4f | ||
|
|
70489e8846 | ||
|
|
c4558ec633 | ||
|
|
5b500ae42a | ||
|
|
cdbe6a2383 | ||
|
|
48c650eab2 | ||
|
|
0c815b5761 | ||
|
|
9b104b9a16 | ||
|
|
97248e2b18 | ||
|
|
b3aa244f4e | ||
|
|
45c59ff242 | ||
|
|
0038c3666d | ||
|
|
7cfebbf87e | ||
|
|
0cd3666a96 | ||
|
|
d4a5f68398 | ||
|
|
1a30a9c29a | ||
|
|
cd75ddbbd7 | ||
|
|
55aedb7194 | ||
|
|
aa303d164f | ||
|
|
1723f63b21 | ||
|
|
55fef695ec | ||
|
|
42ee41ae54 | ||
|
|
676f480db8 | ||
|
|
233408b076 | ||
|
|
9dfec82f6e | ||
|
|
3c791b6363 | ||
|
|
5a0e5f6804 | ||
|
|
3376ab06d0 | ||
|
|
e8b22f9331 | ||
|
|
0b9104f992 | ||
|
|
566d0e50a6 | ||
|
|
be5a6a0ee0 | ||
|
|
4df460d6cb | ||
|
|
7443c969b1 | ||
|
|
3b5b1fb1b3 | ||
|
|
5737927e2d | ||
|
|
c59b837315 | ||
|
|
ce75b68df0 | ||
|
|
d17257fc95 | ||
|
|
ed996eff43 | ||
|
|
8f70c32687 | ||
|
|
d134db65a3 | ||
|
|
deaa3f3f73 | ||
|
|
5f5f6dcf38 | ||
|
|
8e373a9c33 | ||
|
|
f7a367d755 | ||
|
|
fea113269b | ||
|
|
5299da7a21 | ||
|
|
9a06ee3221 | ||
|
|
5b489e2341 | ||
|
|
5b0e4f910d | ||
|
|
575a4f12cc | ||
|
|
9b77f74e53 | ||
|
|
7be801c647 | ||
|
|
a95471a239 | ||
|
|
8982993813 | ||
|
|
cc48dc2a65 | ||
|
|
9e0d8632f5 | ||
|
|
2f751085e0 | ||
|
|
f5faae13c4 | ||
|
|
015fd4014c | ||
|
|
ff9c68d7f6 | ||
|
|
323138eebf | ||
|
|
43f15252bb | ||
|
|
25ad4ffa43 | ||
|
|
0cd3a464d8 | ||
|
|
71e9b313bb | ||
|
|
9b13f82c55 | ||
|
|
20cf214187 | ||
|
|
2d06568470 | ||
|
|
59ccd121c5 | ||
|
|
caa0256f19 | ||
|
|
b27b356997 | ||
|
|
3b76eec06c | ||
|
|
04a768ee40 | ||
|
|
0a3490d4f2 | ||
|
|
df71605c47 | ||
|
|
7424828f0c | ||
|
|
c9c759f33b | ||
|
|
98835fdb6c | ||
|
|
d32887ed40 | ||
|
|
6dd7573f7b | ||
|
|
0027e1bf9a | ||
|
|
eb10aa33d6 | ||
|
|
cfe77569f1 | ||
|
|
62da3462bc | ||
|
|
334b0baacc | ||
|
|
d16d177eaf | ||
|
|
2966f158fe | ||
|
|
1f57bcb250 | ||
|
|
90e775c27a | ||
|
|
9ff47844e7 | ||
|
|
042d98d05b | ||
|
|
0533c5a3ef | ||
|
|
0325f637b2 | ||
|
|
3d2bfe48b9 | ||
|
|
c8a538d73e | ||
|
|
fbc171b07f | ||
|
|
70e4921961 | ||
|
|
1ca96c7ca8 | ||
|
|
65359f103f | ||
|
|
e5afffbde1 | ||
|
|
66364e91b7 | ||
|
|
567ca19398 | ||
|
|
1e073def9d | ||
|
|
70c772dfd2 | ||
|
|
709259f45e | ||
|
|
dca51642e3 | ||
|
|
f24aea6354 | ||
|
|
c020cd4251 | ||
|
|
452e2ddc51 | ||
|
|
1860c69313 | ||
|
|
201beca8fa | ||
|
|
9182aeef99 | ||
|
|
d2cb7f60de | ||
|
|
c6beb0aac3 | ||
|
|
e394b12888 | ||
|
|
a461c8515f | ||
|
|
9bb36e1a35 | ||
|
|
1a5c75daac | ||
|
|
2c7633e74d | ||
|
|
996ad352e1 | ||
|
|
5c4b0d7723 | ||
|
|
6485ed38d6 | ||
|
|
48d9c0a7ff | ||
|
|
40c4b77cbf | ||
|
|
9b0ed1c833 | ||
|
|
bc6e74a092 | ||
|
|
52bdb136d4 | ||
|
|
f0e77da5d4 | ||
|
|
0b77c4cdfe | ||
|
|
2efa0c0ca7 | ||
|
|
87892c799c | ||
|
|
5bfa258881 | ||
|
|
d742de40c5 | ||
|
|
bb3bd0e915 | ||
|
|
8d50f52b7f | ||
|
|
bd2fd5eb3a | ||
|
|
2db25fda63 | ||
|
|
3067abcac2 | ||
|
|
c0c77e6e6b | ||
|
|
4037ffa295 | ||
|
|
2aa263847f | ||
|
|
50f9f24887 | ||
|
|
e36ee5aaff | ||
|
|
6d8017f1dc | ||
|
|
d22ce60f7b | ||
|
|
bc7d4f214f | ||
|
|
daa80d7196 | ||
|
|
8d3da43dca | ||
|
|
15b329580c | ||
|
|
0e2f8d9bf9 | ||
|
|
951d68724b | ||
|
|
f678253b05 | ||
|
|
0603eaf48d | ||
|
|
753caf7eeb | ||
|
|
5dbf719a53 | ||
|
|
1e945cff41 | ||
|
|
4a1237cdcc | ||
|
|
b60e65379e | ||
|
|
6da4e1796b | ||
|
|
2666f05bd5 | ||
|
|
461bffbf02 | ||
|
|
2653bba158 | ||
|
|
56d73519bf | ||
|
|
df3a7d78f4 | ||
|
|
898a7d89c7 | ||
|
|
2734b9bf8c | ||
|
|
2c074c6e82 | ||
|
|
1e67fe69e1 | ||
|
|
08cf333c0c | ||
|
|
0f62d7da13 | ||
|
|
8ce806d41f | ||
|
|
59a564cc1b | ||
|
|
1135573af6 | ||
|
|
c9a1e3733c | ||
|
|
6dbeba3473 | ||
|
|
351087781e | ||
|
|
92f977d6c2 | ||
|
|
489fbb8800 | ||
|
|
159c19fe08 | ||
|
|
c13e46554d | ||
|
|
6f45e26028 | ||
|
|
7e02481b35 | ||
|
|
79e94a8255 | ||
|
|
288398d4c2 | ||
|
|
92afc4deee | ||
|
|
f6892877c1 | ||
|
|
30c57921d1 | ||
|
|
d23bf569c0 | ||
|
|
796830d2dd | ||
|
|
286ec0325d | ||
|
|
c8338e1759 | ||
|
|
5f8adf51c1 | ||
|
|
c7cc44edf6 | ||
|
|
e958d7c488 | ||
|
|
77ff11990b | ||
|
|
e1538a5028 | ||
|
|
994e0c1eda | ||
|
|
d51e88be60 | ||
|
|
b1ba07a995 | ||
|
|
146a7aba1f | ||
|
|
981c60c78a | ||
|
|
2e85e7fc56 | ||
|
|
99edab675a | ||
|
|
1a8d3a3cdf | ||
|
|
43abd1740e | ||
|
|
261d60f338 | ||
|
|
1a36d7758b | ||
|
|
c09fc39881 | ||
|
|
0a7cd28ab5 | ||
|
|
bf8bf5e4d9 | ||
|
|
1defafd258 | ||
|
|
4854133f46 | ||
|
|
d93879a24d | ||
|
|
8ff6d2063c | ||
|
|
a46ecce6d0 | ||
|
|
49175ae1b1 | ||
|
|
532473df15 | ||
|
|
252ba4dccc | ||
|
|
1ddac304d7 | ||
|
|
44ecebad03 | ||
|
|
67d8c6cb17 | ||
|
|
c52ca7244f | ||
|
|
b42b276054 | ||
|
|
619a279dbb | ||
|
|
56e0c9928e | ||
|
|
25a424266b | ||
|
|
c8b13e07b1 | ||
|
|
9595d528a8 | ||
|
|
48cf4a6ed6 | ||
|
|
9de2b5f7ef | ||
|
|
9bfb27e10a | ||
|
|
be50630d2f | ||
|
|
7d7234a226 | ||
|
|
a7517bed9d | ||
|
|
66fca4dadd | ||
|
|
645b64437f | ||
|
|
efa2755f19 | ||
|
|
4fe0f53878 | ||
|
|
d8b629a5a0 | ||
|
|
5db5b41f7f | ||
|
|
6d0b39f2b6 | ||
|
|
909aa49e39 | ||
|
|
dd3d09f895 | ||
|
|
395182bda5 | ||
|
|
fd7d73756a | ||
|
|
aff95d47dd | ||
|
|
b778f74628 | ||
|
|
9f72d65281 | ||
|
|
6db658c0b3 | ||
|
|
6fb88665bb | ||
|
|
669cc2b883 | ||
|
|
dec262e999 | ||
|
|
cb03047ac3 | ||
|
|
8c5f94ace4 | ||
|
|
6269f02bca | ||
|
|
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 | ||
|
|
e0c3530ae5 | ||
|
|
8b4070f9ae | ||
|
|
0b6c5c2862 | ||
|
|
ce9ff10cb0 | ||
|
|
de688bfa12 | ||
|
|
f4ef5fc36f | ||
|
|
b1e184c6d1 | ||
|
|
fbf665fd76 | ||
|
|
95fd66a7a6 | ||
|
|
4b98ea79e0 | ||
|
|
2e916a2ba8 | ||
|
|
26a4d1c6ff | ||
|
|
33fef4c90e | ||
|
|
2dc15294fc | ||
|
|
171df33736 | ||
|
|
9b846b45bc | ||
|
|
bc65975f74 | ||
|
|
a5308831f2 | ||
|
|
ef05e4e9f4 | ||
|
|
83f0a81eb7 | ||
|
|
9e28d4a261 | ||
|
|
a9b3320302 | ||
|
|
b67580ee1d | ||
|
|
884ccb5265 | ||
|
|
ac56c3f79e | ||
|
|
e218056683 | ||
|
|
838288a463 | ||
|
|
e74b90d048 | ||
|
|
b2a653a3dc | ||
|
|
48ee7d4cc7 | ||
|
|
1d38f80748 | ||
|
|
c712366737 | ||
|
|
71f40fd440 | ||
|
|
9049ebfa8c | ||
|
|
f4b9356173 | ||
|
|
beaa4a29ba | ||
|
|
632ee66155 | ||
|
|
4446bc3167 | ||
|
|
785934c7cc | ||
|
|
ac36096d55 | ||
|
|
8ec8cb3c56 | ||
|
|
1f7cb2402d | ||
|
|
987ba2faa5 | ||
|
|
a24f697dca | ||
|
|
3825893ec1 | ||
|
|
a4ed78b953 | ||
|
|
c7947d0c46 | ||
|
|
eed9059913 | ||
|
|
20a1053413 | ||
|
|
16aca57f17 | ||
|
|
a225748840 | ||
|
|
fff1be9d07 | ||
|
|
b73ca3f1bc | ||
|
|
93a4f999b6 | ||
|
|
3030643ce4 | ||
|
|
e814ea9ec6 | ||
|
|
de16e9a9ce | ||
|
|
62fba991e2 | ||
|
|
832c63e014 | ||
|
|
46913c3574 | ||
|
|
0194d364b8 | ||
|
|
1c7785f6ba | ||
|
|
1049ec56eb | ||
|
|
734936b605 | ||
|
|
67e1a088ff | ||
|
|
af623631d1 | ||
|
|
8035bc424e | ||
|
|
7e99cd94b3 | ||
|
|
a88218aceb | ||
|
|
e5fd4dac4d | ||
|
|
26d407bd68 | ||
|
|
80ad96cce6 | ||
|
|
1d85ac3428 | ||
|
|
ca5dfd851d | ||
|
|
8c76b88b8d | ||
|
|
ff5616c399 | ||
|
|
2027b5aca9 | ||
|
|
a43e401ce7 | ||
|
|
396e2c176c | ||
|
|
4ab40990f5 | ||
|
|
35e325d8d0 | ||
|
|
b947d667d6 | ||
|
|
b4ab83d2d8 | ||
|
|
74adfb8b3e | ||
|
|
63bea467c3 | ||
|
|
cf449bba31 | ||
|
|
d247557fa9 | ||
|
|
bcd1c9618d | ||
|
|
cb1c87155f | ||
|
|
0b757b94a4 | ||
|
|
4ffcca7978 | ||
|
|
aac68b9624 | ||
|
|
4b0aeea778 | ||
|
|
1b9522f89c | ||
|
|
391f77d6f8 | ||
|
|
feb8a300d9 | ||
|
|
e2e77d59f9 | ||
|
|
2cb2d2cc2d | ||
|
|
d62c83d869 | ||
|
|
0639ab8424 | ||
|
|
9bdc19d3c2 | ||
|
|
6e26c093fa | ||
|
|
ca40c99ac2 | ||
|
|
6e1cef3d2f | ||
|
|
cc6f89366a | ||
|
|
d0e486a97c | ||
|
|
9c3db209d8 | ||
|
|
3ff6b93ccb | ||
|
|
2bfc86323d | ||
|
|
ed1a58cd1f | ||
|
|
3f89bd23af | ||
|
|
e2fa620a81 | ||
|
|
05b3645321 | ||
|
|
0e71e145bd | ||
|
|
f13baad163 | ||
|
|
2d60fa1edc | ||
|
|
2653873ff6 | ||
|
|
d849cf1115 | ||
|
|
28fcdca977 | ||
|
|
3f620ae742 | ||
|
|
0af8dde821 | ||
|
|
522931c64d | ||
|
|
265373bdcb | ||
|
|
0dbd649bff | ||
|
|
8fa4012267 | ||
|
|
477a57571b | ||
|
|
1de853ab95 | ||
|
|
4567d0de78 | ||
|
|
b2cc82d7e1 | ||
|
|
d3710cd8c0 | ||
|
|
2a4a9cbaa7 | ||
|
|
e27d02e782 | ||
|
|
ea1b7502bb | ||
|
|
69c173bc6c | ||
|
|
944fa45e76 | ||
|
|
eb2413085c | ||
|
|
04ecebbfef | ||
|
|
585ae2a58f | ||
|
|
9aae12f9ae | ||
|
|
73c6cabaa7 | ||
|
|
247075e168 | ||
|
|
6791733761 | ||
|
|
f6003088d8 | ||
|
|
95f93351ea | ||
|
|
b5bd7d043b | ||
|
|
8095665835 | ||
|
|
dd3f9d5ff8 | ||
|
|
7c39df74bc | ||
|
|
0a1497e3e8 | ||
|
|
25b81357c7 | ||
|
|
f7f380ff04 | ||
|
|
a09d99fe53 | ||
|
|
bdd6538984 | ||
|
|
2787d3bc72 | ||
|
|
72e53d096f | ||
|
|
acd48513f7 | ||
|
|
6ffa5654ea | ||
|
|
b2dfdb3446 | ||
|
|
dc5934a0ad | ||
|
|
ec586874a6 | ||
|
|
eb99d643b1 | ||
|
|
f6b37f346f | ||
|
|
180b31f6fa | ||
|
|
b16de8591e | ||
|
|
f87f418c1b | ||
|
|
f79fd38478 | ||
|
|
2e13f73b34 | ||
|
|
300f442b22 | ||
|
|
0f1c31e55a | ||
|
|
86633b31d3 | ||
|
|
f60aa78dde | ||
|
|
ae77cb1d77 | ||
|
|
74d99d8cda | ||
|
|
a90e0874bd | ||
|
|
141d20b472 | ||
|
|
6f08ecc1a7 | ||
|
|
3e4d6edac8 | ||
|
|
19784fc09c | ||
|
|
554f8cc37c | ||
|
|
c6153f6af3 | ||
|
|
048f5318fc | ||
|
|
62985c9776 | ||
|
|
9b30c02c22 | ||
|
|
122f18e8bf | ||
|
|
9d316da4e0 | ||
|
|
46439ff394 | ||
|
|
f73a60ad9f | ||
|
|
c05a153719 | ||
|
|
094f39e987 | ||
|
|
c247def1bc | ||
|
|
c7cd372554 | ||
|
|
ea951a8738 | ||
|
|
d9973bf353 | ||
|
|
0baaf82909 | ||
|
|
e62cb881c9 | ||
|
|
a965f6037f | ||
|
|
d6251f995c | ||
|
|
483c971e3e | ||
|
|
3186dcc65f | ||
|
|
e7aeebee8d | ||
|
|
14c3287131 | ||
|
|
4754b2db2f | ||
|
|
8fa0fae265 | ||
|
|
dc4c4bd084 | ||
|
|
6a5239cedc | ||
|
|
9ea9429757 | ||
|
|
20f89cf75a | ||
|
|
e8acf8aaaf | ||
|
|
0fac47e227 | ||
|
|
fe3cc09623 | ||
|
|
91445f2f9c | ||
|
|
053d516bc9 | ||
|
|
63a9f67bd9 | ||
|
|
344f0227e9 | ||
|
|
bdeaaa7965 | ||
|
|
2768a975d7 | ||
|
|
16384b9f72 | ||
|
|
db9d8e1006 | ||
|
|
c7dd503d80 | ||
|
|
c96265e2a9 | ||
|
|
ff35f7b1ff | ||
|
|
ac1748067b | ||
|
|
a4de09ea36 | ||
|
|
0816831fe1 | ||
|
|
2533854745 | ||
|
|
0e83325e92 | ||
|
|
b32f0976ee | ||
|
|
261e52e64d | ||
|
|
c616baf0a0 | ||
|
|
f1a990e80a | ||
|
|
a3a8110ae6 | ||
|
|
82a213555b | ||
|
|
3590ff2e33 | ||
|
|
775cfec744 | ||
|
|
9ca1d6608c | ||
|
|
59140b0814 | ||
|
|
90cf300334 | ||
|
|
7bd3c7cb0d | ||
|
|
ce75cc90f5 | ||
|
|
00a911434b | ||
|
|
69840086c9 | ||
|
|
5b2a07310e | ||
|
|
b72f6fa2cc | ||
|
|
f6ff8e77e4 | ||
|
|
9f9d0cb2dc | ||
|
|
6a036595d6 | ||
|
|
f4c57046dd | ||
|
|
ff492e2a81 | ||
|
|
1a401381c4 | ||
|
|
7b507f1bab | ||
|
|
c0b8c5e7d2 | ||
|
|
6e49afddf0 | ||
|
|
79dfd6177a | ||
|
|
4908f281a3 | ||
|
|
796b51d620 | ||
|
|
9cc44cf917 | ||
|
|
9f7eecac73 | ||
|
|
cba59fe847 | ||
|
|
07df97ab9e | ||
|
|
0a1322843f | ||
|
|
6c6a3621e8 | ||
|
|
4a075819d1 | ||
|
|
3aa3914f3a | ||
|
|
eef9c3e35c | ||
|
|
fe61fadc09 | ||
|
|
4c931514a2 | ||
|
|
8ad886d871 | ||
|
|
8492916d81 | ||
|
|
917f86a771 | ||
|
|
f3f13a1d96 | ||
|
|
f750330171 | ||
|
|
de19a8274a | ||
|
|
0d66e4097c | ||
|
|
93b8745599 | ||
|
|
55d54ee2da | ||
|
|
fa25dc715f | ||
|
|
c010cf43bf | ||
|
|
e52177a687 | ||
|
|
d424e6a282 | ||
|
|
51bdd15c9e | ||
|
|
b48f10b45f | ||
|
|
027e928bd3 | ||
|
|
3cfcfb02de | ||
|
|
322df7ff68 | ||
|
|
d58b9cac40 | ||
|
|
cca6567bbd | ||
|
|
26eb194ccb | ||
|
|
9b42ae41e7 | ||
|
|
83916cacd9 | ||
|
|
85b484c04e | ||
|
|
0d302e99af | ||
|
|
9e06108d23 | ||
|
|
ae4a6fa3d2 | ||
|
|
8f64fdd025 | ||
|
|
5ee83505af | ||
|
|
4527358a53 | ||
|
|
51cca50828 | ||
|
|
8f1752575a | ||
|
|
29c39fb4fd | ||
|
|
63663ccf6c | ||
|
|
1ba81c3350 | ||
|
|
e0b9b22ff4 | ||
|
|
f7879f425f | ||
|
|
93ed5dce6b | ||
|
|
17f8f1c291 | ||
|
|
bde5ca7b9e | ||
|
|
a08adcf6d5 | ||
|
|
a7bad6aa58 | ||
|
|
14d83c3a19 | ||
|
|
0ec182727a | ||
|
|
bd4057ed05 | ||
|
|
dcee02aed4 | ||
|
|
94b59404a7 | ||
|
|
77a3b5ee77 | ||
|
|
251e100e65 | ||
|
|
e87a69e6a3 | ||
|
|
e45b98d684 | ||
|
|
affc40959b | ||
|
|
e301514ec6 | ||
|
|
0c4c93487d | ||
|
|
7dc6622dd2 | ||
|
|
d7fea15f59 | ||
|
|
e73eb1ccc1 | ||
|
|
3f2cf25ef5 | ||
|
|
76f48900c3 | ||
|
|
a4d76666ac | ||
|
|
8a4ffb4d58 | ||
|
|
a9abfb41c7 | ||
|
|
cee6f58631 | ||
|
|
4075771a12 | ||
|
|
93d596fc95 | ||
|
|
9559e23e58 | ||
|
|
dc6c984b42 | ||
|
|
143cf3f8a1 | ||
|
|
f62436b19c | ||
|
|
7ca524e4ff | ||
|
|
ed4d5d5083 | ||
|
|
3bea0a130d | ||
|
|
8ac26402a2 | ||
|
|
4ff19c5910 | ||
|
|
eb08ca638e | ||
|
|
c373b97af1 | ||
|
|
6ea461faeb | ||
|
|
414576cade | ||
|
|
e35655b8a7 | ||
|
|
d8f3b24e31 | ||
|
|
771212a9a3 | ||
|
|
0d35ba8fe0 | ||
|
|
fd39508bc5 | ||
|
|
0299f30055 | ||
|
|
1cdef2245a | ||
|
|
059fdcfd14 | ||
|
|
4d6bb307ba | ||
|
|
c9fb16b8d7 | ||
|
|
15b2b3ea8e | ||
|
|
f442dbd54a | ||
|
|
aef3b0acf2 | ||
|
|
b0d2d22ab5 | ||
|
|
44c4ae7d28 | ||
|
|
426dc4592e | ||
|
|
db52fb3f0e | ||
|
|
16963fdc58 | ||
|
|
a0b5138216 | ||
|
|
515511a0d1 | ||
|
|
defa668138 | ||
|
|
526739a798 | ||
|
|
1655153b0a | ||
|
|
7cf931897e | ||
|
|
76f5bcb345 | ||
|
|
c112397003 | ||
|
|
2edb4d42f9 | ||
|
|
3e6ec34c91 | ||
|
|
ec417106cd | ||
|
|
d81af3dbed | ||
|
|
1d79c0b92b | ||
|
|
06fa7e99d4 | ||
|
|
5087adf12a | ||
|
|
a3e37fc1c0 | ||
|
|
833ef820aa | ||
|
|
d333d0f3c1 | ||
|
|
fcead3379b | ||
|
|
7fa5b30ae9 | ||
|
|
4f0a1a3fe1 | ||
|
|
d0fd77734c | ||
|
|
e19aca0649 | ||
|
|
1776972c34 | ||
|
|
e3e269cdaa | ||
|
|
c8bfa823e5 | ||
|
|
1efc8fe976 | ||
|
|
d711cbb524 | ||
|
|
c485da5b75 | ||
|
|
32bd385772 | ||
|
|
944e9e5e0b | ||
|
|
47a9515a15 | ||
|
|
fce8bb1acb | ||
|
|
de31441922 | ||
|
|
706bbf2117 | ||
|
|
3d28b46483 | ||
|
|
c272f25e07 | ||
|
|
ccbe9e8c31 | ||
|
|
bf9f443f86 | ||
|
|
532b9cfc7a | ||
|
|
b638a22964 | ||
|
|
fb5eb60b95 | ||
|
|
9f42fcdc4d | ||
|
|
d48e0a6cfe | ||
|
|
8a157729a6 | ||
|
|
01fcb13a12 | ||
|
|
7ddff0b631 | ||
|
|
e5e35a872f | ||
|
|
c76b61e65b | ||
|
|
305e9fb74a | ||
|
|
7d300d1e79 | ||
|
|
93f7cbb4e6 | ||
|
|
70ef83ac54 | ||
|
|
961e709843 | ||
|
|
3bd6e364ca | ||
|
|
17cf8da0d3 | ||
|
|
75c81ccdcf | ||
|
|
df0a958359 | ||
|
|
2e69169c9c | ||
|
|
fb7d313393 | ||
|
|
2ab50c2dcc | ||
|
|
873c683ffb | ||
|
|
6e911dcc41 | ||
|
|
d04133ac68 | ||
|
|
6ca27cb255 | ||
|
|
867aa72038 | ||
|
|
ca4c69570d | ||
|
|
66c5d92bc6 | ||
|
|
0f9c32869c | ||
|
|
8cea6559c1 | ||
|
|
3c6d383e08 | ||
|
|
cdffb85df0 | ||
|
|
884499ee58 | ||
|
|
8462632969 | ||
|
|
84e5fd762d | ||
|
|
eecda0d839 | ||
|
|
0829425aa4 | ||
|
|
be6c21e28c | ||
|
|
32a2df544f | ||
|
|
459b6eccb6 | ||
|
|
bfd611d6fe | ||
|
|
dadd8c8474 | ||
|
|
dc3f6080c9 | ||
|
|
f062c08b31 | ||
|
|
90a287af64 | ||
|
|
fd9d6d2220 | ||
|
|
1bb877c9b7 | ||
|
|
2199f0d483 | ||
|
|
b839c76a1e | ||
|
|
9ced6d7427 | ||
|
|
260d74882e | ||
|
|
7835d74efe | ||
|
|
66108324be | ||
|
|
b1b9dde29f | ||
|
|
c67f2b20d4 | ||
|
|
d78dd9cedb | ||
|
|
8330bb12f1 | ||
|
|
ceef826893 | ||
|
|
675975f763 | ||
|
|
3fd2382741 | ||
|
|
c70ab7c127 | ||
|
|
3cd9d49b4c | ||
|
|
8fafe2c47f | ||
|
|
b12cf2e21b | ||
|
|
6f22452cd9 | ||
|
|
3e0eaf1fa5 | ||
|
|
4f7946fe25 | ||
|
|
d1fd916be0 | ||
|
|
b3ccabcde0 | ||
|
|
c0e6d1191c | ||
|
|
b561c94ad1 | ||
|
|
ee1f71fff3 | ||
|
|
b39aa01ac9 | ||
|
|
b8263295c2 | ||
|
|
56ae7e5d3c | ||
|
|
156e69517f | ||
|
|
359a4ecc45 | ||
|
|
2538f8befc | ||
|
|
3bb0fdbf91 | ||
|
|
caec038c2c | ||
|
|
331602e32b | ||
|
|
cdbc91afcd | ||
|
|
b2fb451620 | ||
|
|
a548245fca | ||
|
|
d12ae68bf4 | ||
|
|
bfb0fcba0c | ||
|
|
40e639f4ba | ||
|
|
831b240f99 | ||
|
|
363aea4c96 | ||
|
|
8bbd918c51 | ||
|
|
304078420c | ||
|
|
6a7a7d9f04 | ||
|
|
fbeb19e69f | ||
|
|
7cfc539ce9 | ||
|
|
b65e23edfe | ||
|
|
3ba308e513 | ||
|
|
6379198019 | ||
|
|
016992573f | ||
|
|
96e827d64d | ||
|
|
cae40465f5 | ||
|
|
d2669dba5e | ||
|
|
e3aa0a40fe | ||
|
|
8dd9fb089a | ||
|
|
e2e384dd76 | ||
|
|
8a4e36a02d | ||
|
|
c4037c0333 | ||
|
|
cb3200f5dd | ||
|
|
e6def8bd4b | ||
|
|
218ce00930 | ||
|
|
ad12f78668 | ||
|
|
ea07895f02 | ||
|
|
023ab86684 | ||
|
|
dc6ba1128d | ||
|
|
40e6c6a648 | ||
|
|
982e3bd9b7 | ||
|
|
efefd8864c | ||
|
|
ca40ed79ee | ||
|
|
07866a266f | ||
|
|
5007b090fd | ||
|
|
95f6b8cd5c | ||
|
|
93f5da1a62 | ||
|
|
8632064bf7 | ||
|
|
544ad898a3 | ||
|
|
ea17b967c2 | ||
|
|
8db78f61d6 | ||
|
|
161673b88a | ||
|
|
6d81d9f6b2 | ||
|
|
f3ed8a67bc | ||
|
|
06702345da | ||
|
|
a5cb57dcfd | ||
|
|
36a4e48a2b | ||
|
|
074bd5a724 | ||
|
|
36b1fbff36 | ||
|
|
620e695d7e | ||
|
|
74dc2c07ea | ||
|
|
3b17d0ade3 | ||
|
|
07cf316c9c | ||
|
|
fa17104d13 | ||
|
|
274663e426 | ||
|
|
ec338fb0fd | ||
|
|
0093fb6670 | ||
|
|
8d36142ad1 | ||
|
|
8bcbec1e11 | ||
|
|
a1a8c157a0 | ||
|
|
7349edcb0c | ||
|
|
594eec29ce | ||
|
|
ff9db53f4f | ||
|
|
2f3fe50aff | ||
|
|
1e1a8c0ad0 | ||
|
|
03196e5728 | ||
|
|
c3bbdb2722 | ||
|
|
9e0e743dc5 | ||
|
|
a565b9c981 | ||
|
|
d85135dd69 | ||
|
|
380304dca1 | ||
|
|
c95c564961 | ||
|
|
9022aebc7e | ||
|
|
b91d6dc2cf | ||
|
|
1a2a8e6b9e | ||
|
|
6bf1de18e7 | ||
|
|
77fba6eb88 | ||
|
|
2e5cef2abb | ||
|
|
2dbb44eb16 | ||
|
|
6dc23517cc | ||
|
|
6c74281190 | ||
|
|
fa993957a1 | ||
|
|
bfa16ecabe | ||
|
|
c359b450f8 | ||
|
|
a638713e80 | ||
|
|
86715684e1 | ||
|
|
b79ea12b44 | ||
|
|
9f24998184 | ||
|
|
88018bf500 | ||
|
|
f95436f513 | ||
|
|
fa8c5adc25 | ||
|
|
0ee966eddd | ||
|
|
f723882f60 | ||
|
|
8333c51e42 | ||
|
|
6abc64fcb2 | ||
|
|
837b324fe8 | ||
|
|
6c56269f18 | ||
|
|
1101d717f2 | ||
|
|
8e177749ef | ||
|
|
ce30c759a3 | ||
|
|
56abf49301 | ||
|
|
f726881f48 | ||
|
|
d908da46cb | ||
|
|
230428456a | ||
|
|
fda8de500c | ||
|
|
583f3d33e8 | ||
|
|
d0abed98d1 | ||
|
|
38b820739d | ||
|
|
0ccda10de8 | ||
|
|
5358984b2d | ||
|
|
e972276487 | ||
|
|
91d4d9bcf9 | ||
|
|
7f3b489832 | ||
|
|
107584e0f9 | ||
|
|
0bf33e6110 | ||
|
|
9aaedea764 | ||
|
|
33c3594273 | ||
|
|
72824c2796 | ||
|
|
bf56c5fe60 | ||
|
|
5c93b49f6a | ||
|
|
f60fd168e6 | ||
|
|
1399913606 | ||
|
|
b233ab506d | ||
|
|
053793be9c | ||
|
|
53503fa615 | ||
|
|
ed4081596b | ||
|
|
6bdfb30c33 | ||
|
|
322d4cffcf | ||
|
|
1a9e03d540 | ||
|
|
cff5e0f688 | ||
|
|
85fb55c999 | ||
|
|
b944a98cf6 | ||
|
|
9c73f83353 | ||
|
|
5caa29b948 | ||
|
|
71efbe8eea | ||
|
|
81077a1c38 | ||
|
|
32e882780e | ||
|
|
23a373f2cf | ||
|
|
0a2c79ba81 | ||
|
|
5360ba0147 | ||
|
|
6620254d00 | ||
|
|
f6eb0bcce8 | ||
|
|
c1116ff5dc | ||
|
|
330fef673a | ||
|
|
7dcdfcd231 | ||
|
|
0eadb9af69 | ||
|
|
a269c0c96c | ||
|
|
ed37380d8e | ||
|
|
fdef9838d1 | ||
|
|
3c3518b857 | ||
|
|
e85f21da92 | ||
|
|
f3ab0a734c | ||
|
|
33adc67dee | ||
|
|
18e475e1b6 | ||
|
|
438c0f7edd | ||
|
|
3159c9d288 | ||
|
|
fe0f93784b | ||
|
|
2d237eae29 | ||
|
|
747aa2d882 | ||
|
|
46a7119ce1 | ||
|
|
c18342694f | ||
|
|
bb47b70f31 | ||
|
|
07767b2dae | ||
|
|
88037c8291 | ||
|
|
ee03c686ca | ||
|
|
78140f7d5e | ||
|
|
549acfd032 | ||
|
|
e4dab33792 | ||
|
|
287f95a8ac | ||
|
|
4951f8464e | ||
|
|
8ed9b9ebd2 | ||
|
|
96ed9612d4 | ||
|
|
1fd77a4c13 | ||
|
|
2390ac10a8 | ||
|
|
03572ecaad | ||
|
|
c1ac692304 | ||
|
|
f371090bde | ||
|
|
e28341f154 | ||
|
|
870f871ceb | ||
|
|
c18d892a4e | ||
|
|
c8bfd1c6dd | ||
|
|
c582860d5c | ||
|
|
1796db30fa | ||
|
|
25aa0ec564 | ||
|
|
f3dc904c65 | ||
|
|
343d33e741 | ||
|
|
276480dcfa | ||
|
|
b00b725af5 | ||
|
|
ab71ced531 | ||
|
|
ba7988a842 | ||
|
|
e1355acda1 | ||
|
|
1853f4f113 | ||
|
|
da677cfae8 | ||
|
|
272bccc2fd | ||
|
|
5372155773 | ||
|
|
e1579295da | ||
|
|
cc708e03d1 | ||
|
|
34e91958d6 | ||
|
|
928e4c2fb5 | ||
|
|
cf86fcda85 | ||
|
|
db3b36a639 | ||
|
|
a4a731437e | ||
|
|
51f4c7fa09 | ||
|
|
cbce4fc327 | ||
|
|
4e953f6fa8 | ||
|
|
0ed0420a4b | ||
|
|
16961795af | ||
|
|
c52c7fed59 | ||
|
|
95c00fc49d | ||
|
|
9f8606dd06 | ||
|
|
b33dc9baae | ||
|
|
8cb95f1b0e | ||
|
|
86cd1ab864 | ||
|
|
df842f3e3e | ||
|
|
572455ecf6 | ||
|
|
7692f9e3ad | ||
|
|
be0c1d8ab1 | ||
|
|
4a6c3d9e18 | ||
|
|
e0fdbd90fd | ||
|
|
18a3f2658a | ||
|
|
80ee06ec1d | ||
|
|
f16adeed99 | ||
|
|
9ca39f3559 | ||
|
|
19285372d6 | ||
|
|
61df6bec45 | ||
|
|
8904d4ddaf | ||
|
|
ca5fba97df | ||
|
|
fa755efefb | ||
|
|
d6085f4985 | ||
|
|
4c01e9329d | ||
|
|
9813eeb5bc | ||
|
|
09d571a639 | ||
|
|
fffd44316e | ||
|
|
a704830b86 | ||
|
|
7910f71428 | ||
|
|
52dcc51f4f | ||
|
|
f870ded9e0 | ||
|
|
224c72c875 | ||
|
|
ed50802073 | ||
|
|
1f5036eb5f | ||
|
|
701a60a07f | ||
|
|
c760f7364c | ||
|
|
4c28409a36 | ||
|
|
e932681166 | ||
|
|
a8209488ee | ||
|
|
d48642ca81 | ||
|
|
6561c4b6c2 | ||
|
|
4f5f84c8f7 | ||
|
|
56a04336fe | ||
|
|
1814529d3e | ||
|
|
1dbe2d9eac | ||
|
|
4ca099afc4 | ||
|
|
7ca09bc893 | ||
|
|
0a4a8c956a | ||
|
|
6f2a7ae08f | ||
|
|
45a9dd1226 | ||
|
|
9d904171c9 | ||
|
|
53abea7cdd | ||
|
|
6427604724 | ||
|
|
0d72dc7c2f | ||
|
|
9ee5a98ff4 | ||
|
|
3f0c92744c | ||
|
|
7a87749c4c | ||
|
|
0eaab6b7ee | ||
|
|
b52722565a | ||
|
|
80fd2a2006 | ||
|
|
1c1fdffb7d | ||
|
|
53481890db | ||
|
|
b82a3d0f31 | ||
|
|
1700b27501 | ||
|
|
635064e116 | ||
|
|
f6e45d8a68 | ||
|
|
ee0cf4bca5 | ||
|
|
ae98290721 | ||
|
|
24bbcf0e0a | ||
|
|
23b1945a3e | ||
|
|
e1fe3c03dd | ||
|
|
7e0034f674 | ||
|
|
d73cfbca53 | ||
|
|
3eec2b2a33 | ||
|
|
d60dc744e6 | ||
|
|
bd66211c3c | ||
|
|
2f341c8967 | ||
|
|
5c7612c9cf | ||
|
|
b41c0f34aa | ||
|
|
14eebc7392 | ||
|
|
5a86d0e396 | ||
|
|
a4e0c8107d | ||
|
|
1652de16a7 | ||
|
|
ad539e19a2 | ||
|
|
592f073bf9 | ||
|
|
d5c1d1b86e | ||
|
|
bd70e2424c | ||
|
|
06d6299d7f | ||
|
|
d00d2bdb0f | ||
|
|
9f481f6887 | ||
|
|
47d0501828 | ||
|
|
a4cd8dccfe | ||
|
|
eee0f0eb13 | ||
|
|
67b9600341 | ||
|
|
4c0329e6be | ||
|
|
ff6cd18411 | ||
|
|
8d4219802b | ||
|
|
07e7374a18 | ||
|
|
060f517591 | ||
|
|
1af5e93bd3 | ||
|
|
38df3162b3 | ||
|
|
e03298b041 | ||
|
|
80278b7213 | ||
|
|
a701905e9c | ||
|
|
59b896e594 | ||
|
|
ba4c8e0afd | ||
|
|
9175d8c7ce | ||
|
|
052fee6ba2 | ||
|
|
aae3afc895 | ||
|
|
1892ff6cae | ||
|
|
aa3e9fd8b0 | ||
|
|
2863092911 | ||
|
|
1c36421157 | ||
|
|
77f7da0ba5 | ||
|
|
a5f858dda2 | ||
|
|
a5b7bfc00e | ||
|
|
4d2cb6c38e | ||
|
|
b6bd70d47c | ||
|
|
ef3ed38b97 | ||
|
|
a38b86b2c6 | ||
|
|
a87044623c | ||
|
|
44a96ddece | ||
|
|
b0e911870b | ||
|
|
96bb421b0a | ||
|
|
c281d7b2d9 | ||
|
|
dc5766088f | ||
|
|
fe69f97b1e | ||
|
|
b7bc1e3622 | ||
|
|
b3c4123669 | ||
|
|
0795f6f6f2 | ||
|
|
c3cd909063 | ||
|
|
0e37c26b9f | ||
|
|
80937f8d09 | ||
|
|
380cdeba35 | ||
|
|
1eabce0d2e | ||
|
|
3cd5f801a5 | ||
|
|
c1cfd75bd6 | ||
|
|
dd5fabdfa4 | ||
|
|
3e9c7056b0 | ||
|
|
26188879b6 | ||
|
|
488717c6a1 | ||
|
|
b8476d7335 | ||
|
|
1cfad615c0 | ||
|
|
e3a3547a54 | ||
|
|
e6948aba2e | ||
|
|
d4943e4d1c | ||
|
|
af5e7d99b2 | ||
|
|
667a46f141 | ||
|
|
67f65492de | ||
|
|
b6a98e7121 | ||
|
|
9669ff91bb | ||
|
|
acb6e245a2 | ||
|
|
b5e015e9c9 | ||
|
|
70d2e311e5 | ||
|
|
6c7e5c0d02 | ||
|
|
d4558d73b3 | ||
|
|
e2257f6cfd | ||
|
|
149fa41e2b | ||
|
|
71e4c2fca0 | ||
|
|
5a4613617c | ||
|
|
cbf9dd458e | ||
|
|
08553bdf9d | ||
|
|
d0b61b42e0 | ||
|
|
3e3348c4a7 | ||
|
|
c32b0f365b | ||
|
|
8fd0554714 | ||
|
|
982f0e1f62 | ||
|
|
c87f5dfab3 | ||
|
|
b335462aa4 | ||
|
|
65f38a4906 |
13
.gitignore
vendored
13
.gitignore
vendored
@@ -2,16 +2,15 @@
|
||||
/data/cache/*
|
||||
/data/upload/*
|
||||
/data/preferences/*
|
||||
/data/.backup/*
|
||||
/data/config.php
|
||||
/custom
|
||||
/application/Espo/Resources/metadata/scopes/CustomTest.json
|
||||
/application/Espo/Modules/Crm/Resources/metadata/scopes/CustomTest.json
|
||||
/application/Espo/Resources/layouts/CustomTest/*
|
||||
/application/Espo/Modules/Crm/Resources/layouts/CustomTest/*
|
||||
/application/Espo/Resources/metadata/customTest/*
|
||||
/application/Espo/Modules/Crm/Resources/metadata/customTest/*
|
||||
/build
|
||||
/node_modules
|
||||
/client
|
||||
/test.php
|
||||
/main.html
|
||||
/frontend/client/css/bootstrap.css
|
||||
/tests/testData/cache/*
|
||||
composer.phar
|
||||
vendor/
|
||||
/custom/Espo/Custom/*
|
||||
26
.htaccess
26
.htaccess
@@ -1,10 +1,26 @@
|
||||
<ifModule mod_headers.c>
|
||||
Header always set Access-Control-Allow-Methods "POST, GET, PUT, PATCH, DELETE"
|
||||
</ifModule>
|
||||
|
||||
DirectoryIndex index.php index.html
|
||||
|
||||
RedirectMatch 403 \.config$
|
||||
|
||||
<IfModule mod_rewrite.c>
|
||||
RewriteEngine On
|
||||
RewriteRule .* - [E=HTTP_ESPO_CGI_AUTH:%{HTTP:Authorization}]
|
||||
RewriteEngine On
|
||||
|
||||
RewriteRule reset/?$ reset.html [QSA,L]
|
||||
# PROTECTED DIRECTORIES
|
||||
RewriteCond %{REQUEST_FILENAME} -d
|
||||
RewriteRule ^/?(data|api)/ - [F]
|
||||
|
||||
RewriteRule ^/?data/config\.php$ - [F]
|
||||
RewriteRule ^/?data/logs/ - [F]
|
||||
RewriteRule ^/?data/cache/ - [F]
|
||||
RewriteRule ^/?data/upload/ - [F]
|
||||
RewriteRule ^/?application/ - [F]
|
||||
RewriteRule ^/?custom/ - [F]
|
||||
RewriteRule ^/?vendor/ - [F]
|
||||
#END PROTECTED DIRECTORIES
|
||||
|
||||
RewriteRule .* - [E=HTTP_ESPO_CGI_AUTH:%{HTTP:Authorization}]
|
||||
|
||||
RewriteRule reset/?$ reset.html [QSA,L]
|
||||
</IfModule>
|
||||
500
Gruntfile.js
500
Gruntfile.js
@@ -1,243 +1,269 @@
|
||||
/************************************************************************
|
||||
* 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/.
|
||||
************************************************************************/
|
||||
module.exports = function (grunt) {
|
||||
|
||||
grunt.initConfig({
|
||||
pkg: grunt.file.readJSON('package.json'),
|
||||
|
||||
mkdir: {
|
||||
tmp: {
|
||||
options: {
|
||||
mode: 0775,
|
||||
create: [
|
||||
'build/tmp',
|
||||
]
|
||||
},
|
||||
|
||||
}
|
||||
},
|
||||
clean: {
|
||||
start: ['build/*'],
|
||||
final: ['build/tmp'],
|
||||
},
|
||||
less: {
|
||||
bootstrap: {
|
||||
options: {
|
||||
yuicompress: true,
|
||||
},
|
||||
files: {
|
||||
'frontend/client/css/bootstrap.css': 'frontend/less/espo/main.less',
|
||||
},
|
||||
},
|
||||
},
|
||||
cssmin: {
|
||||
minify: {
|
||||
files: {
|
||||
'build/tmp/client/css/espo.min.css': [
|
||||
'frontend/client/css/bootstrap.css',
|
||||
'frontend/client/css/datepicker.css',
|
||||
'frontend/client/css/jquery.timepicker.css',
|
||||
]
|
||||
}
|
||||
},
|
||||
},
|
||||
uglify: {
|
||||
options: {
|
||||
mangle: false,
|
||||
banner: '/*! <%= pkg.name %> <%= grunt.template.today("yyyy-mm-dd") %> */\n',
|
||||
},
|
||||
'build/tmp/client/espo.min.js': [
|
||||
'frontend/client/lib/jquery-2.0.2.min.js',
|
||||
'frontend/client/lib/underscore-min.js',
|
||||
'frontend/client/lib/backbone-min.js',
|
||||
'frontend/client/lib/handlebars.js',
|
||||
'frontend/client/lib/base64.js',
|
||||
'frontend/client/lib/jquery-ui.min.js',
|
||||
'frontend/client/lib/moment.min.js',
|
||||
'frontend/client/lib/moment-timezone-with-data.min.js',
|
||||
'frontend/client/lib/jquery.timepicker.min.js',
|
||||
'frontend/client/lib/jquery.autocomplete.js',
|
||||
'frontend/client/lib/bootstrap.min.js',
|
||||
'frontend/client/lib/bootstrap-datepicker.js',
|
||||
'frontend/client/lib/bull.min.js',
|
||||
'frontend/client/src/namespace.js',
|
||||
'frontend/client/src/exceptions.js',
|
||||
'frontend/client/src/app.js',
|
||||
'frontend/client/src/utils.js',
|
||||
'frontend/client/src/storage.js',
|
||||
'frontend/client/src/loader.js',
|
||||
'frontend/client/src/pre-loader.js',
|
||||
'frontend/client/src/ui.js',
|
||||
'frontend/client/src/acl.js',
|
||||
'frontend/client/src/model.js',
|
||||
'frontend/client/src/model-offline.js',
|
||||
'frontend/client/src/metadata.js',
|
||||
'frontend/client/src/language.js',
|
||||
'frontend/client/src/cache.js',
|
||||
'frontend/client/src/controller.js',
|
||||
'frontend/client/src/router.js',
|
||||
'frontend/client/src/date-time.js',
|
||||
'frontend/client/src/field-manager.js',
|
||||
'frontend/client/src/search-manager.js',
|
||||
'frontend/client/src/collection.js',
|
||||
'frontend/client/src/multi-collection.js',
|
||||
'frontend/client/src/view-helper.js',
|
||||
'frontend/client/src/layout-manager.js',
|
||||
'frontend/client/src/model-factory.js',
|
||||
'frontend/client/src/collection-factory.js',
|
||||
'frontend/client/src/models/settings.js',
|
||||
'frontend/client/src/models/user.js',
|
||||
'frontend/client/src/models/preferences.js',
|
||||
'frontend/client/src/controllers/base.js',
|
||||
'frontend/client/src/view.js',
|
||||
'frontend/client/src/views/base.js',
|
||||
'frontend/client/src/views/login.js',
|
||||
]
|
||||
},
|
||||
copy: {
|
||||
frontendFolders: {
|
||||
expand: true,
|
||||
cwd: 'frontend/client',
|
||||
src: [
|
||||
'src/**',
|
||||
'res/**',
|
||||
'fonts/**',
|
||||
'cfg/**',
|
||||
'modules/**',
|
||||
'img/**',
|
||||
'css/**',
|
||||
],
|
||||
dest: 'build/tmp/client',
|
||||
},
|
||||
frontendHtml: {
|
||||
src: 'frontend/html/reset.html',
|
||||
dest: 'build/tmp/reset.html'
|
||||
},
|
||||
frontendLib: {
|
||||
expand: true,
|
||||
dot: true,
|
||||
cwd: 'frontend/client/lib',
|
||||
src: '**',
|
||||
dest: 'build/tmp/client/lib/',
|
||||
},
|
||||
backend: {
|
||||
expand: true,
|
||||
dot: true,
|
||||
src: [
|
||||
'api/**',
|
||||
'application/**',
|
||||
'custom/**',
|
||||
'data/.data',
|
||||
'install/**',
|
||||
'vendor/**',
|
||||
'bootstrap.php',
|
||||
'cron.php',
|
||||
'rebuild.php',
|
||||
'index.php',
|
||||
'LICENSE.txt',
|
||||
'.htaccess',
|
||||
'Web.config',
|
||||
],
|
||||
dest: 'build/tmp/',
|
||||
},
|
||||
final: {
|
||||
expand: true,
|
||||
dot: true,
|
||||
src: '**',
|
||||
cwd: 'build/tmp',
|
||||
dest: 'build/EspoCRM-<%= pkg.version %>/',
|
||||
},
|
||||
},
|
||||
chmod: {
|
||||
options: {
|
||||
mode: '755'
|
||||
},
|
||||
php: {
|
||||
options: {
|
||||
mode: '644'
|
||||
},
|
||||
src: [
|
||||
'build/EspoCRM-<%= pkg.version %>/**/*.php',
|
||||
'build/EspoCRM-<%= pkg.version %>/**/*.json',
|
||||
'build/EspoCRM-<%= pkg.version %>/**/*.config',
|
||||
'build/EspoCRM-<%= pkg.version %>/**/.htaccess',
|
||||
'build/EspoCRM-<%= pkg.version %>/client/**/*.js',
|
||||
'build/EspoCRM-<%= pkg.version %>/client/**/*.css',
|
||||
'build/EspoCRM-<%= pkg.version %>/client/**/*.tpl',
|
||||
'build/EspoCRM-<%= pkg.version %>/**/*.html',
|
||||
'build/EspoCRM-<%= pkg.version %>/**/*.txt',
|
||||
]
|
||||
}
|
||||
},
|
||||
replace: {
|
||||
timestamp: {
|
||||
options: {
|
||||
patterns: [
|
||||
{
|
||||
match: 'timestamp',
|
||||
replacement: '<%= new Date().getTime() %>'
|
||||
}
|
||||
]
|
||||
},
|
||||
files: [
|
||||
{
|
||||
src: 'frontend/html/main.html',
|
||||
dest: 'build/tmp/main.html'
|
||||
}
|
||||
]
|
||||
},
|
||||
version: {
|
||||
options: {
|
||||
patterns: [
|
||||
{
|
||||
match: 'version',
|
||||
replacement: '<%= pkg.version %>'
|
||||
}
|
||||
]
|
||||
},
|
||||
files: [
|
||||
{
|
||||
src: 'build/tmp/application/Espo/Core/defaults/config.php',
|
||||
dest: 'build/tmp/application/Espo/Core/defaults/config.php'
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
compress: {
|
||||
final: {
|
||||
options: {
|
||||
archive: 'build/EspoCRM-<%= pkg.version %>.zip',
|
||||
mode: 'zip'
|
||||
},
|
||||
src: ['**'],
|
||||
cwd: 'build/EspoCRM-<%= pkg.version %>',
|
||||
dest: 'EspoCRM-<%= pkg.version %>'
|
||||
}
|
||||
}
|
||||
});
|
||||
var jsFilesToMinify = [
|
||||
'client/lib/jquery-2.0.2.min.js',
|
||||
'client/lib/underscore-min.js',
|
||||
'client/lib/backbone-min.js',
|
||||
'client/lib/handlebars.js',
|
||||
'client/lib/base64.js',
|
||||
'client/lib/jquery-ui.min.js',
|
||||
'client/lib/moment.min.js',
|
||||
'client/lib/moment-timezone-with-data.min.js',
|
||||
'client/lib/jquery.timepicker.min.js',
|
||||
'client/lib/jquery.autocomplete.js',
|
||||
'client/lib/bootstrap.min.js',
|
||||
'client/lib/bootstrap-datepicker.js',
|
||||
'client/lib/bull.min.js',
|
||||
'client/src/namespace.js',
|
||||
'client/src/exceptions.js',
|
||||
'client/src/app.js',
|
||||
'client/src/utils.js',
|
||||
'client/src/storage.js',
|
||||
'client/src/loader.js',
|
||||
'client/src/pre-loader.js',
|
||||
'client/src/ui.js',
|
||||
'client/src/acl.js',
|
||||
'client/src/model.js',
|
||||
'client/src/model-offline.js',
|
||||
'client/src/metadata.js',
|
||||
'client/src/language.js',
|
||||
'client/src/cache.js',
|
||||
'client/src/controller.js',
|
||||
'client/src/router.js',
|
||||
'client/src/date-time.js',
|
||||
'client/src/field-manager.js',
|
||||
'client/src/search-manager.js',
|
||||
'client/src/collection.js',
|
||||
'client/src/multi-collection.js',
|
||||
'client/src/view-helper.js',
|
||||
'client/src/layout-manager.js',
|
||||
'client/src/model-factory.js',
|
||||
'client/src/collection-factory.js',
|
||||
'client/src/models/settings.js',
|
||||
'client/src/models/user.js',
|
||||
'client/src/models/preferences.js',
|
||||
'client/src/controllers/base.js',
|
||||
'client/src/view.js',
|
||||
];
|
||||
|
||||
grunt.loadNpmTasks('grunt-contrib-clean');
|
||||
grunt.loadNpmTasks('grunt-mkdir');
|
||||
grunt.loadNpmTasks('grunt-contrib-less');
|
||||
grunt.loadNpmTasks('grunt-contrib-cssmin');
|
||||
grunt.loadNpmTasks('grunt-contrib-uglify');
|
||||
grunt.loadNpmTasks('grunt-contrib-copy');
|
||||
grunt.loadNpmTasks('grunt-replace');
|
||||
grunt.loadNpmTasks('grunt-contrib-compress');
|
||||
grunt.loadNpmTasks('grunt-chmod');
|
||||
grunt.initConfig({
|
||||
pkg: grunt.file.readJSON('package.json'),
|
||||
|
||||
grunt.registerTask('default', [
|
||||
'clean:start',
|
||||
'mkdir:tmp',
|
||||
'less',
|
||||
'cssmin',
|
||||
'uglify',
|
||||
'copy:frontendFolders',
|
||||
'copy:frontendHtml',
|
||||
'copy:frontendLib',
|
||||
'copy:backend',
|
||||
'replace',
|
||||
'copy:final',
|
||||
'chmod',
|
||||
'clean:final',
|
||||
]);
|
||||
mkdir: {
|
||||
tmp: {
|
||||
options: {
|
||||
mode: 0775,
|
||||
create: [
|
||||
'build/tmp',
|
||||
]
|
||||
},
|
||||
|
||||
}
|
||||
},
|
||||
clean: {
|
||||
start: ['build/*'],
|
||||
final: ['build/tmp'],
|
||||
},
|
||||
less: {
|
||||
bootstrap: {
|
||||
options: {
|
||||
yuicompress: true,
|
||||
},
|
||||
files: {
|
||||
'frontend/client/css/bootstrap.css': 'frontend/less/espo/main.less',
|
||||
},
|
||||
},
|
||||
},
|
||||
cssmin: {
|
||||
minify: {
|
||||
files: {
|
||||
'build/tmp/client/css/espo.min.css': [
|
||||
'frontend/client/css/bootstrap.css',
|
||||
'frontend/client/css/datepicker.css',
|
||||
'frontend/client/css/jquery.timepicker.css',
|
||||
]
|
||||
}
|
||||
},
|
||||
},
|
||||
uglify: {
|
||||
options: {
|
||||
mangle: false,
|
||||
banner: '/*! <%= pkg.name %> <%= grunt.template.today("yyyy-mm-dd") %> */\n',
|
||||
},
|
||||
'build/tmp/client/espo.min.js': jsFilesToMinify.map(function (item) {
|
||||
return 'frontend/' + item;
|
||||
})
|
||||
},
|
||||
copy: {
|
||||
frontendFolders: {
|
||||
expand: true,
|
||||
cwd: 'frontend/client',
|
||||
src: [
|
||||
'src/**',
|
||||
'res/**',
|
||||
'fonts/**',
|
||||
'cfg/**',
|
||||
'modules/**',
|
||||
'img/**',
|
||||
'css/**',
|
||||
'sounds/**',
|
||||
'custom/**'
|
||||
],
|
||||
dest: 'build/tmp/client',
|
||||
},
|
||||
frontendHtml: {
|
||||
src: 'frontend/html/reset.html',
|
||||
dest: 'build/tmp/reset.html'
|
||||
},
|
||||
frontendLib: {
|
||||
expand: true,
|
||||
dot: true,
|
||||
cwd: 'frontend/client/lib',
|
||||
src: '**',
|
||||
dest: 'build/tmp/client/lib/',
|
||||
},
|
||||
backend: {
|
||||
expand: true,
|
||||
dot: true,
|
||||
src: [
|
||||
'api/**',
|
||||
'application/**',
|
||||
'custom/**',
|
||||
'data/.data',
|
||||
'install/**',
|
||||
'vendor/**',
|
||||
'bootstrap.php',
|
||||
'cron.php',
|
||||
'rebuild.php',
|
||||
'clear_cache.php',
|
||||
'upgrade.php',
|
||||
'index.php',
|
||||
'LICENSE.txt',
|
||||
'.htaccess',
|
||||
'web.config',
|
||||
],
|
||||
dest: 'build/tmp/',
|
||||
},
|
||||
final: {
|
||||
expand: true,
|
||||
dot: true,
|
||||
src: '**',
|
||||
cwd: 'build/tmp',
|
||||
dest: 'build/EspoCRM-<%= pkg.version %>/',
|
||||
},
|
||||
},
|
||||
chmod: {
|
||||
options: {
|
||||
mode: '755'
|
||||
},
|
||||
php: {
|
||||
options: {
|
||||
mode: '644'
|
||||
},
|
||||
src: [
|
||||
'build/EspoCRM-<%= pkg.version %>/**/*.php',
|
||||
'build/EspoCRM-<%= pkg.version %>/**/*.json',
|
||||
'build/EspoCRM-<%= pkg.version %>/**/*.config',
|
||||
'build/EspoCRM-<%= pkg.version %>/**/.htaccess',
|
||||
'build/EspoCRM-<%= pkg.version %>/client/**/*.js',
|
||||
'build/EspoCRM-<%= pkg.version %>/client/**/*.css',
|
||||
'build/EspoCRM-<%= pkg.version %>/client/**/*.tpl',
|
||||
'build/EspoCRM-<%= pkg.version %>/**/*.html',
|
||||
'build/EspoCRM-<%= pkg.version %>/**/*.txt',
|
||||
]
|
||||
}
|
||||
},
|
||||
replace: {
|
||||
timestamp: {
|
||||
options: {
|
||||
patterns: [
|
||||
{
|
||||
match: 'timestamp',
|
||||
replacement: '<%= new Date().getTime() %>'
|
||||
}
|
||||
]
|
||||
},
|
||||
files: [
|
||||
{
|
||||
src: 'frontend/html/main.html',
|
||||
dest: 'build/tmp/main.html'
|
||||
}
|
||||
]
|
||||
},
|
||||
version: {
|
||||
options: {
|
||||
patterns: [
|
||||
{
|
||||
match: 'version',
|
||||
replacement: '<%= pkg.version %>'
|
||||
}
|
||||
]
|
||||
},
|
||||
files: [
|
||||
{
|
||||
src: 'build/tmp/application/Espo/Core/defaults/config.php',
|
||||
dest: 'build/tmp/application/Espo/Core/defaults/config.php'
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
compress: {
|
||||
final: {
|
||||
options: {
|
||||
archive: 'build/EspoCRM-<%= pkg.version %>.zip',
|
||||
mode: 'zip'
|
||||
},
|
||||
src: ['**'],
|
||||
cwd: 'build/EspoCRM-<%= pkg.version %>',
|
||||
dest: 'EspoCRM-<%= pkg.version %>'
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
grunt.loadNpmTasks('grunt-contrib-clean');
|
||||
grunt.loadNpmTasks('grunt-mkdir');
|
||||
grunt.loadNpmTasks('grunt-contrib-less');
|
||||
grunt.loadNpmTasks('grunt-contrib-cssmin');
|
||||
grunt.loadNpmTasks('grunt-contrib-uglify');
|
||||
grunt.loadNpmTasks('grunt-contrib-copy');
|
||||
grunt.loadNpmTasks('grunt-replace');
|
||||
grunt.loadNpmTasks('grunt-contrib-compress');
|
||||
grunt.loadNpmTasks('grunt-chmod');
|
||||
|
||||
grunt.registerTask('default', [
|
||||
'clean:start',
|
||||
'mkdir:tmp',
|
||||
'less',
|
||||
'cssmin',
|
||||
'uglify',
|
||||
'copy:frontendFolders',
|
||||
'copy:frontendHtml',
|
||||
'copy:frontendLib',
|
||||
'copy:backend',
|
||||
'replace',
|
||||
'copy:final',
|
||||
'chmod',
|
||||
'clean:final',
|
||||
]);
|
||||
|
||||
};
|
||||
|
||||
61
README.md
Normal file
61
README.md
Normal file
@@ -0,0 +1,61 @@
|
||||
## EspoCRM
|
||||
|
||||
<a href='http://www.espocrm.com'>EspoCRM is an Open Source CRM</a> (Customer Relationship Management) software that allows you to see, enter and evaluate all your company relationships regardless of the type. People, companies or opportunities - all in an easy and intuitive interface.
|
||||
|
||||
It's a web application with a frontend designed as a single page application based on backbone.js and a REST API backend written in PHP.
|
||||
|
||||
Download the latest release from our [website](http://www.espocrm.com).
|
||||
|
||||
### Requirements
|
||||
|
||||
* PHP 5.4 or above (with pdo, json, gd, mcrypt extensions);
|
||||
* MySQL 5.1 or above.
|
||||
|
||||
For more information about server configuration see [this article](http://blog.espocrm.com/administration/server-configuration-for-espocrm/).
|
||||
|
||||
### How to report bug
|
||||
|
||||
Create an issue [here](https://github.com/espocrm/espocrm/issues) or post on our [forum](http://forum.espocrm.com/bug-reports?routestring=forum/bug-reports).
|
||||
|
||||
### How to get started (for developers)
|
||||
|
||||
1. Clone repository to your local computer.
|
||||
2. Change to the project's root directory.
|
||||
3. Install [composer](https://getcomposer.org/doc/00-intro.md).
|
||||
4. Run `composer install` if composer is installed globally or `php composer.phar install` if locally.
|
||||
|
||||
Never update composer dependencies if you are going to contribute code back.
|
||||
|
||||
Now you can build.
|
||||
|
||||
If your repository is accessible via a web server then you can run EspoCRM by url `http://PROJECT_URL/frontend`. To compose a proper config.php and populate database you can run install by opening `http(s)://{YOUR_CRM_URL}/install` location in a browser. Also you need to run build before to have compiled css.
|
||||
|
||||
### How to build
|
||||
|
||||
You need to have nodejs and Grunt CLI installed.
|
||||
|
||||
1. Change to the project's root directory.
|
||||
2. Install project dependencies with `npm install`.
|
||||
3. Run Grunt with `grunt`.
|
||||
|
||||
The build will be created in the `build` directory.
|
||||
|
||||
### 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).
|
||||
|
||||
22
Web.config
22
Web.config
@@ -1,22 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<configuration>
|
||||
|
||||
<system.webServer>
|
||||
<rewrite>
|
||||
<rules>
|
||||
<rule name="rule 1X" stopProcessing="true">
|
||||
<match url="reset/?$" />
|
||||
<action type="Rewrite" url="reset.html" appendQueryString="true" />
|
||||
</rule>
|
||||
</rules>
|
||||
</rewrite>
|
||||
|
||||
<defaultDocument>
|
||||
<files>
|
||||
<clear />
|
||||
<add value="index.php" />
|
||||
</files>
|
||||
</defaultDocument>
|
||||
</system.webServer>
|
||||
|
||||
</configuration>
|
||||
@@ -1,4 +1,24 @@
|
||||
<?php
|
||||
<?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/.
|
||||
************************************************************************/
|
||||
|
||||
require_once('../../bootstrap.php');
|
||||
|
||||
|
||||
@@ -1,2 +0,0 @@
|
||||
Order Deny,Allow
|
||||
Deny from all
|
||||
72
application/Espo/Acl/Email.php
Normal file
72
application/Espo/Acl/Email.php
Normal file
@@ -0,0 +1,72 @@
|
||||
<?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\Acl;
|
||||
|
||||
use \Espo\Entities\User;
|
||||
use \Espo\ORM\Entity;
|
||||
|
||||
class Email extends \Espo\Core\Acl\Base
|
||||
{
|
||||
|
||||
public function checkEntityRead(User $user, Entity $entity, $data)
|
||||
{
|
||||
if ($this->checkEntity($user, $entity, $data, 'read')) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ($data === false) {
|
||||
return false;
|
||||
}
|
||||
if (is_array($data)) {
|
||||
if (empty($data['read']) || $data['read'] == 'no') {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (!$entity->has('usersIds')) {
|
||||
$entity->loadLinkMultipleField('users');
|
||||
}
|
||||
$userIdList = $entity->get('usersIds');
|
||||
if (is_array($userIdList) && in_array($user->id, $userIdList)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function checkIsOwner(User $user, Entity $entity)
|
||||
{
|
||||
if ($entity->has('assignedUserId')) {
|
||||
if ($user->id === $entity->get('assignedUserId')) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if ($user->id === $entity->get('createdById')) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM - Open Source CRM application.
|
||||
* Copyright (C) 2014 Yuri Kuznetsov, Taras Machyshyn, Oleksiy Avramenko
|
||||
* 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
|
||||
@@ -27,60 +27,60 @@ use \Espo\Core\Exceptions\Error,
|
||||
|
||||
class Admin extends \Espo\Core\Controllers\Base
|
||||
{
|
||||
protected function checkControllerAccess()
|
||||
{
|
||||
if (!$this->getUser()->isAdmin()) {
|
||||
throw new Forbidden();
|
||||
}
|
||||
}
|
||||
protected function checkControllerAccess()
|
||||
{
|
||||
if (!$this->getUser()->isAdmin()) {
|
||||
throw new Forbidden();
|
||||
}
|
||||
}
|
||||
|
||||
public function actionRebuild($params, $data)
|
||||
{
|
||||
$result = $this->getContainer()->get('dataManager')->rebuild();
|
||||
public function actionRebuild($params, $data)
|
||||
{
|
||||
$result = $this->getContainer()->get('dataManager')->rebuild();
|
||||
|
||||
return $result;
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function actionClearCache($params, $data)
|
||||
{
|
||||
$result = $this->getContainer()->get('dataManager')->clearCache();
|
||||
public function actionClearCache($params, $data)
|
||||
{
|
||||
$result = $this->getContainer()->get('dataManager')->clearCache();
|
||||
|
||||
return $result;
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function actionJobs()
|
||||
{
|
||||
$scheduledJob = $this->getContainer()->get('scheduledJob');
|
||||
public function actionJobs()
|
||||
{
|
||||
$scheduledJob = $this->getContainer()->get('scheduledJob');
|
||||
|
||||
return $scheduledJob->getAllNamesOnly();
|
||||
}
|
||||
return $scheduledJob->getAllNamesOnly();
|
||||
}
|
||||
|
||||
public function actionUploadUpgradePackage($params, $data)
|
||||
{
|
||||
$upgradeManager = new \Espo\Core\UpgradeManager($this->getContainer());
|
||||
public function actionUploadUpgradePackage($params, $data)
|
||||
{
|
||||
$upgradeManager = new \Espo\Core\UpgradeManager($this->getContainer());
|
||||
|
||||
$upgradeId = $upgradeManager->upload($data);
|
||||
$manifest = $upgradeManager->getManifest();
|
||||
$upgradeId = $upgradeManager->upload($data);
|
||||
$manifest = $upgradeManager->getManifest();
|
||||
|
||||
return array(
|
||||
'id' => $upgradeId,
|
||||
'version' => $manifest['version'],
|
||||
);
|
||||
}
|
||||
return array(
|
||||
'id' => $upgradeId,
|
||||
'version' => $manifest['version'],
|
||||
);
|
||||
}
|
||||
|
||||
public function actionRunUpgrade($params, $data)
|
||||
{
|
||||
$upgradeManager = new \Espo\Core\UpgradeManager($this->getContainer());
|
||||
public function actionRunUpgrade($params, $data)
|
||||
{
|
||||
$upgradeManager = new \Espo\Core\UpgradeManager($this->getContainer());
|
||||
|
||||
$upgradeManager->run($data['id']);
|
||||
$upgradeManager->install($data);
|
||||
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public function actionCronMessage($params, $data)
|
||||
{
|
||||
return $this->getContainer()->get('scheduledJob')->getSetupMessage();
|
||||
}
|
||||
public function actionCronMessage($params, $data)
|
||||
{
|
||||
return $this->getContainer()->get('scheduledJob')->getSetupMessage();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM - Open Source CRM application.
|
||||
* Copyright (C) 2014 Yuri Kuznetsov, Taras Machyshyn, Oleksiy Avramenko
|
||||
* 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
|
||||
@@ -18,33 +18,41 @@
|
||||
*
|
||||
* 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;
|
||||
|
||||
class App extends \Espo\Core\Controllers\Record
|
||||
class App extends \Espo\Core\Controllers\Base
|
||||
{
|
||||
public function actionUser()
|
||||
{
|
||||
return array(
|
||||
'user' => $this->getUser()->toArray(),
|
||||
'acl' => $this->getAcl()->toArray(),
|
||||
'preferences' => $this->getPreferences()->toArray(),
|
||||
'token' => $this->getUser()->get('token')
|
||||
);
|
||||
}
|
||||
|
||||
public function actionDestroyAuthToken($params, $data)
|
||||
{
|
||||
$token = $data['token'];
|
||||
if (empty($token)) {
|
||||
throw new BadRequest();
|
||||
}
|
||||
public function actionUser()
|
||||
{
|
||||
$preferences = $this->getPreferences()->toArray();
|
||||
unset($preferences['smtpPassword']);
|
||||
|
||||
$auth = new \Espo\Core\Utils\Auth($this->getContainer());
|
||||
return $auth->destroyAuthToken($token);
|
||||
}
|
||||
$user = $this->getUser();
|
||||
if (!$user->has('teamsIds')) {
|
||||
$user->loadLinkMultipleField('teams');
|
||||
}
|
||||
|
||||
return array(
|
||||
'user' => $user->toArray(),
|
||||
'acl' => $this->getAcl()->getMap(),
|
||||
'preferences' => $preferences,
|
||||
'token' => $this->getUser()->get('token')
|
||||
);
|
||||
}
|
||||
|
||||
public function actionDestroyAuthToken($params, $data)
|
||||
{
|
||||
$token = $data['token'];
|
||||
if (empty($token)) {
|
||||
throw new BadRequest();
|
||||
}
|
||||
|
||||
$auth = new \Espo\Core\Utils\Auth($this->getContainer());
|
||||
return $auth->destroyAuthToken($token);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM - Open Source CRM application.
|
||||
* Copyright (C) 2014 Yuri Kuznetsov, Taras Machyshyn, Oleksiy Avramenko
|
||||
* 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
|
||||
@@ -25,19 +25,19 @@ namespace Espo\Controllers;
|
||||
class Attachment extends \Espo\Core\Controllers\Record
|
||||
{
|
||||
|
||||
public function actionUpload($params, $data)
|
||||
{
|
||||
list($prefix, $contents) = explode(',', $data);
|
||||
$contents = base64_decode($contents);
|
||||
|
||||
$attachment = $this->getEntityManager()->getEntity('Attachment');
|
||||
$this->getEntityManager()->saveEntity($attachment);
|
||||
$this->getContainer()->get('fileManager')->putContents('data/upload/' . $attachment->id, $contents);
|
||||
|
||||
return array(
|
||||
'attachmentId' => $attachment->id
|
||||
);
|
||||
}
|
||||
public function actionUpload($params, $data)
|
||||
{
|
||||
list($prefix, $contents) = explode(',', $data);
|
||||
$contents = base64_decode($contents);
|
||||
|
||||
$attachment = $this->getEntityManager()->getEntity('Attachment');
|
||||
$this->getEntityManager()->saveEntity($attachment);
|
||||
$this->getContainer()->get('fileManager')->putContents('data/upload/' . $attachment->id, $contents);
|
||||
|
||||
return array(
|
||||
'attachmentId' => $attachment->id
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM - Open Source CRM application.
|
||||
* Copyright (C) 2014 Yuri Kuznetsov, Taras Machyshyn, Oleksiy Avramenko
|
||||
* 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
|
||||
@@ -25,42 +25,42 @@ namespace Espo\Controllers;
|
||||
use \Espo\Core\Exceptions\Forbidden;
|
||||
|
||||
class AuthToken extends \Espo\Core\Controllers\Record
|
||||
{
|
||||
protected function checkControllerAccess()
|
||||
{
|
||||
if (!$this->getUser()->isAdmin()) {
|
||||
throw new Forbidden();
|
||||
}
|
||||
}
|
||||
|
||||
public function actionUpdate($params, $data)
|
||||
{
|
||||
throw new Forbidden();
|
||||
}
|
||||
|
||||
public function actionCreate($params, $data)
|
||||
{
|
||||
throw new Forbidden();
|
||||
}
|
||||
|
||||
public function actionListLinked($params, $data)
|
||||
{
|
||||
throw new Forbidden();
|
||||
}
|
||||
|
||||
public function actionMassUpdate($params, $data)
|
||||
{
|
||||
throw new Forbidden();
|
||||
}
|
||||
|
||||
public function actionCreateLink($params, $data)
|
||||
{
|
||||
throw new Forbidden();
|
||||
}
|
||||
|
||||
public function actionRemoveLink($params, $data)
|
||||
{
|
||||
throw new Forbidden();
|
||||
}
|
||||
{
|
||||
protected function checkControllerAccess()
|
||||
{
|
||||
if (!$this->getUser()->isAdmin()) {
|
||||
throw new Forbidden();
|
||||
}
|
||||
}
|
||||
|
||||
public function actionUpdate($params, $data)
|
||||
{
|
||||
throw new Forbidden();
|
||||
}
|
||||
|
||||
public function actionCreate($params, $data)
|
||||
{
|
||||
throw new Forbidden();
|
||||
}
|
||||
|
||||
public function actionListLinked($params, $data)
|
||||
{
|
||||
throw new Forbidden();
|
||||
}
|
||||
|
||||
public function actionMassUpdate($params, $data)
|
||||
{
|
||||
throw new Forbidden();
|
||||
}
|
||||
|
||||
public function actionCreateLink($params, $data)
|
||||
{
|
||||
throw new Forbidden();
|
||||
}
|
||||
|
||||
public function actionRemoveLink($params, $data)
|
||||
{
|
||||
throw new Forbidden();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM - Open Source CRM application.
|
||||
* Copyright (C) 2014 Yuri Kuznetsov, Taras Machyshyn, Oleksiy Avramenko
|
||||
* 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
|
||||
@@ -18,11 +18,70 @@
|
||||
*
|
||||
* 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 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 (is_null($data['password'])) {
|
||||
if ($data['type'] == 'preferences') {
|
||||
if (!$this->getUser()->isAdmin() && $data['id'] != $this->getUser()->id) {
|
||||
throw new Forbidden();
|
||||
}
|
||||
$preferences = $this->getEntityManager()->getEntity('Preferences', $data['id']);
|
||||
if (!$preferences) {
|
||||
throw new Error();
|
||||
}
|
||||
|
||||
$data['password'] = $this->getContainer()->get('crypt')->decrypt($preferences->get('smtpPassword'));
|
||||
} else {
|
||||
if (!$this->getUser()->isAdmin()) {
|
||||
throw new Forbidden();
|
||||
}
|
||||
$data['password'] = $this->getConfig()->get('smtpPassword');
|
||||
}
|
||||
}
|
||||
|
||||
return $this->getRecordService()->sendTestEmail($data);
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
70
application/Espo/Controllers/EmailAccount.php
Normal file
70
application/Espo/Controllers/EmailAccount.php
Normal file
@@ -0,0 +1,70 @@
|
||||
<?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\Forbidden;
|
||||
|
||||
class EmailAccount extends \Espo\Core\Controllers\Record
|
||||
{
|
||||
public function actionGetFolders($params, $data, $request)
|
||||
{
|
||||
return $this->getRecordService()->getFolders(array(
|
||||
'host' => $request->get('host'),
|
||||
'port' => $request->get('port'),
|
||||
'ssl' => $request->get('ssl') === 'true',
|
||||
'username' => $request->get('username'),
|
||||
'password' => $request->get('password'),
|
||||
'id' => $request->get('id')
|
||||
));
|
||||
}
|
||||
|
||||
protected function checkControllerAccess()
|
||||
{
|
||||
if (!$this->getAcl()->check('EmailAccountScope')) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM - Open Source CRM application.
|
||||
* Copyright (C) 2014 Yuri Kuznetsov, Taras Machyshyn, Oleksiy Avramenko
|
||||
* 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
|
||||
@@ -24,5 +24,14 @@ namespace Espo\Controllers;
|
||||
|
||||
class EmailAddress extends \Espo\Core\Controllers\Record
|
||||
{
|
||||
|
||||
public function actionSearchInAddressBook($params, $data, $request)
|
||||
{
|
||||
$q = $request->get('q');
|
||||
$limit = intval($request->get('limit'));
|
||||
if (empty($limit) || $limit > 30) {
|
||||
$limit = 5;
|
||||
}
|
||||
return $this->getRecordService()->searchInAddressBook($q, $limit);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM - Open Source CRM application.
|
||||
* Copyright (C) 2014 Yuri Kuznetsov, Taras Machyshyn, Oleksiy Avramenko
|
||||
* 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
|
||||
@@ -26,20 +26,20 @@ use \Espo\Core\Exceptions\Error;
|
||||
|
||||
class EmailTemplate extends \Espo\Core\Controllers\Record
|
||||
{
|
||||
public function actionParse($params, $data, $request)
|
||||
{
|
||||
$id = $request->get('id');
|
||||
$emailAddress = $request->get('emailAddress');
|
||||
if (empty($id)) {
|
||||
throw new Error();
|
||||
}
|
||||
|
||||
return $this->getRecordService()->parse($id, array(
|
||||
'emailAddress' => $request->get('emailAddress'),
|
||||
'parentType' => $request->get('parentType'),
|
||||
'parentId' => $request->get('parentId'),
|
||||
), true);
|
||||
}
|
||||
public function actionParse($params, $data, $request)
|
||||
{
|
||||
$id = $request->get('id');
|
||||
$emailAddress = $request->get('emailAddress');
|
||||
if (empty($id)) {
|
||||
throw new Error();
|
||||
}
|
||||
|
||||
return $this->getRecordService()->parse($id, array(
|
||||
'emailAddress' => $request->get('emailAddress'),
|
||||
'parentType' => $request->get('parentType'),
|
||||
'parentId' => $request->get('parentId'),
|
||||
), true);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
237
application/Espo/Controllers/EntityManager.php
Normal file
237
application/Espo/Controllers/EntityManager.php
Normal file
@@ -0,0 +1,237 @@
|
||||
<?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'];
|
||||
}
|
||||
if (!empty($data['sortBy'])) {
|
||||
$params['sortBy'] = $data['sortBy'];
|
||||
}
|
||||
if (!empty($data['sortDirection'])) {
|
||||
$params['asc'] = $data['sortDirection'] === 'asc';
|
||||
}
|
||||
|
||||
$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);
|
||||
|
||||
if (!empty($data['sortDirection'])) {
|
||||
$data['asc'] = $data['sortDirection'] === 'asc';
|
||||
}
|
||||
|
||||
$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;
|
||||
}
|
||||
}
|
||||
|
||||
131
application/Espo/Controllers/Extension.php
Normal file
131
application/Espo/Controllers/Extension.php
Normal file
@@ -0,0 +1,131 @@
|
||||
<?php
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM - Open Source CRM application.
|
||||
* Copyright (C) 2014-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\Error;
|
||||
use \Espo\Core\Exceptions\Forbidden;
|
||||
|
||||
class Extension extends \Espo\Core\Controllers\Record
|
||||
{
|
||||
protected function checkControllerAccess()
|
||||
{
|
||||
if (!$this->getUser()->isAdmin()) {
|
||||
throw new Forbidden();
|
||||
}
|
||||
}
|
||||
|
||||
public function actionUpload($params, $data, $request)
|
||||
{
|
||||
if (!$request->isPost()) {
|
||||
throw new Forbidden();
|
||||
}
|
||||
|
||||
$manager = new \Espo\Core\ExtensionManager($this->getContainer());
|
||||
|
||||
$id = $manager->upload($data);
|
||||
$manifest = $manager->getManifest();
|
||||
|
||||
return array(
|
||||
'id' => $id,
|
||||
'version' => $manifest['version'],
|
||||
'name' => $manifest['name'],
|
||||
'description' => $manifest['description'],
|
||||
);
|
||||
}
|
||||
|
||||
public function actionInstall($params, $data, $request)
|
||||
{
|
||||
if (!$request->isPost()) {
|
||||
throw new Forbidden();
|
||||
}
|
||||
|
||||
$manager = new \Espo\Core\ExtensionManager($this->getContainer());
|
||||
|
||||
$manager->install($data);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function actionUninstall($params, $data, $request)
|
||||
{
|
||||
if (!$request->isPost()) {
|
||||
throw new Forbidden();
|
||||
}
|
||||
|
||||
$manager = new \Espo\Core\ExtensionManager($this->getContainer());
|
||||
|
||||
$manager->uninstall($data);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function actionCreate($params, $data)
|
||||
{
|
||||
throw new Forbidden();
|
||||
}
|
||||
|
||||
public function actionUpdate($params, $data)
|
||||
{
|
||||
throw new Forbidden();
|
||||
}
|
||||
|
||||
public function actionPatch($params, $data)
|
||||
{
|
||||
throw new Forbidden();
|
||||
}
|
||||
|
||||
public function actionListLinked($params, $data, $request)
|
||||
{
|
||||
throw new Forbidden();
|
||||
}
|
||||
|
||||
public function actionDelete($params)
|
||||
{
|
||||
$manager = new \Espo\Core\ExtensionManager($this->getContainer());
|
||||
|
||||
$manager->delete($params);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function actionMassUpdate($params, $data, $request)
|
||||
{
|
||||
throw new Forbidden();
|
||||
}
|
||||
|
||||
public function actionMassDelete($params, $data, $request)
|
||||
{
|
||||
throw new Forbidden();
|
||||
}
|
||||
|
||||
public function actionCreateLink($params, $data)
|
||||
{
|
||||
throw new Forbidden();
|
||||
}
|
||||
|
||||
public function actionRemoveLink($params, $data)
|
||||
{
|
||||
throw new Forbidden();
|
||||
}
|
||||
}
|
||||
|
||||
124
application/Espo/Controllers/ExternalAccount.php
Normal file
124
application/Espo/Controllers/ExternalAccount.php
Normal file
@@ -0,0 +1,124 @@
|
||||
<?php
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM - Open Source CRM application.
|
||||
* Copyright (C) 2014-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\Error;
|
||||
use \Espo\Core\Exceptions\Forbidden;
|
||||
|
||||
class ExternalAccount extends \Espo\Core\Controllers\Record
|
||||
{
|
||||
public static $defaultAction = 'list';
|
||||
|
||||
public function actionList($params, $data, $request)
|
||||
{
|
||||
$integrations = $this->getEntityManager()->getRepository('Integration')->find();
|
||||
$arr = array();
|
||||
foreach ($integrations as $entity) {
|
||||
if ($entity->get('enabled') && $this->getMetadata()->get('integrations.' . $entity->id .'.allowUserAccounts')) {
|
||||
$arr[] = array(
|
||||
'id' => $entity->id
|
||||
);
|
||||
}
|
||||
}
|
||||
return array(
|
||||
'list' => $arr
|
||||
);
|
||||
}
|
||||
|
||||
public function actionGetOAuth2Info($params, $data, $request)
|
||||
{
|
||||
$id = $request->get('id');
|
||||
list($integration, $userId) = explode('__', $id);
|
||||
|
||||
|
||||
if ($this->getUser()->id != $userId) {
|
||||
throw new Forbidden();
|
||||
}
|
||||
|
||||
$entity = $this->getEntityManager()->getEntity('Integration', $integration);
|
||||
if ($entity) {
|
||||
return array(
|
||||
'clientId' => $entity->get('clientId'),
|
||||
'redirectUri' => $this->getConfig()->get('siteUrl') . '?entryPoint=oauthCallback',
|
||||
'isConnected' => $this->getRecordService()->ping($integration, $userId)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public function actionRead($params, $data, $request)
|
||||
{
|
||||
list($integration, $userId) = explode('__', $params['id']);
|
||||
|
||||
if ($this->getUser()->id != $userId) {
|
||||
throw new Forbidden();
|
||||
}
|
||||
|
||||
$entity = $this->getEntityManager()->getEntity('ExternalAccount', $params['id']);
|
||||
return $entity->toArray();
|
||||
}
|
||||
|
||||
public function actionUpdate($params, $data)
|
||||
{
|
||||
return $this->actionPatch($params, $data);
|
||||
}
|
||||
|
||||
public function actionPatch($params, $data)
|
||||
{
|
||||
list($integration, $userId) = explode('__', $params['id']);
|
||||
|
||||
|
||||
if ($this->getUser()->id != $userId) {
|
||||
throw new Forbidden();
|
||||
}
|
||||
|
||||
if (isset($data['enabled']) && !$data['enabled']) {
|
||||
$data['data'] = null;
|
||||
}
|
||||
|
||||
$entity = $this->getEntityManager()->getEntity('ExternalAccount', $params['id']);
|
||||
$entity->set($data);
|
||||
$this->getEntityManager()->saveEntity($entity);
|
||||
|
||||
return $entity->toArray();
|
||||
}
|
||||
|
||||
public function actionAuthorizationCode($params, $data, $request)
|
||||
{
|
||||
if (!$request->isPost()) {
|
||||
throw new Error('Bad HTTP method type.');
|
||||
}
|
||||
|
||||
$id = $data['id'];
|
||||
$code = $data['code'];
|
||||
|
||||
list($integration, $userId) = explode('__', $id);
|
||||
|
||||
if ($this->getUser()->id != $userId) {
|
||||
throw new Forbidden();
|
||||
}
|
||||
|
||||
$service = $this->getRecordService();
|
||||
return $service->authorizationCode($integration, $userId, $code);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM - Open Source CRM application.
|
||||
* Copyright (C) 2014 Yuri Kuznetsov, Taras Machyshyn, Oleksiy Avramenko
|
||||
* 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
|
||||
@@ -23,66 +23,70 @@
|
||||
namespace Espo\Controllers;
|
||||
|
||||
use \Espo\Core\Exceptions\Error,
|
||||
\Espo\Core\Exceptions\Forbidden,
|
||||
\Espo\Core\Exceptions\NotFound;
|
||||
\Espo\Core\Exceptions\Forbidden,
|
||||
\Espo\Core\Exceptions\NotFound;
|
||||
|
||||
class FieldManager extends \Espo\Core\Controllers\Base
|
||||
{
|
||||
protected function checkControllerAccess()
|
||||
{
|
||||
if (!$this->getUser()->isAdmin()) {
|
||||
throw new Forbidden();
|
||||
}
|
||||
}
|
||||
protected function checkControllerAccess()
|
||||
{
|
||||
if (!$this->getUser()->isAdmin()) {
|
||||
throw new Forbidden();
|
||||
}
|
||||
}
|
||||
|
||||
public function actionRead($params, $data)
|
||||
{
|
||||
$data = $this->getContainer()->get('fieldManager')->read($params['name'], $params['scope']);
|
||||
public function actionRead($params, $data)
|
||||
{
|
||||
$data = $this->getContainer()->get('fieldManager')->read($params['name'], $params['scope']);
|
||||
|
||||
if (!isset($data)) {
|
||||
throw new NotFound();
|
||||
}
|
||||
if (!isset($data)) {
|
||||
throw new NotFound();
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function actionCreate($params, $data)
|
||||
{
|
||||
if (empty($data['name'])) {
|
||||
throw new Error("Field 'name' cannnot be empty");
|
||||
}
|
||||
public function actionCreate($params, $data)
|
||||
{
|
||||
if (empty($data['name'])) {
|
||||
throw new Error("Field 'name' cannnot be empty");
|
||||
}
|
||||
|
||||
$fieldManager = $this->getContainer()->get('fieldManager');
|
||||
$fieldManager->create($data['name'], $data, $params['scope']);
|
||||
$fieldManager = $this->getContainer()->get('fieldManager');
|
||||
$fieldManager->create($data['name'], $data, $params['scope']);
|
||||
|
||||
try {
|
||||
$this->getContainer()->get('dataManager')->rebuild($params['scope']);
|
||||
} catch (Error $e) {
|
||||
$fieldManager->delete($data['name'], $params['scope']);
|
||||
throw new Error($e->getMessage());
|
||||
}
|
||||
try {
|
||||
$this->getContainer()->get('dataManager')->rebuild($params['scope']);
|
||||
} catch (Error $e) {
|
||||
$fieldManager->delete($data['name'], $params['scope']);
|
||||
throw new Error($e->getMessage());
|
||||
}
|
||||
|
||||
return $fieldManager->read($data['name'], $params['scope']);
|
||||
}
|
||||
return $fieldManager->read($data['name'], $params['scope']);
|
||||
}
|
||||
|
||||
public function actionUpdate($params, $data)
|
||||
{
|
||||
$fieldManager = $this->getContainer()->get('fieldManager');
|
||||
$fieldManager->update($params['name'], $data, $params['scope']);
|
||||
public function actionUpdate($params, $data)
|
||||
{
|
||||
$fieldManager = $this->getContainer()->get('fieldManager');
|
||||
$fieldManager->update($params['name'], $data, $params['scope']);
|
||||
|
||||
$this->getContainer()->get('dataManager')->rebuild($params['scope']);
|
||||
if ($fieldManager->isChanged()) {
|
||||
$this->getContainer()->get('dataManager')->rebuild($params['scope']);
|
||||
} else {
|
||||
$this->getContainer()->get('dataManager')->clearCache();
|
||||
}
|
||||
|
||||
return $fieldManager->read($params['name'], $params['scope']);
|
||||
}
|
||||
return $fieldManager->read($params['name'], $params['scope']);
|
||||
}
|
||||
|
||||
public function actionDelete($params, $data)
|
||||
{
|
||||
$res = $this->getContainer()->get('fieldManager')->delete($params['name'], $params['scope']);
|
||||
public function actionDelete($params, $data)
|
||||
{
|
||||
$res = $this->getContainer()->get('fieldManager')->delete($params['name'], $params['scope']);
|
||||
|
||||
$this->getContainer()->get('dataManager')->rebuildMetadata();
|
||||
$this->getContainer()->get('dataManager')->rebuildMetadata();
|
||||
|
||||
return $res;
|
||||
}
|
||||
return $res;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM - Open Source CRM application.
|
||||
* Copyright (C) 2014 Yuri Kuznetsov, Taras Machyshyn, Oleksiy Avramenko
|
||||
* 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
|
||||
@@ -23,18 +23,18 @@
|
||||
namespace Espo\Controllers;
|
||||
|
||||
use \Espo\Core\Exceptions\Error,
|
||||
\Espo\Core\Exceptions\Forbidden;
|
||||
\Espo\Core\Exceptions\Forbidden;
|
||||
|
||||
class GlobalSearch extends \Espo\Core\Controllers\Base
|
||||
{
|
||||
public function actionSearch($params, $data, $request)
|
||||
{
|
||||
$query = $params['query'];
|
||||
|
||||
$offset = $request->get('offset');
|
||||
$maxSize = $request->get('maxSize');
|
||||
|
||||
return $this->getService('GlobalSearch')->find($query, $offset);
|
||||
}
|
||||
{
|
||||
$query = $params['query'];
|
||||
|
||||
$offset = $request->get('offset');
|
||||
$maxSize = $request->get('maxSize');
|
||||
|
||||
return $this->getService('GlobalSearch')->find($query, $offset, $maxSize);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM - Open Source CRM application.
|
||||
* Copyright (C) 2014 Yuri Kuznetsov, Taras Machyshyn, Oleksiy Avramenko
|
||||
* 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
|
||||
@@ -26,7 +26,7 @@ class I18n extends \Espo\Core\Controllers\Base
|
||||
{
|
||||
|
||||
public function actionRead($params, $data)
|
||||
{
|
||||
return $this->getContainer()->get('language')->getAll();
|
||||
}
|
||||
{
|
||||
return $this->getContainer()->get('language')->getAll();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM - Open Source CRM application.
|
||||
* Copyright (C) 2014 Yuri Kuznetsov, Taras Machyshyn, Oleksiy Avramenko
|
||||
* 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
|
||||
@@ -18,69 +18,114 @@
|
||||
*
|
||||
* 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\Base
|
||||
{
|
||||
|
||||
protected function getFileManager()
|
||||
{
|
||||
return $this->getContainer()->get('fileManager');
|
||||
}
|
||||
|
||||
protected function getEntityManager()
|
||||
{
|
||||
return $this->getContainer()->get('entityManager');
|
||||
}
|
||||
|
||||
public function actionUploadFile($params, $data)
|
||||
{
|
||||
$contents = $data;
|
||||
|
||||
$attachment = $this->getEntityManager()->getEntity('Attachment');
|
||||
$attachment->set('type', 'text/csv');
|
||||
$this->getEntityManager()->saveEntity($attachment);
|
||||
|
||||
$this->getFileManager()->putContents('data/upload/' . $attachment->id, $contents);
|
||||
|
||||
return array(
|
||||
'attachmentId' => $attachment->id
|
||||
);
|
||||
}
|
||||
|
||||
public function actionRevert($params, $data)
|
||||
{
|
||||
return $this->getService('Import')->revert($data['entityType'], $data['idsToRemove']);
|
||||
}
|
||||
|
||||
public function actionCreate($params, $data)
|
||||
{
|
||||
$importParams = array(
|
||||
'headerRow' => $data['headerRow'],
|
||||
'fieldDelimiter' => $data['fieldDelimiter'],
|
||||
'textQualifier' => $data['textQualifier'],
|
||||
'dateFormat' => $data['dateFormat'],
|
||||
'timeFormat' => $data['timeFormat'],
|
||||
'personNameFormat' => $data['personNameFormat'],
|
||||
'decimalMark' => $data['decimalMark'],
|
||||
'currency' => $data['currency'],
|
||||
'defaultValues' => $data['defaultValues'],
|
||||
'action' => $data['action'],
|
||||
);
|
||||
|
||||
$attachmentId = $data['attachmentId'];
|
||||
|
||||
if (!$this->getAcl()->check($data['entityType'], 'edit')) {
|
||||
throw new Forbidden();
|
||||
class Import extends \Espo\Core\Controllers\Record
|
||||
{
|
||||
protected function checkControllerAccess()
|
||||
{
|
||||
if (!$this->getUser()->isAdmin()) {
|
||||
throw new Forbidden();
|
||||
}
|
||||
|
||||
return $this->getService('Import')->import($data['entityType'], $data['fields'], $attachmentId, $importParams);
|
||||
}
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
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('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)
|
||||
{
|
||||
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'],
|
||||
'textQualifier' => $data['textQualifier'],
|
||||
'dateFormat' => $data['dateFormat'],
|
||||
'timeFormat' => $data['timeFormat'],
|
||||
'personNameFormat' => $data['personNameFormat'],
|
||||
'decimalMark' => $data['decimalMark'],
|
||||
'currency' => $data['currency'],
|
||||
'defaultValues' => $data['defaultValues'],
|
||||
'action' => $data['action'],
|
||||
);
|
||||
|
||||
$attachmentId = $data['attachmentId'];
|
||||
|
||||
if (!$this->getAcl()->check($data['entityType'], 'edit')) {
|
||||
throw new Forbidden();
|
||||
}
|
||||
|
||||
return $this->getService('Import')->import($data['entityType'], $data['fields'], $attachmentId, $importParams);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
63
application/Espo/Controllers/InboundEmail.php
Normal file
63
application/Espo/Controllers/InboundEmail.php
Normal file
@@ -0,0 +1,63 @@
|
||||
<?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;
|
||||
|
||||
class InboundEmail extends \Espo\Core\Controllers\Record
|
||||
{
|
||||
protected function checkControllerAccess()
|
||||
{
|
||||
if (!$this->getUser()->isAdmin()) {
|
||||
throw new Forbidden();
|
||||
}
|
||||
}
|
||||
|
||||
public function actionGetFolders($params, $data, $request)
|
||||
{
|
||||
return $this->getRecordService()->getFolders(array(
|
||||
'host' => $request->get('host'),
|
||||
'port' => $request->get('port'),
|
||||
'ssl' => $request->get('ssl') === 'true',
|
||||
'username' => $request->get('username'),
|
||||
'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);
|
||||
}
|
||||
|
||||
}
|
||||
61
application/Espo/Controllers/Integration.php
Normal file
61
application/Espo/Controllers/Integration.php
Normal file
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM - Open Source CRM application.
|
||||
* Copyright (C) 2014-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\Error;
|
||||
|
||||
class Integration extends \Espo\Core\Controllers\Record
|
||||
{
|
||||
protected function checkControllerAccess()
|
||||
{
|
||||
if (!$this->getUser()->isAdmin()) {
|
||||
throw new Forbidden();
|
||||
}
|
||||
}
|
||||
|
||||
public function actionIndex($params, $data, $request)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public function actionRead($params, $data, $request)
|
||||
{
|
||||
$entity = $this->getEntityManager()->getEntity('Integration', $params['id']);
|
||||
return $entity->toArray();
|
||||
}
|
||||
|
||||
public function actionUpdate($params, $data)
|
||||
{
|
||||
return $this->actionPatch($params, $data);
|
||||
}
|
||||
|
||||
public function actionPatch($params, $data)
|
||||
{
|
||||
$entity = $this->getEntityManager()->getEntity('Integration', $params['id']);
|
||||
$entity->set($data);
|
||||
$this->getEntityManager()->saveEntity($entity);
|
||||
|
||||
return $entity->toArray();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM - Open Source CRM application.
|
||||
* Copyright (C) 2014 Yuri Kuznetsov, Taras Machyshyn, Oleksiy Avramenko
|
||||
* 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
|
||||
@@ -25,33 +25,40 @@ namespace Espo\Controllers;
|
||||
use Espo\Core\Utils as Utils;
|
||||
use \Espo\Core\Exceptions\NotFound;
|
||||
use \Espo\Core\Exceptions\Error;
|
||||
use \Espo\Core\Exceptions\Forbidden;
|
||||
|
||||
class Layout extends \Espo\Core\Controllers\Base
|
||||
{
|
||||
public function actionRead($params, $data)
|
||||
{
|
||||
$data = $this->getContainer()->get('layout')->get($params['scope'], $params['name']);
|
||||
if (empty($data)) {
|
||||
throw new NotFound("Layout " . $params['scope'] . ":" . $params['name'] . ' is not found');
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
{
|
||||
$data = $this->getContainer()->get('layout')->get($params['scope'], $params['name']);
|
||||
if (empty($data)) {
|
||||
throw new NotFound("Layout " . $params['scope'] . ":" . $params['name'] . ' is not found.');
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function actionUpdate($params, $data)
|
||||
{
|
||||
$result = $this->getContainer()->get('layout')->set($data, $params['scope'], $params['name']);
|
||||
public function actionUpdate($params, $data)
|
||||
{
|
||||
if (!$this->getUser()->isAdmin()) {
|
||||
throw new Forbidden();
|
||||
}
|
||||
|
||||
if ($result === false) {
|
||||
throw new Error("Error while saving layout");
|
||||
}
|
||||
$layoutManager = $this->getContainer()->get('layout');
|
||||
$layoutManager->set($data, $params['scope'], $params['name']);
|
||||
$result = $layoutManager->save();
|
||||
|
||||
$this->getContainer()->get('dataManager')->updateCacheTimestamp();
|
||||
if ($result === false) {
|
||||
throw new Error("Error while saving layout.");
|
||||
}
|
||||
|
||||
return $this->getContainer()->get('layout')->get($params['scope'], $params['name']);
|
||||
}
|
||||
$this->getContainer()->get('dataManager')->updateCacheTimestamp();
|
||||
|
||||
public function actionPatch($params, $data)
|
||||
{
|
||||
return $layoutManager->get($params['scope'], $params['name']);
|
||||
}
|
||||
|
||||
public function actionPatch($params, $data)
|
||||
{
|
||||
return $this->actionUpdate($params, $data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM - Open Source CRM application.
|
||||
* Copyright (C) 2014 Yuri Kuznetsov, Taras Machyshyn, Oleksiy Avramenko
|
||||
* 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
|
||||
@@ -26,7 +26,7 @@ class Metadata extends \Espo\Core\Controllers\Base
|
||||
{
|
||||
|
||||
public function actionRead($params, $data)
|
||||
{
|
||||
return $this->getMetadata()->getAll(true);
|
||||
}
|
||||
{
|
||||
return $this->getMetadata()->getAll(true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM - Open Source CRM application.
|
||||
* Copyright (C) 2014 Yuri Kuznetsov, Taras Machyshyn, Oleksiy Avramenko
|
||||
* 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
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM - Open Source CRM application.
|
||||
* Copyright (C) 2014 Yuri Kuznetsov, Taras Machyshyn, Oleksiy Avramenko
|
||||
* 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
|
||||
@@ -26,35 +26,41 @@ use \Espo\Core\Exceptions\Error;
|
||||
|
||||
class Notification extends \Espo\Core\Controllers\Base
|
||||
{
|
||||
public static $defaultAction = 'list';
|
||||
public static $defaultAction = 'list';
|
||||
|
||||
public function actionList($params, $data, $request)
|
||||
{
|
||||
$scope = $params['scope'];
|
||||
$id = $params['id'];
|
||||
|
||||
$userId = $this->getUser()->id;
|
||||
|
||||
$offset = intval($request->get('offset'));
|
||||
$maxSize = intval($request->get('maxSize'));
|
||||
|
||||
$params = array(
|
||||
'offset' => $offset,
|
||||
'maxSize' => $maxSize,
|
||||
);
|
||||
|
||||
$result = $this->getService('Notification')->getList($userId, $params);
|
||||
|
||||
return array(
|
||||
'total' => $result['total'],
|
||||
'list' => $result['collection']->toArray()
|
||||
);
|
||||
}
|
||||
|
||||
public function actionNotReadCount()
|
||||
{
|
||||
$userId = $this->getUser()->id;
|
||||
return $this->getService('Notification')->getNotReadCount($userId);
|
||||
}
|
||||
public function actionList($params, $data, $request)
|
||||
{
|
||||
$scope = $params['scope'];
|
||||
$id = $params['id'];
|
||||
|
||||
$userId = $this->getUser()->id;
|
||||
|
||||
$offset = intval($request->get('offset'));
|
||||
$maxSize = intval($request->get('maxSize'));
|
||||
|
||||
$params = array(
|
||||
'offset' => $offset,
|
||||
'maxSize' => $maxSize,
|
||||
);
|
||||
|
||||
$result = $this->getService('Notification')->getList($userId, $params);
|
||||
|
||||
return array(
|
||||
'total' => $result['total'],
|
||||
'list' => $result['collection']->toArray()
|
||||
);
|
||||
}
|
||||
|
||||
public function actionNotReadCount()
|
||||
{
|
||||
$userId = $this->getUser()->id;
|
||||
return $this->getService('Notification')->getNotReadCount($userId);
|
||||
}
|
||||
|
||||
public function actionMarkAllRead($params, $data, $request)
|
||||
{
|
||||
$userId = $this->getUser()->id;
|
||||
return $this->getService('Notification')->markAllRead($userId);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM - Open Source CRM application.
|
||||
* Copyright (C) 2014 Yuri Kuznetsov, Taras Machyshyn, Oleksiy Avramenko
|
||||
* 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
|
||||
@@ -18,75 +18,102 @@
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with EspoCRM. If not, see http://www.gnu.org/licenses/.
|
||||
************************************************************************/
|
||||
************************************************************************/
|
||||
|
||||
namespace Espo\Controllers;
|
||||
|
||||
use \Espo\Core\Exceptions\Error;
|
||||
use \Espo\Core\Exceptions\Forbidden;
|
||||
use \Espo\Core\Exceptions\BadRequest;
|
||||
use \Espo\Core\Exceptions\NotFound;
|
||||
|
||||
class Preferences extends \Espo\Core\Controllers\Base
|
||||
{
|
||||
protected function getPreferences()
|
||||
{
|
||||
return $this->getContainer()->get('preferences');
|
||||
}
|
||||
|
||||
protected function getEntityManager()
|
||||
{
|
||||
return $this->getContainer()->get('entityManager');
|
||||
}
|
||||
|
||||
protected function handleUserAccess($userId)
|
||||
{
|
||||
if (!$this->getUser()->isAdmin()) {
|
||||
if ($this->getUser()->id != $userId) {
|
||||
throw new Forbidden();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function actionPatch($params, $data)
|
||||
{
|
||||
return $this->actionUpdate($params, $data);
|
||||
}
|
||||
{
|
||||
protected function getPreferences()
|
||||
{
|
||||
return $this->getContainer()->get('preferences');
|
||||
}
|
||||
|
||||
public function actionUpdate($params, $data)
|
||||
{
|
||||
$userId = $params['id'];
|
||||
$this->handleUserAccess($userId);
|
||||
|
||||
$user = $this->getEntityManager()->getEntity('User', $userId);
|
||||
protected function getEntityManager()
|
||||
{
|
||||
return $this->getContainer()->get('entityManager');
|
||||
}
|
||||
|
||||
$entity = $this->getEntityManager()->getEntity('Preferences', $userId);
|
||||
|
||||
if ($entity) {
|
||||
$entity->set($data);
|
||||
$this->getEntityManager()->saveEntity($entity);
|
||||
|
||||
$entity->set('smtpEmailAddress', $user->get('emailAddress'));
|
||||
$entity->set('name', $user->get('name'));
|
||||
|
||||
return $entity->toArray();
|
||||
}
|
||||
throw new Error();
|
||||
}
|
||||
protected function getCrypt()
|
||||
{
|
||||
return $this->getContainer()->get('crypt');
|
||||
}
|
||||
|
||||
protected function handleUserAccess($userId)
|
||||
{
|
||||
if (!$this->getUser()->isAdmin()) {
|
||||
if ($this->getUser()->id != $userId) {
|
||||
throw new Forbidden();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function actionDelete($params, $data)
|
||||
{
|
||||
$userId = $params['id'];
|
||||
if (empty($userId)) {
|
||||
throw new BadRequest();
|
||||
}
|
||||
$this->handleUserAccess($userId);
|
||||
|
||||
return $this->getEntityManager()->getRepository('Preferences')->resetToDefaults($userId);
|
||||
}
|
||||
|
||||
public function actionPatch($params, $data)
|
||||
{
|
||||
return $this->actionUpdate($params, $data);
|
||||
}
|
||||
|
||||
public function actionUpdate($params, $data)
|
||||
{
|
||||
$userId = $params['id'];
|
||||
$this->handleUserAccess($userId);
|
||||
|
||||
if (array_key_exists('smtpPassword', $data)) {
|
||||
$data['smtpPassword'] = $this->getCrypt()->encrypt($data['smtpPassword']);
|
||||
}
|
||||
|
||||
$user = $this->getEntityManager()->getEntity('User', $userId);
|
||||
|
||||
$entity = $this->getEntityManager()->getEntity('Preferences', $userId);
|
||||
|
||||
if ($entity && $user) {
|
||||
$entity->set($data);
|
||||
$this->getEntityManager()->saveEntity($entity);
|
||||
|
||||
$entity->set('smtpEmailAddress', $user->get('emailAddress'));
|
||||
$entity->set('name', $user->get('name'));
|
||||
|
||||
$entity->clear('smtpPassword');
|
||||
|
||||
return $entity->toArray();
|
||||
}
|
||||
throw new Error();
|
||||
}
|
||||
|
||||
public function actionRead($params)
|
||||
{
|
||||
$userId = $params['id'];
|
||||
$this->handleUserAccess($userId);
|
||||
{
|
||||
$userId = $params['id'];
|
||||
$this->handleUserAccess($userId);
|
||||
|
||||
$entity = $this->getEntityManager()->getEntity('Preferences', $userId);
|
||||
$user = $this->getEntityManager()->getEntity('User', $userId);
|
||||
|
||||
$entity->set('smtpEmailAddress', $user->get('emailAddress'));
|
||||
$entity->set('name', $user->get('name'));
|
||||
if ($entity) {
|
||||
return $entity->toArray();
|
||||
}
|
||||
throw new NotFound();
|
||||
}
|
||||
$entity = $this->getEntityManager()->getEntity('Preferences', $userId);
|
||||
$user = $this->getEntityManager()->getEntity('User', $userId);
|
||||
|
||||
if (!$entity || !$user) {
|
||||
throw new NotFound();
|
||||
}
|
||||
|
||||
$entity->set('smtpEmailAddress', $user->get('emailAddress'));
|
||||
$entity->set('name', $user->get('name'));
|
||||
|
||||
$entity->clear('smtpPassword');
|
||||
|
||||
return $entity->toArray();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM - Open Source CRM application.
|
||||
* Copyright (C) 2014 Yuri Kuznetsov, Taras Machyshyn, Oleksiy Avramenko
|
||||
* 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
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM - Open Source CRM application.
|
||||
* Copyright (C) 2014 Yuri Kuznetsov, Taras Machyshyn, Oleksiy Avramenko
|
||||
* 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
|
||||
@@ -24,11 +24,11 @@ namespace Espo\Controllers;
|
||||
|
||||
class ScheduledJob extends \Espo\Core\Controllers\Record
|
||||
{
|
||||
protected function checkControllerAccess()
|
||||
{
|
||||
if (!$this->getUser()->isAdmin()) {
|
||||
throw new Forbidden();
|
||||
}
|
||||
}
|
||||
protected function checkControllerAccess()
|
||||
{
|
||||
if (!$this->getUser()->isAdmin()) {
|
||||
throw new Forbidden();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM - Open Source CRM application.
|
||||
* Copyright (C) 2014 Yuri Kuznetsov, Taras Machyshyn, Oleksiy Avramenko
|
||||
* 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
|
||||
@@ -24,11 +24,11 @@ namespace Espo\Controllers;
|
||||
|
||||
class ScheduledJobLogRecord extends \Espo\Core\Controllers\Record
|
||||
{
|
||||
protected function checkControllerAccess()
|
||||
{
|
||||
if (!$this->getUser()->isAdmin()) {
|
||||
throw new Forbidden();
|
||||
}
|
||||
}
|
||||
protected function checkControllerAccess()
|
||||
{
|
||||
if (!$this->getUser()->isAdmin()) {
|
||||
throw new Forbidden();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM - Open Source CRM application.
|
||||
* Copyright (C) 2014 Yuri Kuznetsov, Taras Machyshyn, Oleksiy Avramenko
|
||||
* 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
|
||||
@@ -27,42 +27,52 @@ use \Espo\Core\Exceptions\Forbidden;
|
||||
|
||||
class Settings extends \Espo\Core\Controllers\Base
|
||||
{
|
||||
protected function getConfigData()
|
||||
{
|
||||
$data = $this->getConfig()->getData($this->getUser()->isAdmin());
|
||||
protected function getConfigData()
|
||||
{
|
||||
$data = $this->getConfig()->getData($this->getUser()->isAdmin());
|
||||
|
||||
$fieldDefs = $this->getMetadata()->get('entityDefs.Settings.fields');
|
||||
$fieldDefs = $this->getMetadata()->get('entityDefs.Settings.fields');
|
||||
|
||||
foreach ($fieldDefs as $field => $d) {
|
||||
if ($d['type'] == 'password') {
|
||||
unset($data[$field]);
|
||||
}
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
foreach ($fieldDefs as $field => $d) {
|
||||
if ($d['type'] == 'password') {
|
||||
unset($data[$field]);
|
||||
}
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function actionRead($params, $data)
|
||||
{
|
||||
return $this->getConfigData();
|
||||
}
|
||||
public function actionRead($params, $data)
|
||||
{
|
||||
return $this->getConfigData();
|
||||
}
|
||||
|
||||
public function actionUpdate($params, $data)
|
||||
{
|
||||
return $this->actionPatch($params, $data);
|
||||
}
|
||||
public function actionUpdate($params, $data)
|
||||
{
|
||||
return $this->actionPatch($params, $data);
|
||||
}
|
||||
|
||||
public function actionPatch($params, $data)
|
||||
{
|
||||
if (!$this->getUser()->isAdmin()) {
|
||||
throw new Forbidden();
|
||||
}
|
||||
public function actionPatch($params, $data)
|
||||
{
|
||||
if (!$this->getUser()->isAdmin()) {
|
||||
throw new Forbidden();
|
||||
}
|
||||
|
||||
$this->getConfig()->setData($data, $this->getUser()->isAdmin());
|
||||
$result = $this->getConfig()->save();
|
||||
if ($result === false) {
|
||||
throw new Error('Cannot save settings');
|
||||
}
|
||||
if (isset($data['useCache']) && $data['useCache'] != $this->getConfig()->get('useCache')) {
|
||||
$this->getContainer()->get('dataManager')->clearCache();
|
||||
}
|
||||
|
||||
return $this->getConfigData();
|
||||
}
|
||||
$this->getConfig()->setData($data, $this->getUser()->isAdmin());
|
||||
$result = $this->getConfig()->save();
|
||||
if ($result === false) {
|
||||
throw new Error('Cannot save settings');
|
||||
}
|
||||
|
||||
/** Rebuild for Currency Settings */
|
||||
if (isset($data['baseCurrency']) || isset($data['currencyRates'])) {
|
||||
$this->getContainer()->get('dataManager')->rebuildDatabase(array());
|
||||
}
|
||||
/** END Rebuild for Currency Settings */
|
||||
|
||||
return $this->getConfigData();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM - Open Source CRM application.
|
||||
* Copyright (C) 2014 Yuri Kuznetsov, Taras Machyshyn, Oleksiy Avramenko
|
||||
* 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
|
||||
@@ -18,7 +18,7 @@
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with EspoCRM. If not, see http://www.gnu.org/licenses/.
|
||||
************************************************************************/
|
||||
************************************************************************/
|
||||
|
||||
namespace Espo\Controllers;
|
||||
|
||||
@@ -26,38 +26,38 @@ use \Espo\Core\Exceptions\Error;
|
||||
|
||||
class Stream extends \Espo\Core\Controllers\Base
|
||||
{
|
||||
const MAX_SIZE_LIMIT = 400;
|
||||
|
||||
public static $defaultAction = 'list';
|
||||
const MAX_SIZE_LIMIT = 400;
|
||||
|
||||
public static $defaultAction = 'list';
|
||||
|
||||
public function actionList($params, $data, $request)
|
||||
{
|
||||
$scope = $params['scope'];
|
||||
$id = $params['id'];
|
||||
|
||||
$offset = intval($request->get('offset'));
|
||||
$maxSize = intval($request->get('maxSize'));
|
||||
$after = $request->get('after');
|
||||
|
||||
$service = $this->getService('Stream');
|
||||
|
||||
if (empty($maxSize)) {
|
||||
$maxSize = self::MAX_SIZE_LIMIT;
|
||||
}
|
||||
if (!empty($maxSize) && $maxSize > self::MAX_SIZE_LIMIT) {
|
||||
throw new Forbidden();
|
||||
}
|
||||
|
||||
$result = $service->find($scope, $id, array(
|
||||
'offset' => $offset,
|
||||
'maxSize' => $maxSize,
|
||||
'after' => $after,
|
||||
));
|
||||
|
||||
return array(
|
||||
'total' => $result['total'],
|
||||
'list' => $result['collection']->toArray()
|
||||
);
|
||||
}
|
||||
{
|
||||
$scope = $params['scope'];
|
||||
$id = isset($params['id']) ? $params['id'] : null;
|
||||
|
||||
$offset = intval($request->get('offset'));
|
||||
$maxSize = intval($request->get('maxSize'));
|
||||
$after = $request->get('after');
|
||||
|
||||
$service = $this->getService('Stream');
|
||||
|
||||
if (empty($maxSize)) {
|
||||
$maxSize = self::MAX_SIZE_LIMIT;
|
||||
}
|
||||
if (!empty($maxSize) && $maxSize > self::MAX_SIZE_LIMIT) {
|
||||
throw new Forbidden();
|
||||
}
|
||||
|
||||
$result = $service->find($scope, $id, array(
|
||||
'offset' => $offset,
|
||||
'maxSize' => $maxSize,
|
||||
'after' => $after,
|
||||
));
|
||||
|
||||
return array(
|
||||
'total' => $result['total'],
|
||||
'list' => $result['collection']->toArray()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM - Open Source CRM application.
|
||||
* Copyright (C) 2014 Yuri Kuznetsov, Taras Machyshyn, Oleksiy Avramenko
|
||||
* 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
|
||||
@@ -24,6 +24,6 @@ namespace Espo\Controllers;
|
||||
|
||||
class Team extends \Espo\Core\Controllers\Record
|
||||
{
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM - Open Source CRM application.
|
||||
* Copyright (C) 2014 Yuri Kuznetsov, Taras Machyshyn, Oleksiy Avramenko
|
||||
* 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
|
||||
@@ -18,40 +18,84 @@
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with EspoCRM. If not, see http://www.gnu.org/licenses/.
|
||||
************************************************************************/
|
||||
************************************************************************/
|
||||
|
||||
namespace Espo\Controllers;
|
||||
|
||||
use \Espo\Core\Exceptions\Error;
|
||||
use \Espo\Core\Exceptions\NotFound;
|
||||
use \Espo\Core\Exceptions\Forbidden;
|
||||
use \Espo\Core\Exceptions\BadRequest;
|
||||
|
||||
class User extends \Espo\Core\Controllers\Record
|
||||
{
|
||||
public function actionAcl($params, $data, $request)
|
||||
{
|
||||
$userId = $request->get('id');
|
||||
if (empty($userId)) {
|
||||
throw new Error();
|
||||
}
|
||||
|
||||
if (!$this->getUser()->isAdmin() && $this->getUser()->id != $userId) {
|
||||
throw new Forbidden();
|
||||
}
|
||||
|
||||
$user = $this->getEntityManager()->getEntity('User', $userId);
|
||||
if (empty($user)) {
|
||||
throw new NotFound();
|
||||
}
|
||||
|
||||
$acl = new \Espo\Core\Acl($user);
|
||||
|
||||
return $acl->toArray();
|
||||
}
|
||||
|
||||
public function actionChangeOwnPassword($params, $data)
|
||||
{
|
||||
return $this->getService('User')->changePassword($this->getUser()->id, $data['password']);
|
||||
}
|
||||
{
|
||||
public function actionAcl($params, $data, $request)
|
||||
{
|
||||
$userId = $request->get('id');
|
||||
if (empty($userId)) {
|
||||
throw new Error();
|
||||
}
|
||||
|
||||
if (!$this->getUser()->isAdmin() && $this->getUser()->id != $userId) {
|
||||
throw new Forbidden();
|
||||
}
|
||||
|
||||
$user = $this->getEntityManager()->getEntity('User', $userId);
|
||||
if (empty($user)) {
|
||||
throw new NotFound();
|
||||
}
|
||||
|
||||
return $this->getAclManager()->getMap($user);
|
||||
}
|
||||
|
||||
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 BadRequest();
|
||||
}
|
||||
if (empty($data['requestId']) || empty($data['password'])) {
|
||||
throw new BadRequest();
|
||||
}
|
||||
|
||||
$p = $this->getEntityManager()->getRepository('PasswordChangeRequest')->where(array(
|
||||
'requestId' => $data['requestId']
|
||||
))->findOne();
|
||||
|
||||
if (!$p) {
|
||||
throw new Forbidden();
|
||||
}
|
||||
$userId = $p->get('userId');
|
||||
if (!$userId) {
|
||||
throw new Error();
|
||||
}
|
||||
|
||||
$this->getEntityManager()->removeEntity($p);
|
||||
|
||||
return $this->getService('User')->changePassword($userId, $data['password']);
|
||||
}
|
||||
|
||||
public function actionPasswordChangeRequest($params, $data, $request)
|
||||
{
|
||||
if (!$request->isPost()) {
|
||||
throw new Forbidden();
|
||||
}
|
||||
|
||||
if (empty($data['userName']) || empty($data['emailAddress'])) {
|
||||
throw new BadRequest();
|
||||
}
|
||||
|
||||
$userName = $data['userName'];
|
||||
$emailAddress = $data['emailAddress'];
|
||||
|
||||
return $this->getService('User')->passwordChangeRequest($userName, $emailAddress);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM - Open Source CRM application.
|
||||
* Copyright (C) 2014 Yuri Kuznetsov, Taras Machyshyn, Oleksiy Avramenko
|
||||
* 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
|
||||
@@ -18,248 +18,65 @@
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with EspoCRM. If not, see http://www.gnu.org/licenses/.
|
||||
************************************************************************/
|
||||
************************************************************************/
|
||||
|
||||
namespace Espo\Core;
|
||||
|
||||
use \Espo\Core\Exceptions\Error;
|
||||
|
||||
class Acl
|
||||
{
|
||||
private $data = array();
|
||||
private $user;
|
||||
|
||||
private $cacheFile;
|
||||
private $aclManager;
|
||||
|
||||
private $actionList = array('read', 'edit', 'delete');
|
||||
public function __construct(AclManager $aclManager, \Espo\Entities\User $user)
|
||||
{
|
||||
$this->aclManager = $aclManager;
|
||||
$this->user = $user;
|
||||
}
|
||||
|
||||
private $levelList = array('all', 'team', 'own', 'no');
|
||||
|
||||
private $fileManager;
|
||||
protected function getAclManager()
|
||||
{
|
||||
return $this->aclManager;
|
||||
}
|
||||
|
||||
public function __construct(\Espo\Entities\User $user, $config = null, $fileManager = null)
|
||||
{
|
||||
$this->user = $user;
|
||||
|
||||
if (!$this->user->isFetched()) {
|
||||
throw new Error();
|
||||
}
|
||||
|
||||
$this->user->loadLinkMultipleField('teams');
|
||||
|
||||
if ($fileManager) {
|
||||
$this->fileManager = $fileManager;
|
||||
}
|
||||
|
||||
$this->cacheFile = 'data/cache/application/acl/' . $user->id . '.php';
|
||||
|
||||
if ($config && $config->get('useCache') && file_exists($this->cacheFile)) {
|
||||
$cached = include $this->cacheFile;
|
||||
$this->data = $cached;
|
||||
$this->initSolid();
|
||||
} else {
|
||||
$this->load();
|
||||
$this->initSolid();
|
||||
if ($config && $fileManager && $config->get('useCache')) {
|
||||
$this->buildCache();
|
||||
}
|
||||
}
|
||||
protected function getUser()
|
||||
{
|
||||
return $this->user;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function checkScope($scope, $action = null, $isOwner = null, $inTeam = null)
|
||||
{
|
||||
if (array_key_exists($scope, $this->data)) {
|
||||
if ($this->data[$scope] === false) {
|
||||
return false;
|
||||
}
|
||||
if ($this->data[$scope] === true) {
|
||||
return true;
|
||||
}
|
||||
if (!is_null($action)) {
|
||||
if (array_key_exists($action, $this->data[$scope])) {
|
||||
$value = $this->data[$scope][$action];
|
||||
|
||||
if ($value === 'all' || $value === true) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!$value || $value === 'no') {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (is_null($isOwner)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ($isOwner) {
|
||||
if ($value === 'own' || $value === 'team') {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if ($inTeam) {
|
||||
if ($value === 'team') {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public function toArray()
|
||||
{
|
||||
return $this->data;
|
||||
}
|
||||
public function getMap()
|
||||
{
|
||||
return $this->getAclManager()->getMap($this->getUser());
|
||||
}
|
||||
|
||||
public function check($subject, $action = null, $isOwner = null, $inTeam = null)
|
||||
{
|
||||
if ($this->user->isAdmin()) {
|
||||
return true;
|
||||
}
|
||||
if (is_string($subject)) {
|
||||
return $this->checkScope($subject, $action, $isOwner, $inTeam);
|
||||
} else {
|
||||
$entity = $subject;
|
||||
$entityName = $entity->getEntityName();
|
||||
return $this->checkScope($entityName, $action, $this->checkIsOwner($entity), $this->checkInTeam($entity));
|
||||
}
|
||||
}
|
||||
|
||||
public function checkReadOnlyTeam($scope)
|
||||
{
|
||||
if (isset($this->data[$scope]) && isset($this->data[$scope]['read'])) {
|
||||
return $this->data[$scope]['read'] === 'team';
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function checkReadOnlyOwn($scope)
|
||||
{
|
||||
if ($this->user->isAdmin()) {
|
||||
return false;
|
||||
}
|
||||
if (isset($this->data[$scope]) && isset($this->data[$scope]['read'])) {
|
||||
return $this->data[$scope]['read'] === 'own';
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function checkIsOwner($entity)
|
||||
{
|
||||
if ($this->user->isAdmin()) {
|
||||
return false;
|
||||
}
|
||||
$userId = $this->user->id;
|
||||
if ($userId === $entity->get('assignedUserId') || $userId === $entity->get('createdById')) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function checkInTeam($entity)
|
||||
{
|
||||
$userTeamIds = $this->user->get('teamsIds');
|
||||
$teamIds = $entity->get('teamsIds');
|
||||
|
||||
foreach ($userTeamIds as $id) {
|
||||
if (in_array($id, $teamIds)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
public function getLevel($scope, $action)
|
||||
{
|
||||
return $this->getAclManager()->getLevel($this->getUser(), $scope, $action);
|
||||
}
|
||||
|
||||
private function load()
|
||||
{
|
||||
$aclTables = array();
|
||||
public function get($permission)
|
||||
{
|
||||
return $this->getAclManager()->get($this->getUser(), $permission);
|
||||
}
|
||||
|
||||
$userRoles = $this->user->get('roles');
|
||||
|
||||
foreach ($userRoles as $role) {
|
||||
$aclTables[] = json_decode($role->get('data'));
|
||||
}
|
||||
public function checkReadOnlyTeam($scope)
|
||||
{
|
||||
return $this->getAclManager()->checkReadOnlyTeam($this->getUser(), $scope);
|
||||
}
|
||||
|
||||
$teams = $this->user->get('teams');
|
||||
foreach ($teams as $team) {
|
||||
$teamRoles = $team->get('roles');
|
||||
foreach ($teamRoles as $role) {
|
||||
$aclTables[] = json_decode($role->get('data'));
|
||||
}
|
||||
}
|
||||
public function checkReadOnlyOwn($scope)
|
||||
{
|
||||
return $this->getAclManager()->checkReadOnlyOwn($this->getUser(), $scope);
|
||||
}
|
||||
|
||||
$this->data = $this->merge($aclTables);
|
||||
}
|
||||
|
||||
private function initSolid()
|
||||
{
|
||||
$this->data['User'] = array(
|
||||
'read' => 'all',
|
||||
'edit' => 'no',
|
||||
'delete' => 'no',
|
||||
);
|
||||
$this->data['Team'] = array(
|
||||
'read' => 'all',
|
||||
'edit' => 'no',
|
||||
'delete' => 'no',
|
||||
);
|
||||
$this->data['Role'] = false;
|
||||
$this->data['Note'] = array(
|
||||
'read' => 'own',
|
||||
'edit' => 'own',
|
||||
'delete' => 'own',
|
||||
);
|
||||
$this->data['EmailAddress'] = array(
|
||||
'read' => 'no',
|
||||
'edit' => 'no',
|
||||
'delete' => 'no',
|
||||
);
|
||||
$this->data['Note'] = array(
|
||||
'read' => 'all',
|
||||
'edit' => 'own',
|
||||
'delete' => 'own',
|
||||
);
|
||||
}
|
||||
public function check($subject, $action = null, $isOwner = null, $inTeam = null)
|
||||
{
|
||||
return $this->getAclManager()->check($this->getUser(), $subject, $action, $isOwner, $inTeam) ;
|
||||
}
|
||||
|
||||
private function merge($tables)
|
||||
{
|
||||
$data = array();
|
||||
foreach ($tables as $table) {
|
||||
foreach ($table as $scope => $row) {
|
||||
if ($row == false) {
|
||||
if (!isset($data[$scope])) {
|
||||
$data[$scope] = false;
|
||||
}
|
||||
} else {
|
||||
if (!isset($data[$scope])) {
|
||||
$data[$scope] = array();
|
||||
}
|
||||
if ($data[$scope] == false) {
|
||||
$data[$scope] = array();
|
||||
}
|
||||
foreach ($row as $action => $level) {
|
||||
if (!isset($data[$scope][$action])) {
|
||||
$data[$scope][$action] = $level;
|
||||
} else {
|
||||
if (array_search($data[$scope][$action], $this->levelList) > array_search($level, $this->levelList)) {
|
||||
$data[$scope][$action] = $level;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
private function buildCache()
|
||||
{
|
||||
$contents = '<' . '?'. 'php return ' . var_export($this->data, true) . ';';
|
||||
$this->fileManager->putContents($this->cacheFile, $contents);
|
||||
}
|
||||
public function checkScope($scope, $action = null, $isOwner = null, $inTeam = null, $entity = null)
|
||||
{
|
||||
return $this->getAclManager()->checkScope($this->getUser(), $subject, $action, $isOwner, $inTeam, $entity) ;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
223
application/Espo/Core/Acl/Base.php
Normal file
223
application/Espo/Core/Acl/Base.php
Normal file
@@ -0,0 +1,223 @@
|
||||
<?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\Acl;
|
||||
|
||||
use \Espo\Core\Interfaces\Injectable;
|
||||
|
||||
use \Espo\Entities\User;
|
||||
use \Espo\ORM\Entity;
|
||||
|
||||
class Base implements Injectable
|
||||
{
|
||||
protected $dependencies = array(
|
||||
'config',
|
||||
'entityManager',
|
||||
'aclManager'
|
||||
);
|
||||
|
||||
protected $injections = array();
|
||||
|
||||
public function inject($name, $object)
|
||||
{
|
||||
$this->injections[$name] = $object;
|
||||
}
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->init();
|
||||
}
|
||||
|
||||
protected function init()
|
||||
{
|
||||
}
|
||||
|
||||
protected function getInjection($name)
|
||||
{
|
||||
return $this->injections[$name];
|
||||
}
|
||||
|
||||
protected function addDependency($name)
|
||||
{
|
||||
$this->dependencies[] = $name;
|
||||
}
|
||||
|
||||
public function getDependencyList()
|
||||
{
|
||||
return $this->dependencies;
|
||||
}
|
||||
|
||||
protected function getConfig()
|
||||
{
|
||||
return $this->getInjection('config');
|
||||
}
|
||||
|
||||
protected function getEntityManager()
|
||||
{
|
||||
return $this->getInjection('entityManager');
|
||||
}
|
||||
|
||||
protected function getAclManager()
|
||||
{
|
||||
return $this->getInjection('aclManager');
|
||||
}
|
||||
|
||||
public function checkReadOnlyTeam(User $user, $scope, $data)
|
||||
{
|
||||
if (empty($data) || !is_array($data) || !isset($data['read'])) {
|
||||
return false;
|
||||
}
|
||||
return $data['read'] === 'team';
|
||||
}
|
||||
|
||||
public function checkReadOnlyOwn(User $user, $scope, $data)
|
||||
{
|
||||
if (empty($data) || !is_array($data) || !isset($data['read'])) {
|
||||
return false;
|
||||
}
|
||||
return $data['read'] === 'own';
|
||||
}
|
||||
|
||||
public function checkEntity(User $user, Entity $entity, $data, $action)
|
||||
{
|
||||
return $this->checkScope($user, $data, $entity->getEntityType(), $action, null, null, $entity);
|
||||
}
|
||||
|
||||
public function checkScope(User $user, $data, $scope, $action = null, $isOwner = null, $inTeam = null, Entity $entity = null)
|
||||
{
|
||||
if (is_null($data)) {
|
||||
return true;
|
||||
}
|
||||
if ($data === false) {
|
||||
return false;
|
||||
}
|
||||
if ($data === true) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!is_null($action)) {
|
||||
if (array_key_exists($action, $data)) {
|
||||
$value = $data[$action];
|
||||
|
||||
if ($value === 'all' || $value === true) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!$value || $value === 'no') {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (is_null($isOwner)) {
|
||||
if ($entity) {
|
||||
$isOwner = $this->checkIsOwner($user, $entity);
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if ($isOwner) {
|
||||
if ($value === 'own' || $value === 'team') {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (is_null($inTeam) && $entity) {
|
||||
$inTeam = $this->checkInTeam($user, $entity);
|
||||
}
|
||||
|
||||
if ($inTeam) {
|
||||
if ($value === 'team') {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public function checkIsOwner(User $user, Entity $entity)
|
||||
{
|
||||
if ($entity->has('assignedUserId')) {
|
||||
if ($user->id === $entity->get('assignedUserId')) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if ($entity->has('createdById')) {
|
||||
if ($user->id === $entity->get('createdById')) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function checkInTeam(User $user, Entity $entity)
|
||||
{
|
||||
$userTeamIds = $user->get('teamsIds');
|
||||
|
||||
if (!$entity->hasRelation('teams') || !$entity->hasField('teamsIds')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!$entity->has('teamsIds')) {
|
||||
$entity->loadLinkMultipleField('teams');
|
||||
}
|
||||
|
||||
$teamIds = $entity->get('teamsIds');
|
||||
|
||||
if (empty($teamIds)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach ($userTeamIds as $id) {
|
||||
if (in_array($id, $teamIds)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function checkEntityDelete(User $user, Entity $entity, $data)
|
||||
{
|
||||
$result = $this->checkEntity($user, $entity, $data, 'delete');
|
||||
if (!$result) {
|
||||
if (is_array($data)) {
|
||||
if ($data['edit'] != 'no') {
|
||||
if ($entity->has('createdById') && $entity->get('createdById') == $user->id) {
|
||||
if (!$entity->has('assignedUserId')) {
|
||||
return true;
|
||||
} else {
|
||||
if (!$entity->get('assignedUserId')) {
|
||||
return true;
|
||||
}
|
||||
if ($entity->get('assignedUserId') == $entity->get('createdById')) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
247
application/Espo/Core/Acl/Table.php
Normal file
247
application/Espo/Core/Acl/Table.php
Normal file
@@ -0,0 +1,247 @@
|
||||
<?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\Acl;
|
||||
|
||||
use \Espo\Core\Exceptions\Error;
|
||||
|
||||
use \Espo\ORM\Entity;
|
||||
|
||||
class Table
|
||||
{
|
||||
private $data = array(
|
||||
'table' => array()
|
||||
);
|
||||
|
||||
private $cacheFile;
|
||||
|
||||
private $actionList = ['read', 'edit', 'delete'];
|
||||
|
||||
private $levelList = ['all', 'team', 'own', 'no'];
|
||||
|
||||
protected $fileManager;
|
||||
|
||||
protected $metadata;
|
||||
|
||||
public function __construct(\Espo\Entities\User $user, $config = null, $fileManager = null, $metadata = null)
|
||||
{
|
||||
$this->user = $user;
|
||||
|
||||
$this->metadata = $metadata;
|
||||
|
||||
if (!$this->user->isFetched()) {
|
||||
throw new Error();
|
||||
}
|
||||
|
||||
$this->user->loadLinkMultipleField('teams');
|
||||
|
||||
if ($fileManager) {
|
||||
$this->fileManager = $fileManager;
|
||||
}
|
||||
|
||||
$this->cacheFile = 'data/cache/application/acl/' . $user->id . '.php';
|
||||
|
||||
if ($config && $config->get('useCache') && file_exists($this->cacheFile)) {
|
||||
$cached = include $this->cacheFile;
|
||||
$this->data = $cached;
|
||||
$this->initSolid();
|
||||
} else {
|
||||
$this->load();
|
||||
$this->initSolid();
|
||||
if ($config && $fileManager && $config->get('useCache')) {
|
||||
$this->buildCache();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function getMap()
|
||||
{
|
||||
return $this->data;
|
||||
}
|
||||
|
||||
public function getScopeData($scope)
|
||||
{
|
||||
if (array_key_exists($scope, $this->data['table'])) {
|
||||
return $this->data['table'][$scope];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public function get($permission)
|
||||
{
|
||||
if ($permission == 'table') {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (array_key_exists($permission, $this->data)) {
|
||||
return $this->data[$permission];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public function getLevel($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;
|
||||
}
|
||||
|
||||
private function load()
|
||||
{
|
||||
$aclTables = [];
|
||||
$assignmentPermissionList = [];
|
||||
$userPermissionList = [];
|
||||
|
||||
$userRoles = $this->user->get('roles');
|
||||
|
||||
foreach ($userRoles as $role) {
|
||||
$aclTables[] = $role->get('data');
|
||||
$assignmentPermissionList[] = $role->get('assignmentPermission');
|
||||
$userPermissionList[] = $role->get('userPermission');
|
||||
}
|
||||
|
||||
$teams = $this->user->get('teams');
|
||||
foreach ($teams as $team) {
|
||||
$teamRoles = $team->get('roles');
|
||||
foreach ($teamRoles as $role) {
|
||||
$aclTables[] = $role->get('data');
|
||||
$assignmentPermissionList[] = $role->get('assignmentPermission');
|
||||
$userPermissionList[] = $role->get('userPermission');
|
||||
}
|
||||
}
|
||||
|
||||
$this->data['table'] = $this->merge($aclTables);
|
||||
|
||||
$this->data['assignmentPermission'] = $this->mergeValues($assignmentPermissionList, $this->metadata->get('app.acl.valueDefaults.assignmentPermission', 'all'));
|
||||
$this->data['userPermission'] = $this->mergeValues($userPermissionList, $this->metadata->get('app.acl.valueDefaults.userPermission', 'no'));
|
||||
}
|
||||
|
||||
private function initSolid()
|
||||
{
|
||||
if (!$this->metadata) {
|
||||
return;
|
||||
}
|
||||
|
||||
$data = $this->metadata->get('app.acl.solid', array());
|
||||
|
||||
foreach ($data as $entityType => $item) {
|
||||
$this->data['table'][$entityType] = $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 getScopeList()
|
||||
{
|
||||
$scopeList = [];
|
||||
$scopes = $this->metadata->get('scopes');
|
||||
foreach ($scopes as $scope => $d) {
|
||||
if (!empty($d['acl'])) {
|
||||
$scopeList[] = $scope;
|
||||
}
|
||||
}
|
||||
return $scopeList;
|
||||
}
|
||||
|
||||
private function merge($tables)
|
||||
{
|
||||
$data = array();
|
||||
$scopeList = $this->getScopeList();
|
||||
|
||||
foreach ($tables as $table) {
|
||||
foreach ($scopeList as $scope) {
|
||||
if (!isset($table->$scope)) {
|
||||
continue;
|
||||
}
|
||||
$row = $table->$scope;
|
||||
|
||||
if ($row == false) {
|
||||
if (!isset($data[$scope])) {
|
||||
$data[$scope] = false;
|
||||
}
|
||||
} else if ($row === true) {
|
||||
$data[$scope] = true;
|
||||
} else {
|
||||
if (!isset($data[$scope])) {
|
||||
$data[$scope] = array();
|
||||
}
|
||||
if ($data[$scope] == false) {
|
||||
$data[$scope] = array();
|
||||
}
|
||||
|
||||
if (is_array($row) || $row instanceof \stdClass) {
|
||||
foreach ($row as $action => $level) {
|
||||
if (!isset($data[$scope][$action])) {
|
||||
$data[$scope][$action] = $level;
|
||||
} else {
|
||||
if (array_search($data[$scope][$action], $this->levelList) > array_search($level, $this->levelList)) {
|
||||
$data[$scope][$action] = $level;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($scopeList as $scope) {
|
||||
if (!array_key_exists($scope, $data)) {
|
||||
$aclType = $this->metadata->get('scopes.' . $scope . '.acl');
|
||||
if ($aclType === true) {
|
||||
$aclType = 'recordAllTeamOwnNo';
|
||||
}
|
||||
if (!empty($aclType)) {
|
||||
$data[$scope] = $this->metadata->get('app.acl.defaults.' . $aclType, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
private function buildCache()
|
||||
{
|
||||
$contents = '<' . '?'. 'php return ' . var_export($this->data, true) . ';';
|
||||
$this->fileManager->putContents($this->cacheFile, $contents);
|
||||
}
|
||||
}
|
||||
|
||||
181
application/Espo/Core/AclManager.php
Normal file
181
application/Espo/Core/AclManager.php
Normal file
@@ -0,0 +1,181 @@
|
||||
<?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;
|
||||
|
||||
use \Espo\Core\Exceptions\Error;
|
||||
|
||||
use \Espo\ORM\Entity;
|
||||
use \Espo\Entities\User;
|
||||
use \Espo\Core\Utils\Util;
|
||||
|
||||
class AclManager
|
||||
{
|
||||
private $container;
|
||||
|
||||
private $metadata;
|
||||
|
||||
private $implementationHashMap = array();
|
||||
|
||||
private $tableHashMap = array();
|
||||
|
||||
public function __construct(Container $container)
|
||||
{
|
||||
$this->container = $container;
|
||||
$this->metadata = $container->get('metadata');
|
||||
}
|
||||
|
||||
protected function getContainer()
|
||||
{
|
||||
return $this->container;
|
||||
}
|
||||
|
||||
public function getImplementation($scope)
|
||||
{
|
||||
if (empty($this->implementationHashMap[$scope])) {
|
||||
$normalizedName = Util::normilizeClassName($scope);
|
||||
|
||||
$className = '\\Espo\\Custom\\Acl\\' . $normalizedName;
|
||||
if (!class_exists($className)) {
|
||||
$moduleName = $this->metadata->getScopeModuleName($scope);
|
||||
if ($moduleName) {
|
||||
$className = '\\Espo\\Modules\\' . $moduleName . '\\Acl\\' . $normalizedName;
|
||||
} else {
|
||||
$className = '\\Espo\\Acl\\' . $normalizedName;
|
||||
}
|
||||
if (!class_exists($className)) {
|
||||
$className = '\\Espo\\Core\\Acl\\Base';
|
||||
}
|
||||
}
|
||||
|
||||
if (class_exists($className)) {
|
||||
$acl = new $className();
|
||||
$dependencies = $acl->getDependencyList();
|
||||
foreach ($dependencies as $name) {
|
||||
$acl->inject($name, $this->container->get($name));
|
||||
}
|
||||
$this->implementationHashMap[$scope] = $acl;
|
||||
} else {
|
||||
throw new Error();
|
||||
}
|
||||
}
|
||||
|
||||
return $this->implementationHashMap[$scope];
|
||||
}
|
||||
|
||||
protected function getTable(User $user)
|
||||
{
|
||||
$key = spl_object_hash($user);
|
||||
|
||||
if (empty($this->tableHashMap[$key])) {
|
||||
$config = $this->getContainer()->get('config');
|
||||
$fileManager = $this->getContainer()->get('fileManager');
|
||||
$metadata = $this->getContainer()->get('metadata');
|
||||
|
||||
$this->tableHashMap[$key] = new \Espo\Core\Acl\Table($user, $config, $fileManager, $metadata);
|
||||
}
|
||||
|
||||
return $this->tableHashMap[$key];
|
||||
}
|
||||
|
||||
public function getMap(User $user)
|
||||
{
|
||||
return $this->getTable($user)->getMap();
|
||||
}
|
||||
|
||||
public function getLevel(User $user, $scope, $action)
|
||||
{
|
||||
if ($user->isAdmin()) {
|
||||
return 'all';
|
||||
}
|
||||
return $this->getTable($user)->getLevel($scope, $action);
|
||||
}
|
||||
|
||||
public function get(User $user, $permission)
|
||||
{
|
||||
if ($user->isAdmin()) {
|
||||
return true;
|
||||
}
|
||||
return $this->getTable($user)->get($permission);
|
||||
}
|
||||
|
||||
public function checkReadOnlyTeam(User $user, $scope)
|
||||
{
|
||||
if ($user->isAdmin()) {
|
||||
return false;
|
||||
}
|
||||
$data = $this->getTable($user)->getScopeData($scope);
|
||||
return $this->getImplementation($scope)->checkReadOnlyTeam($user, $scope, $data);
|
||||
}
|
||||
|
||||
public function checkReadOnlyOwn(User $user, $scope)
|
||||
{
|
||||
if ($user->isAdmin()) {
|
||||
return false;
|
||||
}
|
||||
$data = $this->getTable($user)->getScopeData($scope);
|
||||
return $this->getImplementation($scope)->checkReadOnlyOwn($user, $scope, $data);
|
||||
}
|
||||
|
||||
public function check(User $user, $subject, $action = null, $isOwner = null, $inTeam = null)
|
||||
{
|
||||
if ($user->isAdmin()) {
|
||||
return true;
|
||||
}
|
||||
if (is_string($subject)) {
|
||||
return $this->checkScope($user, $subject, $action, $isOwner, $inTeam);
|
||||
} else {
|
||||
$entity = $subject;
|
||||
if ($entity instanceof Entity) {
|
||||
$entityType = $entity->getEntityType();
|
||||
|
||||
$impl = $this->getImplementation($entityType);
|
||||
$methodName = 'checkEntity' . ucfirst($action);
|
||||
if (method_exists($impl, $methodName)) {
|
||||
$data = $this->getTable($user)->getScopeData($entityType);
|
||||
return $impl->$methodName($user, $entity, $data);
|
||||
}
|
||||
|
||||
return $this->checkEntity($user, $entity, $action);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function checkEntity(User $user, Entity $entity, $action)
|
||||
{
|
||||
if ($user->isAdmin()) {
|
||||
return true;
|
||||
}
|
||||
$data = $this->getTable($user)->getScopeData($entity->getEntityType());
|
||||
return $this->getImplementation($scope)->checkEntity($user, $entity, $data, $action);
|
||||
}
|
||||
|
||||
public function checkScope(User $user, $scope, $action = null, $isOwner = null, $inTeam = null, $entity = null)
|
||||
{
|
||||
if ($user->isAdmin()) {
|
||||
return true;
|
||||
}
|
||||
$data = $this->getTable($user)->getScopeData($scope);
|
||||
return $this->getImplementation($scope)->checkScope($user, $data, $scope, $action, $isOwner, $inTeam, $entity);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM - Open Source CRM application.
|
||||
* Copyright (C) 2014 Yuri Kuznetsov, Taras Machyshyn, Oleksiy Avramenko
|
||||
* 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
|
||||
@@ -25,54 +25,56 @@ namespace Espo\Core;
|
||||
|
||||
class Application
|
||||
{
|
||||
private $metadata;
|
||||
private $metadata;
|
||||
|
||||
private $container;
|
||||
private $container;
|
||||
|
||||
private $slim;
|
||||
private $slim;
|
||||
|
||||
private $auth;
|
||||
private $auth;
|
||||
|
||||
/**
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->container = new Container();
|
||||
$this->container = new Container();
|
||||
|
||||
date_default_timezone_set('UTC');
|
||||
date_default_timezone_set('UTC');
|
||||
|
||||
$GLOBALS['log'] = $this->container->get('log');
|
||||
$GLOBALS['log'] = $this->container->get('log');
|
||||
|
||||
$this->initAutoloads();
|
||||
}
|
||||
|
||||
public function getSlim()
|
||||
{
|
||||
if (empty($this->slim)) {
|
||||
$this->slim = $this->container->get('slim');
|
||||
}
|
||||
return $this->slim;
|
||||
}
|
||||
public function getSlim()
|
||||
{
|
||||
if (empty($this->slim)) {
|
||||
$this->slim = $this->container->get('slim');
|
||||
}
|
||||
return $this->slim;
|
||||
}
|
||||
|
||||
public function getMetadata()
|
||||
{
|
||||
if (empty($this->metadata)) {
|
||||
$this->metadata = $this->container->get('metadata');
|
||||
}
|
||||
return $this->metadata;
|
||||
}
|
||||
public function getMetadata()
|
||||
{
|
||||
if (empty($this->metadata)) {
|
||||
$this->metadata = $this->container->get('metadata');
|
||||
}
|
||||
return $this->metadata;
|
||||
}
|
||||
|
||||
protected function getAuth()
|
||||
{
|
||||
if (empty($this->auth)) {
|
||||
$this->auth = new \Espo\Core\Utils\Auth($this->container);
|
||||
}
|
||||
return $this->auth;
|
||||
if (empty($this->auth)) {
|
||||
$this->auth = new \Espo\Core\Utils\Auth($this->container);
|
||||
}
|
||||
return $this->auth;
|
||||
}
|
||||
|
||||
public function getContainer()
|
||||
{
|
||||
return $this->container;
|
||||
}
|
||||
public function getContainer()
|
||||
{
|
||||
return $this->container;
|
||||
}
|
||||
|
||||
public function run($name = 'default')
|
||||
{
|
||||
@@ -83,160 +85,200 @@ class Application
|
||||
|
||||
public function runClient()
|
||||
{
|
||||
$config = $this->getContainer()->get('config');
|
||||
$config = $this->getContainer()->get('config');
|
||||
|
||||
$html = file_get_contents('main.html');
|
||||
$html = str_replace('{{cacheTimestamp}}', $config->get('cacheTimestamp', 0), $html);
|
||||
$html = str_replace('{{useCache}}', $config->get('useCache') ? 'true' : 'false' , $html);
|
||||
echo $html;
|
||||
exit;
|
||||
$html = file_get_contents('main.html');
|
||||
$html = str_replace('{{cacheTimestamp}}', $config->get('cacheTimestamp', 0), $html);
|
||||
$html = str_replace('{{useCache}}', $config->get('useCache') ? 'true' : 'false' , $html);
|
||||
$html = str_replace('{{runScript}}', 'app.start();' , $html);
|
||||
echo $html;
|
||||
exit;
|
||||
}
|
||||
|
||||
public function runEntryPoint($entryPoint)
|
||||
{
|
||||
if (empty($entryPoint)) {
|
||||
throw new \Error();
|
||||
}
|
||||
if (empty($entryPoint)) {
|
||||
throw new \Error();
|
||||
}
|
||||
|
||||
$slim = $this->getSlim();
|
||||
$container = $this->getContainer();
|
||||
$slim = $this->getSlim();
|
||||
$container = $this->getContainer();
|
||||
|
||||
$slim->get('/', function() {});
|
||||
$slim->get('/', function() {});
|
||||
$slim->post('/', function() {});
|
||||
|
||||
$entryPointManager = new \Espo\Core\EntryPointManager($container);
|
||||
$entryPointManager = new \Espo\Core\EntryPointManager($container);
|
||||
|
||||
$auth = $this->getAuth();
|
||||
$apiAuth = new \Espo\Core\Utils\Api\Auth($auth, $entryPointManager->checkAuthRequired($entryPoint), true);
|
||||
$slim->add($apiAuth);
|
||||
try {
|
||||
$auth = $this->getAuth();
|
||||
$apiAuth = new \Espo\Core\Utils\Api\Auth($auth, $entryPointManager->checkAuthRequired($entryPoint), true);
|
||||
$slim->add($apiAuth);
|
||||
|
||||
$slim->hook('slim.before.dispatch', function () use ($entryPoint, $entryPointManager, $container) {
|
||||
try {
|
||||
$entryPointManager->run($entryPoint);
|
||||
} catch (\Exception $e) {
|
||||
$container->get('output')->processError($e->getMessage(), $e->getCode(), true);
|
||||
}
|
||||
});
|
||||
$slim->hook('slim.before.dispatch', function () use ($entryPoint, $entryPointManager, $container) {
|
||||
$entryPointManager->run($entryPoint);
|
||||
});
|
||||
|
||||
$slim->run();
|
||||
$slim->run();
|
||||
} catch (\Exception $e) {
|
||||
$container->get('output')->processError($e->getMessage(), $e->getCode(), true);
|
||||
}
|
||||
}
|
||||
|
||||
public function runCron()
|
||||
{
|
||||
$auth = $this->getAuth();
|
||||
$auth->useNoAuth(true);
|
||||
$auth = $this->getAuth();
|
||||
$auth->useNoAuth(true);
|
||||
|
||||
$cronManager = new \Espo\Core\CronManager($this->container);
|
||||
$cronManager->run();
|
||||
$cronManager = new \Espo\Core\CronManager($this->container);
|
||||
$cronManager->run();
|
||||
}
|
||||
|
||||
public function runRebuild()
|
||||
{
|
||||
$dataManager = $this->getContainer()->get('dataManager');
|
||||
$dataManager->rebuild();
|
||||
$dataManager = $this->getContainer()->get('dataManager');
|
||||
$dataManager->rebuild();
|
||||
}
|
||||
|
||||
public function runClearCache()
|
||||
{
|
||||
$dataManager = $this->getContainer()->get('dataManager');
|
||||
$dataManager->clearCache();
|
||||
}
|
||||
|
||||
public function isInstalled()
|
||||
{
|
||||
$config = $this->getContainer()->get('config');
|
||||
$config = $this->getContainer()->get('config');
|
||||
|
||||
if (file_exists($config->getConfigPath()) && $config->get('isInstalled')) {
|
||||
return true;
|
||||
}
|
||||
if (file_exists($config->getConfigPath()) && $config->get('isInstalled')) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
|
||||
protected function routeHooks()
|
||||
{
|
||||
$container = $this->getContainer();
|
||||
$slim = $this->getSlim();
|
||||
protected function routeHooks()
|
||||
{
|
||||
$container = $this->getContainer();
|
||||
$slim = $this->getSlim();
|
||||
|
||||
$auth = $this->getAuth();
|
||||
try {
|
||||
$auth = $this->getAuth();
|
||||
} catch (\Exception $e) {
|
||||
$container->get('output')->processError($e->getMessage(), $e->getCode());
|
||||
}
|
||||
|
||||
$apiAuth = new \Espo\Core\Utils\Api\Auth($auth);
|
||||
$this->getSlim()->add($apiAuth);
|
||||
$apiAuth = new \Espo\Core\Utils\Api\Auth($auth);
|
||||
$this->getSlim()->add($apiAuth);
|
||||
|
||||
$this->getSlim()->hook('slim.before.dispatch', function () use ($slim, $container) {
|
||||
$this->getSlim()->hook('slim.before.dispatch', function () use ($slim, $container) {
|
||||
|
||||
$route = $slim->router()->getCurrentRoute();
|
||||
$conditions = $route->getConditions();
|
||||
$route = $slim->router()->getCurrentRoute();
|
||||
$conditions = $route->getConditions();
|
||||
|
||||
if (isset($conditions['useController']) && $conditions['useController'] == false) {
|
||||
return;
|
||||
}
|
||||
if (isset($conditions['useController']) && $conditions['useController'] == false) {
|
||||
return;
|
||||
}
|
||||
|
||||
$routeOptions = call_user_func($route->getCallable());
|
||||
$routeKeys = is_array($routeOptions) ? array_keys($routeOptions) : array();
|
||||
$routeOptions = call_user_func($route->getCallable());
|
||||
$routeKeys = is_array($routeOptions) ? array_keys($routeOptions) : array();
|
||||
|
||||
if (!in_array('controller', $routeKeys, true)) {
|
||||
return $container->get('output')->render($routeOptions);
|
||||
}
|
||||
if (!in_array('controller', $routeKeys, true)) {
|
||||
return $container->get('output')->render($routeOptions);
|
||||
}
|
||||
|
||||
$params = $route->getParams();
|
||||
$data = $slim->request()->getBody();
|
||||
$params = $route->getParams();
|
||||
$data = $slim->request()->getBody();
|
||||
|
||||
foreach ($routeOptions as $key => $value) {
|
||||
if (strstr($value, ':')) {
|
||||
$paramName = str_replace(':', '', $value);
|
||||
$value = $params[$paramName];
|
||||
}
|
||||
$controllerParams[$key] = $value;
|
||||
}
|
||||
foreach ($routeOptions as $key => $value) {
|
||||
if (strstr($value, ':')) {
|
||||
$paramName = str_replace(':', '', $value);
|
||||
$value = $params[$paramName];
|
||||
}
|
||||
$controllerParams[$key] = $value;
|
||||
}
|
||||
|
||||
$params = array_merge($params, $controllerParams);
|
||||
$params = array_merge($params, $controllerParams);
|
||||
|
||||
$controllerName = ucfirst($controllerParams['controller']);
|
||||
$controllerName = ucfirst($controllerParams['controller']);
|
||||
|
||||
if (!empty($controllerParams['action'])) {
|
||||
$actionName = $controllerParams['action'];
|
||||
} else {
|
||||
$httpMethod = strtolower($slim->request()->getMethod());
|
||||
$crudList = $container->get('config')->get('crud');
|
||||
$actionName = $crudList[$httpMethod];
|
||||
}
|
||||
if (!empty($controllerParams['action'])) {
|
||||
$actionName = $controllerParams['action'];
|
||||
} else {
|
||||
$httpMethod = strtolower($slim->request()->getMethod());
|
||||
$crudList = $container->get('config')->get('crud');
|
||||
$actionName = $crudList[$httpMethod];
|
||||
}
|
||||
|
||||
try {
|
||||
$controllerManager = new \Espo\Core\ControllerManager($container);
|
||||
$result = $controllerManager->process($controllerName, $actionName, $params, $data, $slim->request());
|
||||
$container->get('output')->render($result);
|
||||
} catch (\Exception $e) {
|
||||
$container->get('output')->processError($e->getMessage(), $e->getCode());
|
||||
}
|
||||
});
|
||||
try {
|
||||
$controllerManager = new \Espo\Core\ControllerManager($container);
|
||||
$result = $controllerManager->process($controllerName, $actionName, $params, $data, $slim->request());
|
||||
$container->get('output')->render($result);
|
||||
} catch (\Exception $e) {
|
||||
$container->get('output')->processError($e->getMessage(), $e->getCode());
|
||||
}
|
||||
});
|
||||
|
||||
$this->getSlim()->hook('slim.after.router', function () use (&$slim) {
|
||||
$slim->contentType('application/json');
|
||||
$this->getSlim()->hook('slim.after.router', function () use (&$slim) {
|
||||
$slim->contentType('application/json');
|
||||
|
||||
$res = $slim->response();
|
||||
$res->header('Expires', '0');
|
||||
$res->header('Last-Modified', gmdate("D, d M Y H:i:s") . " GMT");
|
||||
$res->header('Cache-Control', 'no-store, no-cache, must-revalidate, post-check=0, pre-check=0');
|
||||
$res->header('Pragma', 'no-cache');
|
||||
});
|
||||
}
|
||||
$res = $slim->response();
|
||||
$res->header('Expires', '0');
|
||||
$res->header('Last-Modified', gmdate("D, d M Y H:i:s") . " GMT");
|
||||
$res->header('Cache-Control', 'no-store, no-cache, must-revalidate, post-check=0, pre-check=0');
|
||||
$res->header('Pragma', 'no-cache');
|
||||
});
|
||||
}
|
||||
|
||||
protected function initRoutes()
|
||||
{
|
||||
$routes = new \Espo\Core\Utils\Route($this->getContainer()->get('config'), $this->getMetadata(), $this->getContainer()->get('fileManager'));
|
||||
$crudList = array_keys( $this->getContainer()->get('config')->get('crud') );
|
||||
|
||||
protected function initRoutes()
|
||||
{
|
||||
$routes = new \Espo\Core\Utils\Route($this->getContainer()->get('config'), $this->getMetadata(), $this->getContainer()->get('fileManager'));
|
||||
$crudList = array_keys( $this->getContainer()->get('config')->get('crud') );
|
||||
foreach ($routes->getAll() as $route) {
|
||||
|
||||
foreach ($routes->getAll() as $route) {
|
||||
|
||||
$method = strtolower($route['method']);
|
||||
if (!in_array($method, $crudList)) {
|
||||
$GLOBALS['log']->error('Route: Method ['.$method.'] does not exist. Please check your route ['.$route['route'].']');
|
||||
continue;
|
||||
}
|
||||
$method = strtolower($route['method']);
|
||||
if (!in_array($method, $crudList)) {
|
||||
$GLOBALS['log']->error('Route: Method ['.$method.'] does not exist. Please check your route ['.$route['route'].']');
|
||||
continue;
|
||||
}
|
||||
|
||||
$currentRoute = $this->getSlim()->$method($route['route'], function() use ($route) { //todo change "use" for php 5.4
|
||||
return $route['params'];
|
||||
});
|
||||
return $route['params'];
|
||||
});
|
||||
|
||||
if (isset($route['conditions'])) {
|
||||
$currentRoute->conditions($route['conditions']);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (isset($route['conditions'])) {
|
||||
$currentRoute->conditions($route['conditions']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected function initAutoloads()
|
||||
{
|
||||
$autoload = new \Espo\Core\Utils\Autoload($this->getContainer()->get('config'), $this->getMetadata(), $this->getContainer()->get('fileManager'));
|
||||
|
||||
try {
|
||||
$autoloadList = $autoload->getAll();
|
||||
} catch (\Exception $e) {} //bad permissions
|
||||
|
||||
if (empty($autoloadList)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$namespacesPath = 'vendor/composer/autoload_namespaces.php';
|
||||
$existingNamespaces = file_exists($namespacesPath) ? include($namespacesPath) : array();
|
||||
if (!empty($existingNamespaces) && is_array($existingNamespaces)) {
|
||||
$existingNamespaces = array_keys($existingNamespaces);
|
||||
}
|
||||
|
||||
$classLoader = new \Composer\Autoload\ClassLoader();
|
||||
|
||||
foreach ($autoloadList as $prefix => $path) {
|
||||
if (!in_array($prefix, $existingNamespaces)) {
|
||||
$classLoader->add($prefix, $path);
|
||||
}
|
||||
}
|
||||
|
||||
$classLoader->register(true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM - Open Source CRM application.
|
||||
* Copyright (C) 2014 Yuri Kuznetsov, Taras Machyshyn, Oleksiy Avramenko
|
||||
* 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
|
||||
@@ -25,10 +25,10 @@ namespace Espo\Core;
|
||||
class Container
|
||||
{
|
||||
|
||||
private $data = array();
|
||||
private $data = array();
|
||||
|
||||
|
||||
/**
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public function __construct()
|
||||
@@ -38,186 +38,241 @@ class Container
|
||||
|
||||
public function get($name)
|
||||
{
|
||||
if (empty($this->data[$name])) {
|
||||
$this->load($name);
|
||||
}
|
||||
return $this->data[$name];
|
||||
if (empty($this->data[$name])) {
|
||||
$this->load($name);
|
||||
}
|
||||
return $this->data[$name];
|
||||
}
|
||||
|
||||
private function load($name)
|
||||
{
|
||||
$loadMethod = 'load' . ucfirst($name);
|
||||
if (method_exists($this, $loadMethod)) {
|
||||
$obj = $this->$loadMethod();
|
||||
$this->data[$name] = $obj;
|
||||
} else {
|
||||
//external loader class \Espo\Core\Loaders\<className> or \Espo\Custom\Core\Loaders\<className> with load() method
|
||||
$className = '\Espo\Custom\Core\Loaders\\'.ucfirst($name);
|
||||
if (!class_exists($className)) {
|
||||
$className = '\Espo\Core\Loaders\\'.ucfirst($name);
|
||||
$loadMethod = 'load' . ucfirst($name);
|
||||
if (method_exists($this, $loadMethod)) {
|
||||
$obj = $this->$loadMethod();
|
||||
$this->data[$name] = $obj;
|
||||
} else {
|
||||
|
||||
try {
|
||||
$className = $this->get('metadata')->get('app.loaders.' . ucfirst($name));
|
||||
} catch (\Exception $e) {}
|
||||
|
||||
if (!isset($className) || !class_exists($className)) {
|
||||
$className = '\Espo\Custom\Core\Loaders\\'.ucfirst($name);
|
||||
if (!class_exists($className)) {
|
||||
$className = '\Espo\Core\Loaders\\'.ucfirst($name);
|
||||
}
|
||||
}
|
||||
|
||||
if (class_exists($className)) {
|
||||
$loadClass = new $className($this);
|
||||
$this->data[$name] = $loadClass->load();
|
||||
}
|
||||
}
|
||||
if (class_exists($className)) {
|
||||
$loadClass = new $className($this);
|
||||
$this->data[$name] = $loadClass->load();
|
||||
}
|
||||
}
|
||||
|
||||
// TODO throw an exception
|
||||
return null;
|
||||
return null;
|
||||
}
|
||||
|
||||
protected function getServiceClassName($name, $default)
|
||||
{
|
||||
$metadata = $this->get('metadata');
|
||||
$className = $metadata->get('app.serviceContainer.classNames.' . $name, $default);
|
||||
return $className;
|
||||
}
|
||||
|
||||
protected function 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;
|
||||
}
|
||||
|
||||
private function loadSlim()
|
||||
{
|
||||
//return new \Slim\Slim();
|
||||
return new \Espo\Core\Utils\Api\Slim();
|
||||
}
|
||||
|
||||
private function loadFileManager()
|
||||
private function loadFileManager()
|
||||
{
|
||||
return new \Espo\Core\Utils\File\Manager(
|
||||
$this->get('config')
|
||||
);
|
||||
return new \Espo\Core\Utils\File\Manager(
|
||||
$this->get('config')
|
||||
);
|
||||
}
|
||||
|
||||
private function loadPreferences()
|
||||
private function loadPreferences()
|
||||
{
|
||||
return $this->get('entityManager')->getEntity('Preferences', $this->get('user')->id);
|
||||
return $this->get('entityManager')->getEntity('Preferences', $this->get('user')->id);
|
||||
}
|
||||
|
||||
private function loadConfig()
|
||||
private function loadConfig()
|
||||
{
|
||||
return new \Espo\Core\Utils\Config(
|
||||
new \Espo\Core\Utils\File\Manager()
|
||||
);
|
||||
return new \Espo\Core\Utils\Config(
|
||||
new \Espo\Core\Utils\File\Manager()
|
||||
);
|
||||
}
|
||||
|
||||
private function loadHookManager()
|
||||
private function loadHookManager()
|
||||
{
|
||||
return new \Espo\Core\HookManager(
|
||||
$this
|
||||
);
|
||||
return new \Espo\Core\HookManager(
|
||||
$this
|
||||
);
|
||||
}
|
||||
|
||||
private function loadOutput()
|
||||
private function loadOutput()
|
||||
{
|
||||
return new \Espo\Core\Utils\Api\Output(
|
||||
$this->get('slim')
|
||||
);
|
||||
return new \Espo\Core\Utils\Api\Output(
|
||||
$this->get('slim')
|
||||
);
|
||||
}
|
||||
|
||||
private function loadMailSender()
|
||||
private function loadMailSender()
|
||||
{
|
||||
return new \Espo\Core\Mail\Sender(
|
||||
$this->get('config')
|
||||
);
|
||||
$className = $this->getServiceClassName('mailSernder', '\\Espo\\Core\\Mail\\Sender');
|
||||
return new $className(
|
||||
$this->get('config')
|
||||
);
|
||||
}
|
||||
|
||||
private function loadDateTime()
|
||||
private function loadDateTime()
|
||||
{
|
||||
return new \Espo\Core\Utils\DateTime(
|
||||
$this->get('config')->get('dateFormat'),
|
||||
$this->get('config')->get('timeFormat'),
|
||||
$this->get('config')->get('timeZone')
|
||||
);
|
||||
return new \Espo\Core\Utils\DateTime(
|
||||
$this->get('config')->get('dateFormat'),
|
||||
$this->get('config')->get('timeFormat'),
|
||||
$this->get('config')->get('timeZone')
|
||||
);
|
||||
}
|
||||
|
||||
private function loadServiceFactory()
|
||||
private function loadServiceFactory()
|
||||
{
|
||||
return new \Espo\Core\ServiceFactory(
|
||||
$this
|
||||
);
|
||||
return new \Espo\Core\ServiceFactory(
|
||||
$this
|
||||
);
|
||||
}
|
||||
|
||||
private function loadSelectManagerFactory()
|
||||
private function loadSelectManagerFactory()
|
||||
{
|
||||
return new \Espo\Core\SelectManagerFactory(
|
||||
$this->get('entityManager'),
|
||||
$this->get('user'),
|
||||
$this->get('acl'),
|
||||
$this->get('metadata')
|
||||
);
|
||||
return new \Espo\Core\SelectManagerFactory(
|
||||
$this->get('entityManager'),
|
||||
$this->get('user'),
|
||||
$this->get('acl'),
|
||||
$this->get('metadata')
|
||||
);
|
||||
}
|
||||
|
||||
private function loadMetadata()
|
||||
private function loadMetadata()
|
||||
{
|
||||
return new \Espo\Core\Utils\Metadata(
|
||||
$this->get('config'),
|
||||
$this->get('fileManager')
|
||||
);
|
||||
return new \Espo\Core\Utils\Metadata(
|
||||
$this->get('config'),
|
||||
$this->get('fileManager')
|
||||
);
|
||||
}
|
||||
|
||||
private function loadLayout()
|
||||
private function loadLayout()
|
||||
{
|
||||
return new \Espo\Core\Utils\Layout(
|
||||
$this->get('fileManager'),
|
||||
$this->get('metadata')
|
||||
);
|
||||
return new \Espo\Core\Utils\Layout(
|
||||
$this->get('fileManager'),
|
||||
$this->get('metadata')
|
||||
);
|
||||
}
|
||||
|
||||
private function loadAcl()
|
||||
{
|
||||
return new \Espo\Core\Acl(
|
||||
$this->get('user'),
|
||||
$this->get('config'),
|
||||
$this->get('fileManager')
|
||||
);
|
||||
}
|
||||
private function loadAclManager()
|
||||
{
|
||||
$className = $this->getServiceClassName('acl', '\\Espo\\Core\\AclManager');
|
||||
return new $className(
|
||||
$this->get('container')
|
||||
);
|
||||
}
|
||||
|
||||
private function loadSchema()
|
||||
{
|
||||
return new \Espo\Core\Utils\Database\Schema\Schema(
|
||||
$this->get('config'),
|
||||
$this->get('metadata'),
|
||||
$this->get('fileManager'),
|
||||
$this->get('entityManager'),
|
||||
$this->get('classParser')
|
||||
);
|
||||
}
|
||||
private function loadAcl()
|
||||
{
|
||||
$className = $this->getServiceClassName('acl', '\\Espo\\Core\\Acl');
|
||||
return new $className(
|
||||
$this->get('aclManager'),
|
||||
$this->get('user')
|
||||
);
|
||||
}
|
||||
|
||||
private function loadClassParser()
|
||||
{
|
||||
return new \Espo\Core\Utils\File\ClassParser(
|
||||
$this->get('fileManager'),
|
||||
$this->get('config'),
|
||||
$this->get('metadata')
|
||||
);
|
||||
}
|
||||
private function loadSchema()
|
||||
{
|
||||
return new \Espo\Core\Utils\Database\Schema\Schema(
|
||||
$this->get('config'),
|
||||
$this->get('metadata'),
|
||||
$this->get('fileManager'),
|
||||
$this->get('entityManager'),
|
||||
$this->get('classParser')
|
||||
);
|
||||
}
|
||||
|
||||
private function loadLanguage()
|
||||
{
|
||||
return new \Espo\Core\Utils\Language(
|
||||
$this->get('fileManager'),
|
||||
$this->get('config'),
|
||||
$this->get('preferences')
|
||||
);
|
||||
}
|
||||
private function loadClassParser()
|
||||
{
|
||||
return new \Espo\Core\Utils\File\ClassParser(
|
||||
$this->get('fileManager'),
|
||||
$this->get('config'),
|
||||
$this->get('metadata')
|
||||
);
|
||||
}
|
||||
|
||||
private function loadScheduledJob()
|
||||
{
|
||||
return new \Espo\Core\Cron\ScheduledJob(
|
||||
$this
|
||||
);
|
||||
}
|
||||
private function loadLanguage()
|
||||
{
|
||||
return new \Espo\Core\Utils\Language(
|
||||
$this->get('fileManager'),
|
||||
$this->get('config'),
|
||||
$this->get('metadata'),
|
||||
$this->get('preferences')
|
||||
);
|
||||
}
|
||||
|
||||
private function loadDataManager()
|
||||
{
|
||||
return new \Espo\Core\DataManager(
|
||||
$this
|
||||
);
|
||||
}
|
||||
private function loadCrypt()
|
||||
{
|
||||
return new \Espo\Core\Utils\Crypt(
|
||||
$this->get('config')
|
||||
);
|
||||
}
|
||||
|
||||
private function loadFieldManager()
|
||||
{
|
||||
return new \Espo\Core\Utils\FieldManager(
|
||||
$this->get('metadata'),
|
||||
$this->get('language')
|
||||
);
|
||||
}
|
||||
private function loadScheduledJob()
|
||||
{
|
||||
return new \Espo\Core\Utils\ScheduledJob(
|
||||
$this
|
||||
);
|
||||
}
|
||||
|
||||
public function setUser($user)
|
||||
{
|
||||
$this->data['user'] = $user;
|
||||
}
|
||||
private function loadDataManager()
|
||||
{
|
||||
return new \Espo\Core\DataManager(
|
||||
$this
|
||||
);
|
||||
}
|
||||
|
||||
private function loadFieldManager()
|
||||
{
|
||||
return new \Espo\Core\Utils\FieldManager(
|
||||
$this->get('metadata'),
|
||||
$this->get('language')
|
||||
);
|
||||
}
|
||||
|
||||
public function setUser($user)
|
||||
{
|
||||
$this->data['user'] = $user;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM - Open Source CRM application.
|
||||
* Copyright (C) 2014 Yuri Kuznetsov, Taras Machyshyn, Oleksiy Avramenko
|
||||
* 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
|
||||
@@ -27,88 +27,88 @@ use \Espo\Core\Exceptions\NotFound;
|
||||
|
||||
class ControllerManager
|
||||
{
|
||||
private $config;
|
||||
private $config;
|
||||
|
||||
private $metadata;
|
||||
private $metadata;
|
||||
|
||||
private $container;
|
||||
private $container;
|
||||
|
||||
public function __construct(\Espo\Core\Container $container)
|
||||
{
|
||||
$this->container = $container;
|
||||
public function __construct(\Espo\Core\Container $container)
|
||||
{
|
||||
$this->container = $container;
|
||||
|
||||
$this->config = $this->container->get('config');
|
||||
$this->metadata = $this->container->get('metadata');
|
||||
}
|
||||
$this->config = $this->container->get('config');
|
||||
$this->metadata = $this->container->get('metadata');
|
||||
}
|
||||
|
||||
protected function getConfig()
|
||||
{
|
||||
return $this->config;
|
||||
}
|
||||
{
|
||||
return $this->config;
|
||||
}
|
||||
|
||||
protected function getMetadata()
|
||||
{
|
||||
return $this->metadata;
|
||||
}
|
||||
protected function getMetadata()
|
||||
{
|
||||
return $this->metadata;
|
||||
}
|
||||
|
||||
public function process($controllerName, $actionName, $params, $data, $request)
|
||||
{
|
||||
$customeClassName = '\\Espo\\Custom\\Controllers\\' . Util::normilizeClassName($controllerName);
|
||||
if (class_exists($customeClassName)) {
|
||||
$controllerClassName = $customeClassName;
|
||||
} else {
|
||||
$moduleName = $this->metadata->getScopeModuleName($controllerName);
|
||||
if ($moduleName) {
|
||||
$controllerClassName = '\\Espo\\Modules\\' . $moduleName . '\\Controllers\\' . Util::normilizeClassName($controllerName);
|
||||
} else {
|
||||
$controllerClassName = '\\Espo\\Controllers\\' . Util::normilizeClassName($controllerName);
|
||||
}
|
||||
}
|
||||
public function process($controllerName, $actionName, $params, $data, $request)
|
||||
{
|
||||
$customeClassName = '\\Espo\\Custom\\Controllers\\' . Util::normilizeClassName($controllerName);
|
||||
if (class_exists($customeClassName)) {
|
||||
$controllerClassName = $customeClassName;
|
||||
} else {
|
||||
$moduleName = $this->metadata->getScopeModuleName($controllerName);
|
||||
if ($moduleName) {
|
||||
$controllerClassName = '\\Espo\\Modules\\' . $moduleName . '\\Controllers\\' . Util::normilizeClassName($controllerName);
|
||||
} else {
|
||||
$controllerClassName = '\\Espo\\Controllers\\' . Util::normilizeClassName($controllerName);
|
||||
}
|
||||
}
|
||||
|
||||
if ($data && stristr($request->getContentType(), 'application/json')) {
|
||||
$data = json_decode($data);
|
||||
}
|
||||
if ($data && stristr($request->getContentType(), 'application/json')) {
|
||||
$data = json_decode($data);
|
||||
}
|
||||
|
||||
|
||||
if ($data instanceof \stdClass) {
|
||||
$data = get_object_vars($data);
|
||||
}
|
||||
if ($data instanceof \stdClass) {
|
||||
$data = get_object_vars($data);
|
||||
}
|
||||
|
||||
if (!class_exists($controllerClassName)) {
|
||||
throw new NotFound("Controller '$controllerName' is not found");
|
||||
}
|
||||
if (!class_exists($controllerClassName)) {
|
||||
throw new NotFound("Controller '$controllerName' is not found");
|
||||
}
|
||||
|
||||
$controller = new $controllerClassName($this->container);
|
||||
$controller = new $controllerClassName($this->container, $request->getMethod());
|
||||
|
||||
if ($actionName == 'index') {
|
||||
$actionName = $controllerClassName::$defaultAction;
|
||||
}
|
||||
if ($actionName == 'index') {
|
||||
$actionName = $controllerClassName::$defaultAction;
|
||||
}
|
||||
|
||||
$actionNameUcfirst = ucfirst($actionName);
|
||||
$actionNameUcfirst = ucfirst($actionName);
|
||||
|
||||
$beforeMethodName = 'before' . $actionNameUcfirst;
|
||||
if (method_exists($controller, $beforeMethodName)) {
|
||||
$controller->$beforeMethodName($params, $data, $request);
|
||||
}
|
||||
$actionMethodName = 'action' . $actionNameUcfirst;
|
||||
$beforeMethodName = 'before' . $actionNameUcfirst;
|
||||
if (method_exists($controller, $beforeMethodName)) {
|
||||
$controller->$beforeMethodName($params, $data, $request);
|
||||
}
|
||||
$actionMethodName = 'action' . $actionNameUcfirst;
|
||||
|
||||
if (!method_exists($controller, $actionMethodName)) {
|
||||
throw new NotFound("Action '$actionMethodName' does not exist in controller '$controller'");
|
||||
}
|
||||
if (!method_exists($controller, $actionMethodName)) {
|
||||
throw new NotFound("Action '$actionMethodName' does not exist in controller '$controller'");
|
||||
}
|
||||
|
||||
$result = $controller->$actionMethodName($params, $data, $request);
|
||||
$result = $controller->$actionMethodName($params, $data, $request);
|
||||
|
||||
$afterMethodName = 'after' . $actionNameUcfirst;
|
||||
if (method_exists($controller, $afterMethodName)) {
|
||||
$controller->$afterMethodName($params, $data, $request);
|
||||
}
|
||||
$afterMethodName = 'after' . $actionNameUcfirst;
|
||||
if (method_exists($controller, $afterMethodName)) {
|
||||
$controller->$afterMethodName($params, $data, $request);
|
||||
}
|
||||
|
||||
if (is_array($result) || is_bool($result)) {
|
||||
return \Espo\Core\Utils\Json::encode($result);
|
||||
}
|
||||
if (is_array($result) || is_bool($result)) {
|
||||
return \Espo\Core\Utils\Json::encode($result);
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM - Open Source CRM application.
|
||||
* Copyright (C) 2014 Yuri Kuznetsov, Taras Machyshyn, Oleksiy Avramenko
|
||||
* 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
|
||||
@@ -18,7 +18,7 @@
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with EspoCRM. If not, see http://www.gnu.org/licenses/.
|
||||
************************************************************************/
|
||||
************************************************************************/
|
||||
|
||||
namespace Espo\Core\Controllers;
|
||||
|
||||
@@ -28,70 +28,96 @@ use \Espo\Core\Utils\Util;
|
||||
|
||||
abstract class Base
|
||||
{
|
||||
protected $name;
|
||||
|
||||
private $container;
|
||||
|
||||
public static $defaultAction = 'index';
|
||||
protected $name;
|
||||
|
||||
public function __construct(Container $container)
|
||||
{
|
||||
$this->container = $container;
|
||||
|
||||
if (empty($this->name)) {
|
||||
$name = get_class($this);
|
||||
if (preg_match('@\\\\([\w]+)$@', $name, $matches)) {
|
||||
$name = $matches[1];
|
||||
}
|
||||
$this->name = $name;
|
||||
}
|
||||
|
||||
$this->checkControllerAccess();
|
||||
}
|
||||
|
||||
protected function checkControllerAccess()
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
protected function getContainer()
|
||||
{
|
||||
return $this->container;
|
||||
}
|
||||
|
||||
protected function getUser()
|
||||
{
|
||||
return $this->container->get('user');
|
||||
}
|
||||
|
||||
protected function getAcl()
|
||||
{
|
||||
return $this->container->get('acl');
|
||||
}
|
||||
|
||||
protected function getConfig()
|
||||
{
|
||||
return $this->container->get('config');
|
||||
}
|
||||
|
||||
protected function getPreferences()
|
||||
{
|
||||
return $this->container->get('preferences');
|
||||
}
|
||||
|
||||
protected function getMetadata()
|
||||
{
|
||||
return $this->container->get('metadata');
|
||||
}
|
||||
private $container;
|
||||
|
||||
protected function getServiceFactory()
|
||||
{
|
||||
return $this->container->get('serviceFactory');
|
||||
}
|
||||
|
||||
protected function getService($name)
|
||||
{
|
||||
return $this->getServiceFactory()->create($name);
|
||||
}
|
||||
private $requestMethod;
|
||||
|
||||
public static $defaultAction = 'index';
|
||||
|
||||
public function __construct(Container $container, $requestMethod = null)
|
||||
{
|
||||
$this->container = $container;
|
||||
|
||||
if (isset($requestMethod)) {
|
||||
$this->setRequestMethod($requestMethod);
|
||||
}
|
||||
|
||||
if (empty($this->name)) {
|
||||
$name = get_class($this);
|
||||
if (preg_match('@\\\\([\w]+)$@', $name, $matches)) {
|
||||
$name = $matches[1];
|
||||
}
|
||||
$this->name = $name;
|
||||
}
|
||||
|
||||
$this->checkControllerAccess();
|
||||
}
|
||||
|
||||
protected function checkControllerAccess()
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
protected function getContainer()
|
||||
{
|
||||
return $this->container;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get request method name (Uppercase)
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getRequestMethod()
|
||||
{
|
||||
return $this->requestMethod;
|
||||
}
|
||||
|
||||
protected function setRequestMethod($requestMethod)
|
||||
{
|
||||
$this->requestMethod = strtoupper($requestMethod);
|
||||
}
|
||||
|
||||
protected function getUser()
|
||||
{
|
||||
return $this->container->get('user');
|
||||
}
|
||||
|
||||
protected function getAcl()
|
||||
{
|
||||
return $this->container->get('acl');
|
||||
}
|
||||
|
||||
protected function getAclManager()
|
||||
{
|
||||
return $this->container->get('aclManager');
|
||||
}
|
||||
|
||||
protected function getConfig()
|
||||
{
|
||||
return $this->container->get('config');
|
||||
}
|
||||
|
||||
protected function getPreferences()
|
||||
{
|
||||
return $this->container->get('preferences');
|
||||
}
|
||||
|
||||
protected function getMetadata()
|
||||
{
|
||||
return $this->container->get('metadata');
|
||||
}
|
||||
|
||||
protected function getServiceFactory()
|
||||
{
|
||||
return $this->container->get('serviceFactory');
|
||||
}
|
||||
|
||||
protected function getService($name)
|
||||
{
|
||||
return $this->getServiceFactory()->create($name);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM - Open Source CRM application.
|
||||
* Copyright (C) 2014 Yuri Kuznetsov, Taras Machyshyn, Oleksiy Avramenko
|
||||
* 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
|
||||
@@ -18,288 +18,382 @@
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with EspoCRM. If not, see http://www.gnu.org/licenses/.
|
||||
************************************************************************/
|
||||
************************************************************************/
|
||||
|
||||
namespace Espo\Core\Controllers;
|
||||
|
||||
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
|
||||
{
|
||||
const MAX_SIZE_LIMIT = 200;
|
||||
|
||||
public static $defaultAction = 'list';
|
||||
|
||||
protected function getEntityManager()
|
||||
{
|
||||
return $this->getContainer()->get('entityManager');
|
||||
}
|
||||
|
||||
protected function getRecordService($name = null)
|
||||
{
|
||||
if (empty($name)) {
|
||||
$name = $this->name;
|
||||
}
|
||||
|
||||
if ($this->getServiceFactory()->checkExists($name)) {
|
||||
$service = $this->getServiceFactory()->create($name);
|
||||
} else {
|
||||
$service = $this->getServiceFactory()->create('Record');
|
||||
$service->setEntityName($name);
|
||||
}
|
||||
|
||||
return $service;
|
||||
}
|
||||
const MAX_SIZE_LIMIT = 200;
|
||||
|
||||
public function actionRead($params)
|
||||
{
|
||||
$id = $params['id'];
|
||||
$entity = $this->getRecordService()->getEntity($id);
|
||||
|
||||
if (empty($entity)) {
|
||||
throw new NotFound();
|
||||
}
|
||||
public static $defaultAction = 'list';
|
||||
|
||||
return $entity->toArray();
|
||||
}
|
||||
|
||||
public function actionPatch($params, $data)
|
||||
{
|
||||
return $this->actionUpdate($params, $data);
|
||||
}
|
||||
|
||||
public function actionCreate($params, $data)
|
||||
{
|
||||
if (!$this->getAcl()->check($this->name, 'edit')) {
|
||||
throw new Forbidden();
|
||||
}
|
||||
protected $defaultRecordServiceName = 'Record';
|
||||
|
||||
$service = $this->getRecordService();
|
||||
|
||||
if ($entity = $service->createEntity($data)) {
|
||||
return $entity->toArray();
|
||||
}
|
||||
protected function getEntityManager()
|
||||
{
|
||||
return $this->getContainer()->get('entityManager');
|
||||
}
|
||||
|
||||
throw new Error();
|
||||
}
|
||||
protected function getRecordService($name = null)
|
||||
{
|
||||
if (empty($name)) {
|
||||
$name = $this->name;
|
||||
}
|
||||
|
||||
public function actionUpdate($params, $data)
|
||||
{
|
||||
if (!$this->getAcl()->check($this->name, 'edit')) {
|
||||
throw new Forbidden();
|
||||
}
|
||||
|
||||
$id = $params['id'];
|
||||
|
||||
if ($entity = $this->getRecordService()->updateEntity($id, $data)) {
|
||||
return $entity->toArray();
|
||||
}
|
||||
if ($this->getServiceFactory()->checkExists($name)) {
|
||||
$service = $this->getServiceFactory()->create($name);
|
||||
} else {
|
||||
$service = $this->getServiceFactory()->create($this->defaultRecordServiceName);
|
||||
$service->setEntityType($name);
|
||||
}
|
||||
|
||||
throw new Error();
|
||||
}
|
||||
return $service;
|
||||
}
|
||||
|
||||
public function actionList($params, $data, $request)
|
||||
{
|
||||
if (!$this->getAcl()->check($this->name, 'read')) {
|
||||
throw new Forbidden();
|
||||
}
|
||||
public function actionRead($params)
|
||||
{
|
||||
$id = $params['id'];
|
||||
$entity = $this->getRecordService()->getEntity($id);
|
||||
|
||||
$where = $request->get('where');
|
||||
$offset = $request->get('offset');
|
||||
$maxSize = $request->get('maxSize');
|
||||
$asc = $request->get('asc') === 'true';
|
||||
$sortBy = $request->get('sortBy');
|
||||
$q = $request->get('q');
|
||||
|
||||
if (empty($maxSize)) {
|
||||
$maxSize = self::MAX_SIZE_LIMIT;
|
||||
}
|
||||
if (!empty($maxSize) && $maxSize > self::MAX_SIZE_LIMIT) {
|
||||
throw new Forbidden();
|
||||
}
|
||||
if (empty($entity)) {
|
||||
throw new NotFound();
|
||||
}
|
||||
|
||||
$result = $this->getRecordService()->findEntities(array(
|
||||
'where' => $where,
|
||||
'offset' => $offset,
|
||||
'maxSize' => $maxSize,
|
||||
'asc' => $asc,
|
||||
'sortBy' => $sortBy,
|
||||
'q' => $q,
|
||||
));
|
||||
|
||||
return array(
|
||||
'total' => $result['total'],
|
||||
'list' => $result['collection']->toArray()
|
||||
);
|
||||
}
|
||||
|
||||
public function actionListLinked($params, $data, $request)
|
||||
{
|
||||
$id = $params['id'];
|
||||
$link = $params['link'];
|
||||
return $entity->toArray();
|
||||
}
|
||||
|
||||
$where = $request->get('where');
|
||||
$offset = $request->get('offset');
|
||||
$maxSize = $request->get('maxSize');
|
||||
$asc = $request->get('asc') === 'true';
|
||||
$sortBy = $request->get('sortBy');
|
||||
$q = $request->get('q');
|
||||
|
||||
if (empty($maxSize)) {
|
||||
$maxSize = self::MAX_SIZE_LIMIT;
|
||||
}
|
||||
if (!empty($maxSize) && $maxSize > self::MAX_SIZE_LIMIT) {
|
||||
throw new Forbidden();
|
||||
}
|
||||
public function actionPatch($params, $data, $request)
|
||||
{
|
||||
return $this->actionUpdate($params, $data, $request);
|
||||
}
|
||||
|
||||
$result = $this->getRecordService()->findLinkedEntities($id, $link, array(
|
||||
'where' => $where,
|
||||
'offset' => $offset,
|
||||
'maxSize' => $maxSize,
|
||||
'asc' => $asc,
|
||||
'sortBy' => $sortBy,
|
||||
'q' => $q,
|
||||
));
|
||||
|
||||
|
||||
return array(
|
||||
'total' => $result['total'],
|
||||
'list' => $result['collection']->toArray()
|
||||
);
|
||||
}
|
||||
public function actionCreate($params, $data, $request)
|
||||
{
|
||||
if (!$request->isPost()) {
|
||||
throw BadRequest();
|
||||
}
|
||||
|
||||
public function actionDelete($params)
|
||||
{
|
||||
$id = $params['id'];
|
||||
if (!$this->getAcl()->check($this->name, 'edit')) {
|
||||
throw new Forbidden();
|
||||
}
|
||||
|
||||
if ($this->getRecordService()->deleteEntity($id)) {
|
||||
return true;
|
||||
}
|
||||
throw new Error();
|
||||
}
|
||||
|
||||
public function actionExport($params, $data, $request)
|
||||
{
|
||||
if ($this->getConfig()->get('disableExport') && !$this->getUser()->isAdmin()) {
|
||||
throw new Forbidden();
|
||||
}
|
||||
|
||||
if (!$this->getAcl()->check($this->name, 'read')) {
|
||||
throw new Forbidden();
|
||||
}
|
||||
|
||||
$ids = $request->get('ids');
|
||||
$where = $request->get('where');
|
||||
|
||||
return array(
|
||||
'id' => $this->getRecordService()->export($ids, $where)
|
||||
);
|
||||
}
|
||||
$service = $this->getRecordService();
|
||||
|
||||
public function actionMassUpdate($params, $data)
|
||||
{
|
||||
if (!$this->getAcl()->check($this->name, 'edit')) {
|
||||
throw new Forbidden();
|
||||
}
|
||||
if ($entity = $service->createEntity($data)) {
|
||||
return $entity->toArray();
|
||||
}
|
||||
|
||||
$ids = $data['ids'];
|
||||
$where = $data['where'];
|
||||
$attributes = $data['attributes'];
|
||||
throw new Error();
|
||||
}
|
||||
|
||||
$idsUpdated = $this->getRecordService()->massUpdate($attributes, $ids, $where);
|
||||
public function actionUpdate($params, $data, $request)
|
||||
{
|
||||
if (!$request->isPut() && !$request->isPatch()) {
|
||||
throw BadRequest();
|
||||
}
|
||||
|
||||
return $idsUpdated;
|
||||
}
|
||||
if (!$this->getAcl()->check($this->name, 'edit')) {
|
||||
throw new Forbidden();
|
||||
}
|
||||
|
||||
public function actionMassDelete($params, $data)
|
||||
{
|
||||
if (!$this->getAcl()->check($this->name, 'delete')) {
|
||||
throw new Forbidden();
|
||||
}
|
||||
$id = $params['id'];
|
||||
|
||||
$ids = $data['ids'];
|
||||
$where = $data['where'];
|
||||
if ($entity = $this->getRecordService()->updateEntity($id, $data)) {
|
||||
return $entity->toArray();
|
||||
}
|
||||
|
||||
$idsDeleted = $this->getRecordService()->massDelete($ids, $where);
|
||||
throw new Error();
|
||||
}
|
||||
|
||||
return $idsDeleted;
|
||||
}
|
||||
public function actionList($params, $data, $request)
|
||||
{
|
||||
if (!$this->getAcl()->check($this->name, 'read')) {
|
||||
throw new Forbidden();
|
||||
}
|
||||
|
||||
public function actionCreateLink($params, $data)
|
||||
{
|
||||
$id = $params['id'];
|
||||
$link = $params['link'];
|
||||
|
||||
$foreignIds = array();
|
||||
if (isset($data['id'])) {
|
||||
$foreignIds[] = $data['id'];
|
||||
}
|
||||
if (isset($data['ids']) && is_array($data['ids'])) {
|
||||
foreach ($data['ids'] as $foreignId) {
|
||||
$foreignIds[] = $foreignId;
|
||||
}
|
||||
}
|
||||
|
||||
$result = false;
|
||||
foreach ($foreignIds as $foreignId) {
|
||||
if ($this->getRecordService()->linkEntity($id, $link, $foreignId)) {
|
||||
$result = $result || true;
|
||||
}
|
||||
}
|
||||
if ($result) {
|
||||
return true;
|
||||
}
|
||||
|
||||
throw new Error();
|
||||
}
|
||||
|
||||
public function actionRemoveLink($params, $data)
|
||||
{
|
||||
$id = $params['id'];
|
||||
$link = $params['link'];
|
||||
|
||||
$foreignIds = array();
|
||||
if (isset($data['id'])) {
|
||||
$foreignIds[] = $data['id'];
|
||||
}
|
||||
if (isset($data['ids']) && is_array($data['ids'])) {
|
||||
foreach ($data['ids'] as $foreignId) {
|
||||
$foreignIds[] = $foreignId;
|
||||
}
|
||||
}
|
||||
|
||||
$result = false;
|
||||
foreach ($foreignIds as $foreignId) {
|
||||
if ($this->getRecordService()->unlinkEntity($id, $link, $foreignId)) {
|
||||
$result = $result || true;
|
||||
}
|
||||
}
|
||||
if ($result) {
|
||||
return true;
|
||||
}
|
||||
|
||||
throw new Error();
|
||||
}
|
||||
|
||||
public function actionFollow($params)
|
||||
{
|
||||
if (!$this->getAcl()->check($this->name, 'read')) {
|
||||
throw new Forbidden();
|
||||
}
|
||||
$id = $params['id'];
|
||||
return $this->getRecordService()->follow($id);
|
||||
}
|
||||
|
||||
public function actionUnfollow($params)
|
||||
{
|
||||
if (!$this->getAcl()->check($this->name, 'read')) {
|
||||
throw new Forbidden();
|
||||
}
|
||||
$id = $params['id'];
|
||||
return $this->getRecordService()->unfollow($id);
|
||||
}
|
||||
$where = $request->get('where');
|
||||
$offset = $request->get('offset');
|
||||
$maxSize = $request->get('maxSize');
|
||||
$asc = $request->get('asc') === 'true';
|
||||
$sortBy = $request->get('sortBy');
|
||||
$q = $request->get('q');
|
||||
|
||||
if (empty($maxSize)) {
|
||||
$maxSize = self::MAX_SIZE_LIMIT;
|
||||
}
|
||||
if (!empty($maxSize) && $maxSize > self::MAX_SIZE_LIMIT) {
|
||||
throw new Forbidden();
|
||||
}
|
||||
|
||||
$result = $this->getRecordService()->findEntities(array(
|
||||
'where' => $where,
|
||||
'offset' => $offset,
|
||||
'maxSize' => $maxSize,
|
||||
'asc' => $asc,
|
||||
'sortBy' => $sortBy,
|
||||
'q' => $q,
|
||||
));
|
||||
|
||||
return array(
|
||||
'total' => $result['total'],
|
||||
'list' => isset($result['collection']) ? $result['collection']->toArray() : $result['list']
|
||||
);
|
||||
}
|
||||
|
||||
public function actionListLinked($params, $data, $request)
|
||||
{
|
||||
$id = $params['id'];
|
||||
$link = $params['link'];
|
||||
|
||||
$where = $request->get('where');
|
||||
$offset = $request->get('offset');
|
||||
$maxSize = $request->get('maxSize');
|
||||
$asc = $request->get('asc') === 'true';
|
||||
$sortBy = $request->get('sortBy');
|
||||
$q = $request->get('q');
|
||||
|
||||
if (empty($maxSize)) {
|
||||
$maxSize = self::MAX_SIZE_LIMIT;
|
||||
}
|
||||
if (!empty($maxSize) && $maxSize > self::MAX_SIZE_LIMIT) {
|
||||
throw new Forbidden();
|
||||
}
|
||||
|
||||
$result = $this->getRecordService()->findLinkedEntities($id, $link, array(
|
||||
'where' => $where,
|
||||
'offset' => $offset,
|
||||
'maxSize' => $maxSize,
|
||||
'asc' => $asc,
|
||||
'sortBy' => $sortBy,
|
||||
'q' => $q,
|
||||
));
|
||||
|
||||
|
||||
return array(
|
||||
'total' => $result['total'],
|
||||
'list' => isset($result['collection']) ? $result['collection']->toArray() : $result['list']
|
||||
);
|
||||
}
|
||||
|
||||
public function actionDelete($params, $data, $request)
|
||||
{
|
||||
if (!$request->isDelete()) {
|
||||
throw BadRequest();
|
||||
}
|
||||
|
||||
$id = $params['id'];
|
||||
|
||||
if ($this->getRecordService()->deleteEntity($id)) {
|
||||
return true;
|
||||
}
|
||||
throw new Error();
|
||||
}
|
||||
|
||||
public function actionExport($params, $data, $request)
|
||||
{
|
||||
if ($this->getConfig()->get('disableExport') && !$this->getUser()->isAdmin()) {
|
||||
throw new Forbidden();
|
||||
}
|
||||
|
||||
if (!$this->getAcl()->check($this->name, 'read')) {
|
||||
throw new Forbidden();
|
||||
}
|
||||
|
||||
$ids = $request->get('ids');
|
||||
$where = $request->get('where');
|
||||
$byWhere = $request->get('byWhere');
|
||||
|
||||
$params = array();
|
||||
if ($byWhere) {
|
||||
$params['where'] = $where;
|
||||
} else {
|
||||
$params['ids'] = $ids;
|
||||
}
|
||||
|
||||
return array(
|
||||
'id' => $this->getRecordService()->export($params)
|
||||
);
|
||||
}
|
||||
|
||||
public function actionMassUpdate($params, $data, $request)
|
||||
{
|
||||
if (!$request->isPut()) {
|
||||
throw new BadRequest();
|
||||
}
|
||||
|
||||
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'];
|
||||
}
|
||||
|
||||
$attributes = $data['attributes'];
|
||||
|
||||
$idsUpdated = $this->getRecordService()->massUpdate($attributes, $params);
|
||||
|
||||
return $idsUpdated;
|
||||
}
|
||||
|
||||
public function actionMassDelete($params, $data, $request)
|
||||
{
|
||||
if (!$request->isPost()) {
|
||||
throw new BadRequest();
|
||||
}
|
||||
if (!$this->getAcl()->check($this->name, 'delete')) {
|
||||
throw new Forbidden();
|
||||
}
|
||||
|
||||
$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($params);
|
||||
|
||||
return $idsRemoved;
|
||||
}
|
||||
|
||||
public function actionCreateLink($params, $data, $request)
|
||||
{
|
||||
if (!$request->isPost()) {
|
||||
throw new BadRequest();
|
||||
}
|
||||
|
||||
if (empty($params['id']) || empty($params['link'])) {
|
||||
throw new BadRequest();
|
||||
}
|
||||
|
||||
$id = $params['id'];
|
||||
$link = $params['link'];
|
||||
|
||||
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 = true;
|
||||
}
|
||||
}
|
||||
if ($result) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
throw new Error();
|
||||
}
|
||||
|
||||
public function actionRemoveLink($params, $data, $request)
|
||||
{
|
||||
if (!$request->isDelete()) {
|
||||
throw new BadRequest();
|
||||
}
|
||||
|
||||
$id = $params['id'];
|
||||
$link = $params['link'];
|
||||
|
||||
if (empty($params['id']) || empty($params['link'])) {
|
||||
throw new BadRequest();
|
||||
}
|
||||
|
||||
$foreignIds = array();
|
||||
if (isset($data['id'])) {
|
||||
$foreignIds[] = $data['id'];
|
||||
}
|
||||
if (isset($data['ids']) && is_array($data['ids'])) {
|
||||
foreach ($data['ids'] as $foreignId) {
|
||||
$foreignIds[] = $foreignId;
|
||||
}
|
||||
}
|
||||
|
||||
$result = false;
|
||||
foreach ($foreignIds as $foreignId) {
|
||||
if ($this->getRecordService()->unlinkEntity($id, $link, $foreignId)) {
|
||||
$result = $result || true;
|
||||
}
|
||||
}
|
||||
if ($result) {
|
||||
return true;
|
||||
}
|
||||
|
||||
throw new Error();
|
||||
}
|
||||
|
||||
public function actionFollow($params, $data, $request)
|
||||
{
|
||||
if (!$request->isPut()) {
|
||||
throw new BadRequest();
|
||||
}
|
||||
if (!$this->getAcl()->check($this->name, 'read')) {
|
||||
throw new Forbidden();
|
||||
}
|
||||
$id = $params['id'];
|
||||
return $this->getRecordService()->follow($id);
|
||||
}
|
||||
|
||||
public function actionUnfollow($params, $data, $request)
|
||||
{
|
||||
if (!$request->isDelete()) {
|
||||
throw new BadRequest();
|
||||
}
|
||||
if (!$this->getAcl()->check($this->name, 'read')) {
|
||||
throw new Forbidden();
|
||||
}
|
||||
$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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
57
application/Espo/Core/Controllers/RecordTree.php
Normal file
57
application/Espo/Core/Controllers/RecordTree.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\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 RecordTree extends Record
|
||||
{
|
||||
|
||||
public static $defaultAction = 'list';
|
||||
|
||||
protected $defaultRecordServiceName = 'RecordTree';
|
||||
|
||||
public function actionListTree($params, $data, $request)
|
||||
{
|
||||
if (!$this->getAcl()->check($this->name, 'read')) {
|
||||
throw new Forbidden();
|
||||
}
|
||||
|
||||
$where = $request->get('where');
|
||||
$parentId = $request->get('parentId');
|
||||
$maxDepth = $request->get('maxDepth');
|
||||
|
||||
$collection = $this->getRecordService()->getTree($parentId, array(
|
||||
'where' => $where
|
||||
), 0, $maxDepth);
|
||||
return array(
|
||||
'list' => $collection->toArray(),
|
||||
'path' => $this->getRecordService()->getTreeItemPath($parentId)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,185 +0,0 @@
|
||||
<?php
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM - Open Source CRM application.
|
||||
* Copyright (C) 2014 Yuri Kuznetsov, Taras Machyshyn, Oleksiy Avramenko
|
||||
* Website: http://www.espocrm.com
|
||||
*
|
||||
* EspoCRM is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* EspoCRM is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with EspoCRM. If not, see http://www.gnu.org/licenses/.
|
||||
************************************************************************/
|
||||
|
||||
namespace Espo\Core\Cron;
|
||||
|
||||
use Espo\Core\Exceptions\NotFound,
|
||||
Espo\Core\Utils\Util;
|
||||
|
||||
class ScheduledJob
|
||||
{
|
||||
private $container;
|
||||
private $systemUtil;
|
||||
|
||||
protected $data = null;
|
||||
|
||||
protected $cacheFile = 'data/cache/application/jobs.php';
|
||||
|
||||
protected $cronFile = 'cron.php';
|
||||
|
||||
protected $allowedMethod = 'run';
|
||||
|
||||
/**
|
||||
* @var array - path to cron job files
|
||||
*/
|
||||
private $paths = array(
|
||||
'corePath' => 'application/Espo/Jobs',
|
||||
'modulePath' => 'application/Espo/Modules/{*}/Jobs',
|
||||
'customPath' => 'custom/Espo/Custom/Jobs',
|
||||
);
|
||||
|
||||
protected $cronSetup = array(
|
||||
'linux' => '* * * * * {PHP-BIN-DIR} -f {CRON-FILE} > /dev/null 2>&1',
|
||||
'windows' => '{PHP-BIN-DIR}.exe -f {CRON-FILE}',
|
||||
'mac' => '* * * * * {PHP-BIN-DIR} -f {CRON-FILE} > /dev/null 2>&1',
|
||||
'default' => '* * * * * {PHP-BIN-DIR} -f {CRON-FILE}',
|
||||
);
|
||||
|
||||
|
||||
public function __construct(\Espo\Core\Container $container)
|
||||
{
|
||||
$this->container = $container;
|
||||
$this->systemUtil = new \Espo\Core\Utils\System();
|
||||
}
|
||||
|
||||
protected function getContainer()
|
||||
{
|
||||
return $this->container;
|
||||
}
|
||||
|
||||
protected function getEntityManager()
|
||||
{
|
||||
return $this->container->get('entityManager');
|
||||
}
|
||||
|
||||
protected function getSystemUtil()
|
||||
{
|
||||
return $this->systemUtil;
|
||||
}
|
||||
|
||||
public function run(array $job)
|
||||
{
|
||||
$jobName = $job['method'];
|
||||
|
||||
$className = $this->getClassName($jobName);
|
||||
if ($className === false) {
|
||||
throw new NotFound();
|
||||
}
|
||||
|
||||
$jobClass = new $className($this->container);
|
||||
$method = $this->allowedMethod;
|
||||
|
||||
$jobClass->$method();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get list of all jobs
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getAll()
|
||||
{
|
||||
if (!isset($this->data)) {
|
||||
$this->init();
|
||||
}
|
||||
|
||||
return $this->data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get class name of a job by name
|
||||
*
|
||||
* @param string $name
|
||||
* @return string
|
||||
*/
|
||||
public function get($name)
|
||||
{
|
||||
return $this->getClassName($name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get list of all job names
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getAllNamesOnly()
|
||||
{
|
||||
$data = $this->getAll();
|
||||
|
||||
$namesOnly = array_keys($data);
|
||||
|
||||
return $namesOnly;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get class name of a job
|
||||
*
|
||||
* @param string $name
|
||||
* @return string
|
||||
*/
|
||||
protected function getClassName($name)
|
||||
{
|
||||
$name = Util::normilizeClassName($name);
|
||||
|
||||
$data = $this->getAll();
|
||||
|
||||
$name = ucfirst($name);
|
||||
if (isset($data[$name])) {
|
||||
return $data[$name];
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load scheduler classes. It loads from ...Jobs, ex. \Espo\Jobs
|
||||
* @return null
|
||||
*/
|
||||
protected function init()
|
||||
{
|
||||
$classParser = $this->getContainer()->get('classParser');
|
||||
$classParser->setAllowedMethods( array($this->allowedMethod) );
|
||||
$this->data = $classParser->getData($this->paths, $this->cacheFile);
|
||||
}
|
||||
|
||||
|
||||
public function getSetupMessage()
|
||||
{
|
||||
$language = $this->getContainer()->get('language');
|
||||
|
||||
$OS = $this->getSystemUtil()->getOS();
|
||||
$phpBin = $this->getSystemUtil()->getPhpBin();
|
||||
$cronFile = Util::concatPath($this->getSystemUtil()->getRootDir(), $this->cronFile);
|
||||
$desc = $language->translate('cronSetup', 'options', 'ScheduledJob');
|
||||
|
||||
$message = isset($desc[$OS]) ? $desc[$OS] : $desc['default'];
|
||||
|
||||
$command = isset($this->cronSetup[$OS]) ? $this->cronSetup[$OS] : $this->cronSetup['default'];
|
||||
$command = str_replace(array('{PHP-BIN-DIR}', '{CRON-FILE}'), array($phpBin, $cronFile), $command);
|
||||
|
||||
return array(
|
||||
'message' => $message,
|
||||
'command' => $command,
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,67 +0,0 @@
|
||||
<?php
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM - Open Source CRM application.
|
||||
* Copyright (C) 2014 Yuri Kuznetsov, Taras Machyshyn, Oleksiy Avramenko
|
||||
* Website: http://www.espocrm.com
|
||||
*
|
||||
* EspoCRM is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* EspoCRM is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with EspoCRM. If not, see http://www.gnu.org/licenses/.
|
||||
************************************************************************/
|
||||
|
||||
namespace Espo\Core\Cron;
|
||||
|
||||
use Espo\Core\Utils\Json,
|
||||
Espo\Core\Exceptions\NotFound;
|
||||
|
||||
class Service
|
||||
{
|
||||
private $serviceFactory;
|
||||
|
||||
public function __construct(\Espo\Core\ServiceFactory $serviceFactory)
|
||||
{
|
||||
$this->serviceFactory = $serviceFactory;
|
||||
}
|
||||
|
||||
protected function getServiceFactory()
|
||||
{
|
||||
return $this->serviceFactory;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function run($job)
|
||||
{
|
||||
$serviceName = $job['service_name'];
|
||||
|
||||
if (!$this->getServiceFactory()->checkExists($serviceName)) {
|
||||
throw new NotFound();
|
||||
}
|
||||
|
||||
$service = $this->getServiceFactory()->create($serviceName);
|
||||
$serviceMethod = $job['method'];
|
||||
|
||||
if (!method_exists($service, $serviceMethod)) {
|
||||
throw new NotFound();
|
||||
}
|
||||
|
||||
$data = $job['data'];
|
||||
if (Json::isJSON($data)) {
|
||||
$data = Json::decode($data, true);
|
||||
}
|
||||
|
||||
$service->$serviceMethod($data);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -3,7 +3,7 @@
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM - Open Source CRM application.
|
||||
* Copyright (C) 2014 Yuri Kuznetsov, Taras Machyshyn, Oleksiy Avramenko
|
||||
* 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
|
||||
@@ -22,191 +22,285 @@
|
||||
|
||||
namespace Espo\Core;
|
||||
|
||||
use \PDO;
|
||||
use Espo\Core\Utils\Json;
|
||||
use Espo\Core\Exceptions\NotFound;
|
||||
|
||||
class CronManager
|
||||
{
|
||||
private $container;
|
||||
private $config;
|
||||
private $fileManager;
|
||||
private $container;
|
||||
private $config;
|
||||
private $fileManager;
|
||||
private $entityManager;
|
||||
|
||||
private $scheduledJobCron;
|
||||
private $serviceCron;
|
||||
private $scheduledJobUtil;
|
||||
|
||||
private $jobService;
|
||||
private $scheduledJobService;
|
||||
const PENDING = 'Pending';
|
||||
const RUNNING = 'Running';
|
||||
const SUCCESS = 'Success';
|
||||
const FAILED = 'Failed';
|
||||
|
||||
protected $lastRunTime = 'data/cache/application/cronLastRunTime.php';
|
||||
protected $lastRunTime = 'data/cache/application/cronLastRunTime.php';
|
||||
|
||||
public function __construct(\Espo\Core\Container $container)
|
||||
{
|
||||
$this->container = $container;
|
||||
|
||||
public function __construct(\Espo\Core\Container $container)
|
||||
{
|
||||
$this->container = $container;
|
||||
$this->config = $this->container->get('config');
|
||||
$this->fileManager = $this->container->get('fileManager');
|
||||
$this->entityManager = $this->container->get('entityManager');
|
||||
$this->serviceFactory = $this->container->get('serviceFactory');
|
||||
|
||||
$this->config = $this->container->get('config');
|
||||
$this->fileManager = $this->container->get('fileManager');
|
||||
$this->scheduledJobUtil = $this->container->get('scheduledJob');
|
||||
$this->cronJob = new \Espo\Core\Utils\Cron\Job($this->config, $this->entityManager);
|
||||
$this->cronScheduledJob = new \Espo\Core\Utils\Cron\ScheduledJob($this->config, $this->entityManager);
|
||||
}
|
||||
|
||||
$this->scheduledJobCron = $this->container->get('scheduledJob');
|
||||
$this->serviceCron = new \Espo\Core\Cron\Service( $this->container->get('serviceFactory'));
|
||||
protected function getContainer()
|
||||
{
|
||||
return $this->container;
|
||||
}
|
||||
|
||||
$this->jobService = $this->container->get('serviceFactory')->create('job');
|
||||
$this->scheduledJobService = $this->container->get('serviceFactory')->create('scheduledJob');
|
||||
}
|
||||
protected function getConfig()
|
||||
{
|
||||
return $this->config;
|
||||
}
|
||||
|
||||
protected function getContainer()
|
||||
{
|
||||
return $this->container;
|
||||
}
|
||||
protected function getFileManager()
|
||||
{
|
||||
return $this->fileManager;
|
||||
}
|
||||
|
||||
protected function getConfig()
|
||||
{
|
||||
return $this->config;
|
||||
}
|
||||
protected function getEntityManager()
|
||||
{
|
||||
return $this->entityManager;
|
||||
}
|
||||
|
||||
protected function getFileManager()
|
||||
{
|
||||
return $this->fileManager;
|
||||
}
|
||||
protected function getServiceFactory()
|
||||
{
|
||||
return $this->serviceFactory;
|
||||
}
|
||||
|
||||
protected function getJobService()
|
||||
{
|
||||
return $this->jobService;
|
||||
}
|
||||
protected function getScheduledJobUtil()
|
||||
{
|
||||
return $this->scheduledJobUtil;
|
||||
}
|
||||
|
||||
protected function getScheduledJobService()
|
||||
{
|
||||
return $this->scheduledJobService;
|
||||
}
|
||||
protected function getCronJob()
|
||||
{
|
||||
return $this->cronJob;
|
||||
}
|
||||
|
||||
protected function getScheduledJobCron()
|
||||
{
|
||||
return $this->scheduledJobCron;
|
||||
}
|
||||
protected function getCronScheduledJob()
|
||||
{
|
||||
return $this->cronScheduledJob;
|
||||
}
|
||||
|
||||
protected function getServiceCron()
|
||||
{
|
||||
return $this->serviceCron;
|
||||
}
|
||||
protected function getLastRunTime()
|
||||
{
|
||||
$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'];
|
||||
}
|
||||
|
||||
protected function getLastRunTime()
|
||||
{
|
||||
$lastRunTime = $this->getFileManager()->getContents($this->lastRunTime);
|
||||
if (!is_int($lastRunTime)) {
|
||||
$lastRunTime = time() - (intval($this->getConfig()->get('cron.minExecutionTime')) + 60);
|
||||
}
|
||||
return $lastRunTime;
|
||||
}
|
||||
|
||||
return $lastRunTime;
|
||||
}
|
||||
protected function setLastRunTime($time)
|
||||
{
|
||||
$data = array(
|
||||
'time' => $time,
|
||||
);
|
||||
return $this->getFileManager()->putPhpContents($this->lastRunTime, $data);
|
||||
}
|
||||
|
||||
protected function setLastRunTime($time)
|
||||
{
|
||||
return $this->getFileManager()->putContentsPHP($this->lastRunTime, $time);
|
||||
}
|
||||
protected function checkLastRunTime()
|
||||
{
|
||||
$currentTime = time();
|
||||
$lastRunTime = $this->getLastRunTime();
|
||||
$minTime = $this->getConfig()->get('cron.minExecutionTime');
|
||||
|
||||
protected function checkLastRunTime()
|
||||
{
|
||||
$currentTime = time();
|
||||
$lastRunTime = $this->getLastRunTime();
|
||||
$minTime = $this->getConfig()->get('cron.minExecutionTime');
|
||||
if ($currentTime > ($lastRunTime + $minTime) ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ($currentTime > ($lastRunTime + $minTime) ) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
/**
|
||||
* Run Cron
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function run()
|
||||
{
|
||||
if (!$this->checkLastRunTime()) {
|
||||
$GLOBALS['log']->info('CronManager: Stop cron running, too frequent execution.');
|
||||
return;
|
||||
}
|
||||
|
||||
$this->setLastRunTime(time());
|
||||
|
||||
public function run()
|
||||
{
|
||||
if (!$this->checkLastRunTime()) {
|
||||
$GLOBALS['log']->info('Cron Manager: Stop cron running, too frequency execution');
|
||||
return; //stop cron running, too frequency execution
|
||||
}
|
||||
$entityManager = $this->getEntityManager();
|
||||
|
||||
$this->setLastRunTime(time());
|
||||
$cronJob = $this->getCronJob();
|
||||
$cronScheduledJob = $this->getCronScheduledJob();
|
||||
|
||||
//Check scheduled jobs and create related jobs
|
||||
$this->createJobsFromScheduledJobs();
|
||||
//Check scheduled jobs and create related jobs
|
||||
$this->createJobsFromScheduledJobs();
|
||||
|
||||
$pendingJobs = $cronJob->getPendingJobs();
|
||||
|
||||
$pendingJobs = $this->getJobService()->getPendingJobs();
|
||||
foreach ($pendingJobs as $job) {
|
||||
|
||||
foreach ($pendingJobs as $job) {
|
||||
$jobEntity = $entityManager->getEntity('Job', $job['id']);
|
||||
|
||||
$this->getJobService()->updateEntity($job['id'], array(
|
||||
'status' => 'Running',
|
||||
));
|
||||
if (!isset($jobEntity)) {
|
||||
$GLOBALS['log']->error('CronManager: empty Job entity ['.$job['id'].'].');
|
||||
continue;
|
||||
}
|
||||
|
||||
$isSuccess = true;
|
||||
$jobEntity->set('status', self::RUNNING);
|
||||
$entityManager->saveEntity($jobEntity);
|
||||
|
||||
try {
|
||||
if (!empty($job['scheduled_job_id'])) {
|
||||
$this->getScheduledJobCron()->run($job);
|
||||
} else {
|
||||
$this->getServiceCron()->run($job);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
$isSuccess = false;
|
||||
$GLOBALS['log']->error('Failed job running, job ['.$job['id'].']. Error Details: '.$e->getMessage());
|
||||
}
|
||||
$isSuccess = true;
|
||||
|
||||
$status = $isSuccess ? 'Success' : 'Failed';
|
||||
try {
|
||||
if (!empty($job['scheduled_job_id'])) {
|
||||
$this->runScheduledJob($job);
|
||||
} else {
|
||||
$this->runService($job);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
$isSuccess = false;
|
||||
$GLOBALS['log']->error('CronManager: Failed job running, job ['.$job['id'].']. Error Details: '.$e->getMessage());
|
||||
}
|
||||
|
||||
$this->getJobService()->updateEntity($job['id'], array(
|
||||
'status' => $status,
|
||||
));
|
||||
$status = $isSuccess ? self::SUCCESS : self::FAILED;
|
||||
|
||||
//set status in the schedulerJobLog
|
||||
if (!empty($job['scheduled_job_id'])) {
|
||||
$this->getScheduledJobService()->addLogRecord($job['scheduled_job_id'], $status);
|
||||
}
|
||||
}
|
||||
$jobEntity->set('status', $status);
|
||||
$entityManager->saveEntity($jobEntity);
|
||||
|
||||
}
|
||||
//set status in the schedulerJobLog
|
||||
if (!empty($job['scheduled_job_id'])) {
|
||||
$cronScheduledJob->addLogRecord($job['scheduled_job_id'], $status);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check scheduled jobs and create related jobs
|
||||
* @return array List of created Jobs
|
||||
*/
|
||||
protected function createJobsFromScheduledJobs()
|
||||
{
|
||||
$activeScheduledJobs = $this->getScheduledJobService()->getActiveJobs();
|
||||
/**
|
||||
* Run Scheduled Job
|
||||
*
|
||||
* @param array $job
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function runScheduledJob(array $job)
|
||||
{
|
||||
$jobName = $job['method'];
|
||||
|
||||
$createdJobs = array();
|
||||
foreach ($activeScheduledJobs as $scheduledJob) {
|
||||
$className = $this->getScheduledJobUtil()->get($jobName);
|
||||
if ($className === false) {
|
||||
throw new NotFound();
|
||||
}
|
||||
|
||||
$scheduling = $scheduledJob['scheduling'];
|
||||
$jobClass = new $className($this->container);
|
||||
$method = $this->getScheduledJobUtil()->getMethodName();
|
||||
if (!method_exists($jobClass, $method)) {
|
||||
throw new NotFound();
|
||||
}
|
||||
|
||||
$cronExpression = \Cron\CronExpression::factory($scheduling);
|
||||
$jobClass->$method();
|
||||
}
|
||||
|
||||
try {
|
||||
//$nextDate = $cronExpression->getNextRunDate()->format('Y-m-d H:i:s');
|
||||
$prevDate = $cronExpression->getPreviousRunDate()->format('Y-m-d H:i:s');
|
||||
} catch (\Exception $e) {
|
||||
$GLOBALS['log']->error('ScheduledJob ['.$scheduledJob['id'].']: CronExpression - Impossible CRON expression ['.$scheduling.']');
|
||||
continue;
|
||||
}
|
||||
/**
|
||||
* Run Service
|
||||
*
|
||||
* @param array $job
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function runService(array $job)
|
||||
{
|
||||
$serviceName = $job['service_name'];
|
||||
|
||||
if ($cronExpression->isDue()) {
|
||||
$prevDate = date('Y-m-d H:i:00');
|
||||
}
|
||||
if (!$this->getServiceFactory()->checkExists($serviceName)) {
|
||||
throw new NotFound();
|
||||
}
|
||||
|
||||
$existsJob = $this->getJobService()->getJobByScheduledJob($scheduledJob['id'], $prevDate);
|
||||
$service = $this->getServiceFactory()->create($serviceName);
|
||||
$serviceMethod = $job['method'];
|
||||
|
||||
if (!isset($existsJob) || empty($existsJob)) {
|
||||
//create a job
|
||||
$data = array(
|
||||
'name' => $scheduledJob['name'],
|
||||
'status' => 'Pending',
|
||||
'scheduledJobId' => $scheduledJob['id'],
|
||||
'executeTime' => $prevDate,
|
||||
'method' => $scheduledJob['job'],
|
||||
);
|
||||
$createdJobs[] = $this->getJobService()->createEntity($data);
|
||||
}
|
||||
}
|
||||
if (!method_exists($service, $serviceMethod)) {
|
||||
throw new NotFound();
|
||||
}
|
||||
|
||||
return $createdJobs;
|
||||
}
|
||||
$data = $job['data'];
|
||||
if (Json::isJSON($data)) {
|
||||
$data = Json::decode($data, true);
|
||||
}
|
||||
|
||||
$service->$serviceMethod($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check scheduled jobs and create related jobs
|
||||
*
|
||||
* @return array List of created Jobs
|
||||
*/
|
||||
protected function createJobsFromScheduledJobs()
|
||||
{
|
||||
$entityManager = $this->getEntityManager();
|
||||
|
||||
$activeScheduledJobs = $this->getCronScheduledJob()->getActiveJobs();
|
||||
|
||||
$cronJob = $this->getCronJob();
|
||||
$runningScheduledJobs = $cronJob->getActiveJobs('scheduled_job_id', self::RUNNING, PDO::FETCH_COLUMN);
|
||||
|
||||
$createdJobs = array();
|
||||
foreach ($activeScheduledJobs as $scheduledJob) {
|
||||
|
||||
if (in_array($scheduledJob['id'], $runningScheduledJobs)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$scheduling = $scheduledJob['scheduling'];
|
||||
|
||||
$cronExpression = \Cron\CronExpression::factory($scheduling);
|
||||
|
||||
try {
|
||||
$prevDate = $cronExpression->getPreviousRunDate()->format('Y-m-d H:i:s');
|
||||
} catch (\Exception $e) {
|
||||
$GLOBALS['log']->error('CronManager: ScheduledJob ['.$scheduledJob['id'].']: CronExpression - Impossible CRON expression ['.$scheduling.']');
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($cronExpression->isDue()) {
|
||||
$prevDate = date('Y-m-d H:i:s');
|
||||
}
|
||||
|
||||
$existsJob = $cronJob->getJobByScheduledJob($scheduledJob['id'], $prevDate);
|
||||
|
||||
if (!isset($existsJob) || empty($existsJob)) {
|
||||
//create a new job
|
||||
$jobEntity = $entityManager->getEntity('Job');
|
||||
$jobEntity->set(array(
|
||||
'name' => $scheduledJob['name'],
|
||||
'status' => self::PENDING,
|
||||
'scheduledJobId' => $scheduledJob['id'],
|
||||
'executeTime' => $prevDate,
|
||||
'method' => $scheduledJob['job'],
|
||||
));
|
||||
$jobEntityId = $entityManager->saveEntity($jobEntity);
|
||||
if (!empty($jobEntityId)) {
|
||||
$createdJobs[] = $jobEntityId;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $createdJobs;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM - Open Source CRM application.
|
||||
* Copyright (C) 2014 Yuri Kuznetsov, Taras Machyshyn, Oleksiy Avramenko
|
||||
* 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
|
||||
@@ -24,105 +24,106 @@ namespace Espo\Core;
|
||||
|
||||
class DataManager
|
||||
{
|
||||
private $container;
|
||||
private $container;
|
||||
|
||||
private $cachePath = 'data/cache';
|
||||
private $cachePath = 'data/cache';
|
||||
|
||||
|
||||
public function __construct(Container $container)
|
||||
{
|
||||
$this->container = $container;
|
||||
}
|
||||
public function __construct(Container $container)
|
||||
{
|
||||
$this->container = $container;
|
||||
}
|
||||
|
||||
protected function getContainer()
|
||||
{
|
||||
return $this->container;
|
||||
}
|
||||
protected function getContainer()
|
||||
{
|
||||
return $this->container;
|
||||
}
|
||||
|
||||
/**
|
||||
* Rebuild the system with metadata, database and cache clearing
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function rebuild($entityList = null)
|
||||
{
|
||||
$result = $this->clearCache();
|
||||
/**
|
||||
* Rebuild the system with metadata, database and cache clearing
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function rebuild($entityList = null)
|
||||
{
|
||||
$result = $this->clearCache();
|
||||
|
||||
$result &= $this->rebuildMetadata();
|
||||
$result &= $this->rebuildMetadata();
|
||||
|
||||
$result &= $this->rebuildDatabase($entityList);
|
||||
$result &= $this->rebuildDatabase($entityList);
|
||||
|
||||
return $result;
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear a cache
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function clearCache()
|
||||
{
|
||||
$result = $this->getContainer()->get('fileManager')->removeInDir($this->cachePath);
|
||||
/**
|
||||
* Clear a cache
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function clearCache()
|
||||
{
|
||||
$result = $this->getContainer()->get('fileManager')->removeInDir($this->cachePath);
|
||||
|
||||
if ($result === false) {
|
||||
throw new Exceptions\Error("Error while clearing cache");
|
||||
}
|
||||
if ($result != true) {
|
||||
throw new Exceptions\Error("Error while clearing cache");
|
||||
}
|
||||
|
||||
$this->updateCacheTimestamp();
|
||||
$this->updateCacheTimestamp();
|
||||
|
||||
return $result;
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Rebuild database
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function rebuildDatabase($entityList = null)
|
||||
{
|
||||
try {
|
||||
$result = $this->getContainer()->get('schema')->rebuild($entityList);
|
||||
} catch (\Exception $e) {
|
||||
$result = false;
|
||||
$GLOBALS['log']->error('Fault to rebuild database schema'.'. Details: '.$e->getMessage());
|
||||
}
|
||||
/**
|
||||
* Rebuild database
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function rebuildDatabase($entityList = null)
|
||||
{
|
||||
try {
|
||||
$result = $this->getContainer()->get('schema')->rebuild($entityList);
|
||||
} catch (\Exception $e) {
|
||||
$result = false;
|
||||
$GLOBALS['log']->error('Fault to rebuild database schema'.'. Details: '.$e->getMessage());
|
||||
}
|
||||
|
||||
if ($result === false) {
|
||||
throw new Exceptions\Error("Error while rebuilding database. See log file for details.");
|
||||
}
|
||||
if ($result != true) {
|
||||
throw new Exceptions\Error("Error while rebuilding database. See log file for details.");
|
||||
}
|
||||
|
||||
$this->updateCacheTimestamp();
|
||||
$this->updateCacheTimestamp();
|
||||
|
||||
return $result;
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Rebuild metadata
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function rebuildMetadata()
|
||||
{
|
||||
$metadata = $this->getContainer()->get('metadata');
|
||||
/**
|
||||
* Rebuild metadata
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function rebuildMetadata()
|
||||
{
|
||||
$metadata = $this->getContainer()->get('metadata');
|
||||
|
||||
$metadata->init(true);
|
||||
$metadata->init(true);
|
||||
|
||||
$ormMeta = $metadata->getOrmMetadata(true);
|
||||
$ormMeta = $metadata->getOrmMetadata(true);
|
||||
|
||||
$this->updateCacheTimestamp();
|
||||
$this->updateCacheTimestamp();
|
||||
|
||||
return empty($ormMeta) ? false : true;
|
||||
}
|
||||
return empty($ormMeta) ? false : true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update cache timestamp
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function updateCacheTimestamp()
|
||||
{
|
||||
return $this->getContainer()->get('config')->updateCacheTimestamp();
|
||||
}
|
||||
/**
|
||||
* Update cache timestamp
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function updateCacheTimestamp()
|
||||
{
|
||||
$this->getContainer()->get('config')->updateCacheTimestamp();
|
||||
$this->getContainer()->get('config')->save();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
43
application/Espo/Core/Entities/CategoryTreeItem.php
Normal file
43
application/Espo/Core/Entities/CategoryTreeItem.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<?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\Entities;
|
||||
|
||||
class CategoryTreeItem extends \Espo\Core\ORM\Entity
|
||||
{
|
||||
public function toArray()
|
||||
{
|
||||
$data = parent::toArray();
|
||||
$childList = $this->get('childList');
|
||||
if (is_null($childList)) {
|
||||
$data['childList'] = null;
|
||||
} else {
|
||||
$arr = [];
|
||||
foreach ($childList as $entity) {
|
||||
$arr[] = $entity->toArray();
|
||||
}
|
||||
$data['childList'] = $arr;
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM - Open Source CRM application.
|
||||
* Copyright (C) 2014 Yuri Kuznetsov, Taras Machyshyn, Oleksiy Avramenko
|
||||
* 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
|
||||
@@ -18,36 +18,34 @@
|
||||
*
|
||||
* 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\Entities;
|
||||
|
||||
class Person extends \Espo\Core\ORM\Entity
|
||||
{
|
||||
public static $person = true;
|
||||
|
||||
public function setLastName($value)
|
||||
{
|
||||
$this->setValue('lastName', $value);
|
||||
|
||||
$firstName = $this->get('firstName');
|
||||
if (empty($firstName)) {
|
||||
$this->setValue('name', $value);
|
||||
} else {
|
||||
$this->setValue('name', $firstName . ' ' . $value);
|
||||
}
|
||||
}
|
||||
|
||||
public function setFirstName($value)
|
||||
{
|
||||
$this->setValue('firstName', $value);
|
||||
|
||||
$lastName = $this->get('lastName');
|
||||
if (empty($lastName)) {
|
||||
$this->setValue('name', $value);
|
||||
} else {
|
||||
$this->setValue('name', $value . ' ' . $lastName);
|
||||
}
|
||||
}
|
||||
public function _setLastName($value)
|
||||
{
|
||||
$this->setValue('lastName', $value);
|
||||
|
||||
$firstName = $this->get('firstName');
|
||||
if (empty($firstName)) {
|
||||
$this->setValue('name', $value);
|
||||
} else {
|
||||
$this->setValue('name', $firstName . ' ' . $value);
|
||||
}
|
||||
}
|
||||
|
||||
public function _setFirstName($value)
|
||||
{
|
||||
$this->setValue('firstName', $value);
|
||||
|
||||
$lastName = $this->get('lastName');
|
||||
if (empty($lastName)) {
|
||||
$this->setValue('name', $value);
|
||||
} else {
|
||||
$this->setValue('name', $value . ' ' . $lastName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM - Open Source CRM application.
|
||||
* Copyright (C) 2014 Yuri Kuznetsov, Taras Machyshyn, Oleksiy Avramenko
|
||||
* 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
|
||||
@@ -23,93 +23,92 @@
|
||||
namespace Espo\Core;
|
||||
|
||||
use \Espo\Core\Exceptions\NotFound,
|
||||
\Espo\Core\Utils\Util;
|
||||
\Espo\Core\Utils\Util;
|
||||
|
||||
|
||||
class EntryPointManager
|
||||
{
|
||||
private $container;
|
||||
|
||||
private $fileManager;
|
||||
private $container;
|
||||
|
||||
protected $data = null;
|
||||
private $fileManager;
|
||||
|
||||
protected $cacheFile = 'data/cache/application/entryPoints.php';
|
||||
protected $data = null;
|
||||
|
||||
protected $allowedMethods = array(
|
||||
'run',
|
||||
);
|
||||
protected $cacheFile = 'data/cache/application/entryPoints.php';
|
||||
|
||||
/**
|
||||
protected $allowedMethods = array(
|
||||
'run',
|
||||
);
|
||||
|
||||
/**
|
||||
* @var array - path to entryPoint files
|
||||
*/
|
||||
private $paths = array(
|
||||
'corePath' => 'application/Espo/EntryPoints',
|
||||
'modulePath' => 'application/Espo/Modules/{*}/EntryPoints',
|
||||
'customPath' => 'custom/Espo/Custom/EntryPoints',
|
||||
);
|
||||
private $paths = array(
|
||||
'corePath' => 'application/Espo/EntryPoints',
|
||||
'modulePath' => 'application/Espo/Modules/{*}/EntryPoints',
|
||||
'customPath' => 'custom/Espo/Custom/EntryPoints',
|
||||
);
|
||||
|
||||
|
||||
public function __construct(\Espo\Core\Container $container)
|
||||
{
|
||||
$this->container = $container;
|
||||
$this->fileManager = $container->get('fileManager');
|
||||
}
|
||||
public function __construct(\Espo\Core\Container $container)
|
||||
{
|
||||
$this->container = $container;
|
||||
$this->fileManager = $container->get('fileManager');
|
||||
}
|
||||
|
||||
protected function getContainer()
|
||||
{
|
||||
return $this->container;
|
||||
}
|
||||
protected function getContainer()
|
||||
{
|
||||
return $this->container;
|
||||
}
|
||||
|
||||
protected function getFileManager()
|
||||
{
|
||||
return $this->fileManager;
|
||||
}
|
||||
protected function getFileManager()
|
||||
{
|
||||
return $this->fileManager;
|
||||
}
|
||||
|
||||
public function checkAuthRequired($name)
|
||||
{
|
||||
$className = $this->getClassName($name);
|
||||
if ($className === false) {
|
||||
throw new NotFound();
|
||||
}
|
||||
return $className::$authRequired;
|
||||
}
|
||||
public function checkAuthRequired($name)
|
||||
{
|
||||
$className = $this->getClassName($name);
|
||||
if (!$className) {
|
||||
throw new NotFound();
|
||||
}
|
||||
return $className::$authRequired;
|
||||
}
|
||||
|
||||
public function run($name)
|
||||
{
|
||||
$className = $this->getClassName($name);
|
||||
if ($className === false) {
|
||||
throw new NotFound();
|
||||
}
|
||||
$entryPoint = new $className($this->container);
|
||||
public function run($name)
|
||||
{
|
||||
$className = $this->getClassName($name);
|
||||
if (!$className) {
|
||||
throw new NotFound();
|
||||
}
|
||||
$entryPoint = new $className($this->container);
|
||||
|
||||
$entryPoint->run();
|
||||
}
|
||||
$entryPoint->run();
|
||||
}
|
||||
|
||||
protected function getClassName($name)
|
||||
{
|
||||
$name = Util::normilizeClassName($name);
|
||||
|
||||
if (!isset($this->data)) {
|
||||
$this->init();
|
||||
}
|
||||
protected function getClassName($name)
|
||||
{
|
||||
$name = Util::normilizeClassName($name);
|
||||
|
||||
$name = ucfirst($name);
|
||||
if (isset($this->data[$name])) {
|
||||
return $this->data[$name];
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
if (!isset($this->data)) {
|
||||
$this->init();
|
||||
}
|
||||
|
||||
$name = ucfirst($name);
|
||||
if (isset($this->data[$name])) {
|
||||
return $this->data[$name];
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
protected function init()
|
||||
{
|
||||
$classParser = $this->getContainer()->get('classParser');
|
||||
$classParser->setAllowedMethods($this->allowedMethods);
|
||||
$this->data = $classParser->getData($this->paths, $this->cacheFile);
|
||||
}
|
||||
|
||||
protected function init()
|
||||
{
|
||||
$classParser = $this->getContainer()->get('classParser');
|
||||
$classParser->setAllowedMethods($this->allowedMethods);
|
||||
$this->data = $classParser->getData($this->paths, $this->cacheFile);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM - Open Source CRM application.
|
||||
* Copyright (C) 2014 Yuri Kuznetsov, Taras Machyshyn, Oleksiy Avramenko
|
||||
* 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
|
||||
@@ -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\EntryPoints;
|
||||
|
||||
@@ -28,51 +28,51 @@ use \Espo\Core\Exceptions\Forbidden;
|
||||
|
||||
abstract class Base
|
||||
{
|
||||
private $container;
|
||||
|
||||
public static $authRequired = true;
|
||||
|
||||
protected function getContainer()
|
||||
{
|
||||
return $this->container;
|
||||
}
|
||||
|
||||
protected function getUser()
|
||||
{
|
||||
return $this->getContainer()->get('user');
|
||||
}
|
||||
|
||||
protected function getAcl()
|
||||
{
|
||||
return $this->getContainer()->get('acl');
|
||||
}
|
||||
|
||||
protected function getEntityManager()
|
||||
{
|
||||
return $this->getContainer()->get('entityManager');
|
||||
}
|
||||
|
||||
protected function getServiceFactory()
|
||||
{
|
||||
return $this->getContainer()->get('serviceFactory');
|
||||
}
|
||||
|
||||
protected function getConfig()
|
||||
{
|
||||
return $this->getContainer()->get('config');
|
||||
}
|
||||
|
||||
protected function getMetadata()
|
||||
{
|
||||
return $this->getContainer()->get('metadata');
|
||||
}
|
||||
|
||||
public function __construct(Container $container)
|
||||
{
|
||||
$this->container = $container;
|
||||
}
|
||||
|
||||
abstract public function run();
|
||||
private $container;
|
||||
|
||||
public static $authRequired = true;
|
||||
|
||||
protected function getContainer()
|
||||
{
|
||||
return $this->container;
|
||||
}
|
||||
|
||||
protected function getUser()
|
||||
{
|
||||
return $this->getContainer()->get('user');
|
||||
}
|
||||
|
||||
protected function getAcl()
|
||||
{
|
||||
return $this->getContainer()->get('acl');
|
||||
}
|
||||
|
||||
protected function getEntityManager()
|
||||
{
|
||||
return $this->getContainer()->get('entityManager');
|
||||
}
|
||||
|
||||
protected function getServiceFactory()
|
||||
{
|
||||
return $this->getContainer()->get('serviceFactory');
|
||||
}
|
||||
|
||||
protected function getConfig()
|
||||
{
|
||||
return $this->getContainer()->get('config');
|
||||
}
|
||||
|
||||
protected function getMetadata()
|
||||
{
|
||||
return $this->getContainer()->get('metadata');
|
||||
}
|
||||
|
||||
public function __construct(Container $container)
|
||||
{
|
||||
$this->container = $container;
|
||||
}
|
||||
|
||||
abstract public function run();
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM - Open Source CRM application.
|
||||
* Copyright (C) 2014 Yuri Kuznetsov, Taras Machyshyn, Oleksiy Avramenko
|
||||
* 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
|
||||
@@ -24,7 +24,7 @@ namespace Espo\Core\Exceptions;
|
||||
|
||||
class BadRequest extends \Exception
|
||||
{
|
||||
protected $code = 400;
|
||||
protected $code = 400;
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM - Open Source CRM application.
|
||||
* Copyright (C) 2014 Yuri Kuznetsov, Taras Machyshyn, Oleksiy Avramenko
|
||||
* 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
|
||||
@@ -24,7 +24,7 @@ namespace Espo\Core\Exceptions;
|
||||
|
||||
class Conflict extends \Exception
|
||||
{
|
||||
protected $code = 409;
|
||||
protected $code = 409;
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM - Open Source CRM application.
|
||||
* Copyright (C) 2014 Yuri Kuznetsov, Taras Machyshyn, Oleksiy Avramenko
|
||||
* 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
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM - Open Source CRM application.
|
||||
* Copyright (C) 2014 Yuri Kuznetsov, Taras Machyshyn, Oleksiy Avramenko
|
||||
* 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
|
||||
@@ -24,7 +24,7 @@ namespace Espo\Core\Exceptions;
|
||||
|
||||
class Forbidden extends \Exception
|
||||
{
|
||||
protected $code = 403;
|
||||
protected $code = 403;
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM - Open Source CRM application.
|
||||
* Copyright (C) 2014 Yuri Kuznetsov, Taras Machyshyn, Oleksiy Avramenko
|
||||
* 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
|
||||
@@ -24,6 +24,6 @@ namespace Espo\Core\Exceptions;
|
||||
|
||||
class InternalServerError extends \Exception
|
||||
{
|
||||
protected $code = 500;
|
||||
protected $code = 500;
|
||||
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM - Open Source CRM application.
|
||||
* Copyright (C) 2014 Yuri Kuznetsov, Taras Machyshyn, Oleksiy Avramenko
|
||||
* 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
|
||||
@@ -24,7 +24,7 @@ namespace Espo\Core\Exceptions;
|
||||
|
||||
class NotFound extends \Exception
|
||||
{
|
||||
protected $code = 404;
|
||||
protected $code = 404;
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM - Open Source CRM application.
|
||||
* Copyright (C) 2014 Yuri Kuznetsov, Taras Machyshyn, Oleksiy Avramenko
|
||||
* 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
|
||||
@@ -24,7 +24,7 @@ namespace Espo\Core\Exceptions;
|
||||
|
||||
class Unauthorized extends \Exception
|
||||
{
|
||||
protected $code = 401;
|
||||
protected $code = 401;
|
||||
|
||||
}
|
||||
|
||||
|
||||
40
application/Espo/Core/ExtensionManager.php
Normal file
40
application/Espo/Core/ExtensionManager.php
Normal file
@@ -0,0 +1,40 @@
|
||||
<?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;
|
||||
|
||||
class ExtensionManager extends Upgrades\Base
|
||||
{
|
||||
protected $name = 'Extension';
|
||||
|
||||
protected $params = array(
|
||||
'packagePath' => 'data/upload/extensions',
|
||||
'backupPath' => 'data/.backup/extensions',
|
||||
|
||||
'scriptNames' => array(
|
||||
'before' => 'BeforeInstall',
|
||||
'after' => 'AfterInstall',
|
||||
'beforeUninstall' => 'BeforeUninstall',
|
||||
'afterUninstall' => 'AfterUninstall',
|
||||
)
|
||||
);
|
||||
}
|
||||
125
application/Espo/Core/ExternalAccount/ClientManager.php
Normal file
125
application/Espo/Core/ExternalAccount/ClientManager.php
Normal file
@@ -0,0 +1,125 @@
|
||||
<?php
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM - Open Source CRM application.
|
||||
* Copyright (C) 2014-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\ExternalAccount;
|
||||
|
||||
use \Espo\Core\Exceptions\Error;
|
||||
use \Espo\Core\Exceptions\Forbidden;
|
||||
use \Espo\Core\Exceptions\NotFound;
|
||||
|
||||
class ClientManager
|
||||
{
|
||||
protected $entityManager;
|
||||
|
||||
protected $metadata;
|
||||
|
||||
protected $clientMap = array();
|
||||
|
||||
public function __construct($entityManager, $metadata, $config)
|
||||
{
|
||||
$this->entityManager = $entityManager;
|
||||
$this->metadata = $metadata;
|
||||
$this->config = $config;
|
||||
}
|
||||
|
||||
protected function getMetadata()
|
||||
{
|
||||
return $this->metadata;
|
||||
}
|
||||
|
||||
protected function getEntityManager()
|
||||
{
|
||||
return $this->entityManager;
|
||||
}
|
||||
|
||||
protected function getConfig()
|
||||
{
|
||||
return $this->config;
|
||||
}
|
||||
|
||||
public function storeAccessToken($hash, $data)
|
||||
{
|
||||
if (!empty($this->clientMap[$hash]) && !empty($this->clientMap[$hash]['externalAccountEntity'])) {
|
||||
$externalAccountEntity = $this->clientMap[$hash]['externalAccountEntity'];
|
||||
$externalAccountEntity->set('accessToken', $data['accessToken']);
|
||||
$externalAccountEntity->set('tokenType', $data['tokenType']);
|
||||
$this->getEntityManager()->saveEntity($externalAccountEntity);
|
||||
}
|
||||
}
|
||||
|
||||
public function create($integration, $userId)
|
||||
{
|
||||
$authMethod = $this->getMetadata()->get("integrations.{$integration}.authMethod");
|
||||
$methodName = 'create' . ucfirst($authMethod);
|
||||
return $this->$methodName($integration, $userId);
|
||||
}
|
||||
|
||||
protected function createOAuth2($integration, $userId)
|
||||
{
|
||||
$integrationEntity = $this->getEntityManager()->getEntity('Integration', $integration);
|
||||
$externalAccountEntity = $this->getEntityManager()->getEntity('ExternalAccount', $integration . '__' . $userId);
|
||||
|
||||
$className = $this->getMetadata()->get("integrations.{$integration}.clientClassName");
|
||||
|
||||
$redirectUri = $this->getConfig()->get('siteUrl') . '?entryPoint=oauthCallback'; // TODO move to client class
|
||||
|
||||
if (!$externalAccountEntity) {
|
||||
throw new Error("External Account {$integration} not found for {$userId}");
|
||||
}
|
||||
|
||||
if (!$integrationEntity->get('enabled')) {
|
||||
return null;
|
||||
}
|
||||
if (!$externalAccountEntity->get('enabled')) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$oauth2Client = new \Espo\Core\ExternalAccount\OAuth2\Client();
|
||||
|
||||
$client = new $className($oauth2Client, array(
|
||||
'endpoint' => $this->getMetadata()->get("integrations.{$integration}.params.endpoint"),
|
||||
'tokenEndpoint' => $this->getMetadata()->get("integrations.{$integration}.params.tokenEndpoint"),
|
||||
'clientId' => $integrationEntity->get('clientId'),
|
||||
'clientSecret' => $integrationEntity->get('clientSecret'),
|
||||
'redirectUri' => $redirectUri,
|
||||
'accessToken' => $externalAccountEntity->get('accessToken'),
|
||||
'refreshToken' => $externalAccountEntity->get('refreshToken'),
|
||||
'tokenType' => $externalAccountEntity->get('tokenType'),
|
||||
), $this);
|
||||
|
||||
$this->addToClientMap($client, $integrationEntity, $externalAccountEntity, $userId);
|
||||
|
||||
return $client;
|
||||
}
|
||||
|
||||
protected function addToClientMap($client, $integrationEntity, $externalAccountEntity, $userId)
|
||||
{
|
||||
$this->clientMap[spl_object_hash($client)] = array(
|
||||
'client' => $client,
|
||||
'userId' => $userId,
|
||||
'integration' => $integrationEntity->id,
|
||||
'integrationEntity' => $integrationEntity,
|
||||
'externalAccountEntity' => $externalAccountEntity,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
34
application/Espo/Core/ExternalAccount/Clients/Google.php
Normal file
34
application/Espo/Core/ExternalAccount/Clients/Google.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM - Open Source CRM application.
|
||||
* Copyright (C) 2014-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\ExternalAccount\Clients;
|
||||
|
||||
use \Espo\Core\Exceptions\Error;
|
||||
|
||||
class Google extends OAuth2Abstract
|
||||
{
|
||||
protected function getPingUrl()
|
||||
{
|
||||
return 'https://www.googleapis.com/calendar/v3/users/me/calendarList';
|
||||
}
|
||||
}
|
||||
|
||||
35
application/Espo/Core/ExternalAccount/Clients/IClient.php
Normal file
35
application/Espo/Core/ExternalAccount/Clients/IClient.php
Normal file
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM - Open Source CRM application.
|
||||
* Copyright (C) 2014-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\ExternalAccount\Clients;
|
||||
|
||||
interface IClient
|
||||
{
|
||||
public function getParam($name);
|
||||
|
||||
public function setParam($name, $value);
|
||||
|
||||
public function setParams(array $params);
|
||||
|
||||
public function ping();
|
||||
}
|
||||
|
||||
221
application/Espo/Core/ExternalAccount/Clients/OAuth2Abstract.php
Normal file
221
application/Espo/Core/ExternalAccount/Clients/OAuth2Abstract.php
Normal file
@@ -0,0 +1,221 @@
|
||||
<?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\ExternalAccount\Clients;
|
||||
|
||||
use \Espo\Core\Exceptions\Error;
|
||||
|
||||
use \Espo\Core\ExternalAccount\OAuth2\Client;
|
||||
|
||||
abstract class OAuth2Abstract implements IClient
|
||||
{
|
||||
protected $client = null;
|
||||
|
||||
protected $manager = null;
|
||||
|
||||
protected $paramList = array(
|
||||
'endpoint',
|
||||
'tokenEndpoint',
|
||||
'clientId',
|
||||
'clientSecret',
|
||||
'tokenType',
|
||||
'accessToken',
|
||||
'refreshToken',
|
||||
'redirectUri',
|
||||
);
|
||||
|
||||
protected $clientId = null;
|
||||
|
||||
protected $clientSecret = null;
|
||||
|
||||
protected $accessToken = null;
|
||||
|
||||
protected $refreshToken = null;
|
||||
|
||||
protected $redirectUri = null;
|
||||
|
||||
public function __construct($client, array $params = array(), $manager = null)
|
||||
{
|
||||
$this->client = $client;
|
||||
|
||||
$this->setParams($params);
|
||||
|
||||
$this->manager = $manager;
|
||||
}
|
||||
|
||||
public function getParam($name)
|
||||
{
|
||||
if (in_array($name, $this->paramList)) {
|
||||
return $this->$name;
|
||||
}
|
||||
}
|
||||
|
||||
public function setParam($name, $value)
|
||||
{
|
||||
if (in_array($name, $this->paramList)) {
|
||||
$methodName = 'set' . ucfirst($name);
|
||||
if (method_exists($this->client, $methodName)) {
|
||||
$this->client->$methodName($value);
|
||||
}
|
||||
$this->$name = $value;
|
||||
}
|
||||
}
|
||||
|
||||
public function setParams(array $params)
|
||||
{
|
||||
foreach ($this->paramList as $name) {
|
||||
if (!empty($params[$name])) {
|
||||
$this->setParam($name, $params[$name]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected function afterTokenRefreshed($data)
|
||||
{
|
||||
if ($this->manager) {
|
||||
$this->manager->storeAccessToken(spl_object_hash($this), $data);
|
||||
}
|
||||
}
|
||||
|
||||
public function getAccessTokenFromAuthorizationCode($code)
|
||||
{
|
||||
$r = $this->client->getAccessToken($this->getParam('tokenEndpoint'), Client::GRANT_TYPE_AUTHORIZATION_CODE, array(
|
||||
'code' => $code,
|
||||
'redirect_uri' => $this->getParam('redirectUri')
|
||||
));
|
||||
|
||||
if ($r['code'] == 200) {
|
||||
$data = array();
|
||||
if (!empty($r['result'])) {
|
||||
$data['accessToken'] = $r['result']['access_token'];
|
||||
$data['tokenType'] = $r['result']['token_type'];
|
||||
$data['refreshToken'] = $r['result']['refresh_token'];
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
abstract protected function getPingUrl();
|
||||
|
||||
public function ping()
|
||||
{
|
||||
if (empty($this->accessToken) || empty($this->clientId) || empty($this->clientSecret)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$url = $this->getPingUrl();
|
||||
|
||||
try {
|
||||
$this->request($url);
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public function request($url, $params = null, $httpMethod = Client::HTTP_METHOD_GET, $contentType = null, $allowRenew = true)
|
||||
{
|
||||
$httpHeaders = array();
|
||||
if (!empty($contentType)) {
|
||||
$httpHeaders['Content-Type'] = $contentType;
|
||||
switch ($contentType) {
|
||||
case Client::CONTENT_TYPE_MULTIPART_FORM_DATA:
|
||||
$httpHeaders['Content-Length'] = strlen($params);
|
||||
break;
|
||||
case Client::CONTENT_TYPE_APPLICATION_JSON:
|
||||
$httpHeaders['Content-Length'] = strlen($params);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$r = $this->client->request($url, $params, $httpMethod, $httpHeaders);
|
||||
|
||||
$code = null;
|
||||
if (!empty($r['code'])) {
|
||||
$code = $r['code'];
|
||||
}
|
||||
|
||||
if ($code >= 200 && $code < 300) {
|
||||
return $r['result'];
|
||||
} else {
|
||||
$handledData = $this->handleErrorResponse($r);
|
||||
|
||||
if ($allowRenew && is_array($handledData)) {
|
||||
if ($handledData['action'] == 'refreshToken') {
|
||||
if ($this->refreshToken()) {
|
||||
return $this->request($url, $params, $httpMethod, $contentType, false);
|
||||
}
|
||||
} else if ($handledData['action'] == 'renew') {
|
||||
return $this->request($url, $params, $httpMethod, $contentType, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
throw new Error("Error after requesting {$httpMethod} {$url}.", $code);
|
||||
}
|
||||
|
||||
protected function refreshToken()
|
||||
{
|
||||
if (!empty($this->refreshToken)) {
|
||||
$r = $this->client->getAccessToken($this->getParam('tokenEndpoint'), Client::GRANT_TYPE_REFRESH_TOKEN, array(
|
||||
'refresh_token' => $this->refreshToken,
|
||||
));
|
||||
if ($r['code'] == 200) {
|
||||
if (is_array($r['result'])) {
|
||||
if (!empty($r['result']['access_token'])) {
|
||||
$data = array();
|
||||
$data['accessToken'] = $r['result']['access_token'];
|
||||
$data['tokenType'] = $r['result']['token_type'];
|
||||
|
||||
$this->setParams($data);
|
||||
$this->afterTokenRefreshed($data);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected function handleErrorResponse($r)
|
||||
{
|
||||
if ($r['code'] == 401 && !empty($r['result'])) {
|
||||
$result = $r['result'];
|
||||
if (strpos($r['header'], 'error=invalid_token') !== false) {
|
||||
return array(
|
||||
'action' => 'refreshToken'
|
||||
);
|
||||
} else {
|
||||
return array(
|
||||
'action' => 'renew'
|
||||
);
|
||||
}
|
||||
} else if ($r['code'] == 400 && !empty($r['result'])) {
|
||||
if ($r['result']['error'] == 'invalid_token') {
|
||||
return array(
|
||||
'action' => 'refreshToken'
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
253
application/Espo/Core/ExternalAccount/OAuth2/Client.php
Normal file
253
application/Espo/Core/ExternalAccount/OAuth2/Client.php
Normal file
@@ -0,0 +1,253 @@
|
||||
<?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\ExternalAccount\OAuth2;
|
||||
|
||||
class Client
|
||||
{
|
||||
const AUTH_TYPE_URI = 0;
|
||||
const AUTH_TYPE_AUTHORIZATION_BASIC = 1;
|
||||
const AUTH_TYPE_FORM = 2;
|
||||
|
||||
const TOKEN_TYPE_URI = 'Uri';
|
||||
const TOKEN_TYPE_BEARER = 'Bearer';
|
||||
const TOKEN_TYPE_OAUTH = 'OAuth';
|
||||
|
||||
const CONTENT_TYPE_APPLICATION_X_WWW_FORM_URLENENCODED = 'application/x-www-form-urlencoded';
|
||||
const CONTENT_TYPE_MULTIPART_FORM_DATA = 'multipart/form-data';
|
||||
const CONTENT_TYPE_APPLICATION_JSON = 'application/json';
|
||||
|
||||
const HTTP_METHOD_GET = 'GET';
|
||||
const HTTP_METHOD_POST = 'POST';
|
||||
const HTTP_METHOD_PUT = 'PUT';
|
||||
|
||||
const HTTP_METHOD_DELETE = 'DELETE';
|
||||
const HTTP_METHOD_HEAD = 'HEAD';
|
||||
const HTTP_METHOD_PATCH = 'PATCH';
|
||||
|
||||
const GRANT_TYPE_AUTHORIZATION_CODE = 'authorization_code';
|
||||
const GRANT_TYPE_REFRESH_TOKEN = 'refresh_token';
|
||||
const GRANT_TYPE_PASSWORD = 'password';
|
||||
const GRANT_TYPE_CLIENT_CREDENTIALS = 'client_credentials';
|
||||
|
||||
protected $clientId = null;
|
||||
|
||||
protected $clientSecret = null;
|
||||
|
||||
protected $accessToken = null;
|
||||
|
||||
protected $authType = self::AUTH_TYPE_URI;
|
||||
|
||||
protected $tokenType = self::TOKEN_TYPE_URI;
|
||||
|
||||
protected $accessTokenSecret = null;
|
||||
|
||||
protected $accessTokenParamName = 'access_token';
|
||||
|
||||
protected $certificateFile = null;
|
||||
|
||||
protected $curlOptions = array();
|
||||
|
||||
public function __construct(array $params = array())
|
||||
{
|
||||
if (!extension_loaded('curl')) {
|
||||
throw new \Exception('CURL extension not found.');
|
||||
}
|
||||
}
|
||||
|
||||
public function setClientId($clientId)
|
||||
{
|
||||
$this->clientId = $clientId;
|
||||
}
|
||||
|
||||
public function setClientSecret($clientSecret)
|
||||
{
|
||||
$this->clientSecret = $clientSecret;
|
||||
}
|
||||
|
||||
public function setAccessToken($accessToken)
|
||||
{
|
||||
$this->accessToken = $accessToken;
|
||||
}
|
||||
|
||||
public function setAuthType($authType)
|
||||
{
|
||||
$this->authType = $authType;
|
||||
}
|
||||
|
||||
public function setCertificateFile($certificateFile)
|
||||
{
|
||||
$this->certificateFile = $certificateFile;
|
||||
}
|
||||
|
||||
public function setCurlOption($option, $value)
|
||||
{
|
||||
$this->curlOptions[$option] = $value;
|
||||
}
|
||||
|
||||
public function setCurlOptions($options)
|
||||
{
|
||||
$this->curlOptions = array_merge($this->curlOptions, $options);
|
||||
}
|
||||
|
||||
public function setTokenType($tokenType)
|
||||
{
|
||||
$this->tokenType = $tokenType;
|
||||
}
|
||||
|
||||
public function setAccessTokenSecret($accessTokenSecret)
|
||||
{
|
||||
$this->accessTokenSecret = $accessTokenSecret;
|
||||
}
|
||||
|
||||
public function request($url, $params = null, $httpMethod = self::HTTP_METHOD_GET, array $httpHeaders = array())
|
||||
{
|
||||
if ($this->accessToken) {
|
||||
switch ($this->tokenType) {
|
||||
case self::TOKEN_TYPE_URI:
|
||||
$params[$this->accessTokenParamName] = $this->accessToken;
|
||||
break;
|
||||
case self::TOKEN_TYPE_BEARER:
|
||||
$httpHeaders['Authorization'] = 'Bearer ' . $this->accessToken;
|
||||
break;
|
||||
case self::TOKEN_TYPE_OAUTH:
|
||||
$httpHeaders['Authorization'] = 'OAuth ' . $this->accessToken;
|
||||
break;
|
||||
default:
|
||||
throw new \Exception('Unknown access token type.');
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return $this->execute($url, $params, $httpMethod, $httpHeaders);
|
||||
}
|
||||
|
||||
private function execute($url, $params = null, $httpMethod, array $httpHeaders = array())
|
||||
{
|
||||
$curlOptions = array(
|
||||
CURLOPT_RETURNTRANSFER => true,
|
||||
CURLOPT_SSL_VERIFYPEER => true,
|
||||
CURLOPT_CUSTOMREQUEST => $httpMethod
|
||||
);
|
||||
|
||||
switch ($httpMethod) {
|
||||
case self::HTTP_METHOD_POST:
|
||||
$curlOptions[CURLOPT_POST] = true;
|
||||
case self::HTTP_METHOD_PUT:
|
||||
case self::HTTP_METHOD_PATCH:
|
||||
if (is_array($params)) {
|
||||
$postFields = http_build_query($params, null, '&');
|
||||
} else {
|
||||
$postFields = $params;
|
||||
}
|
||||
$curlOptions[CURLOPT_POSTFIELDS] = $postFields;
|
||||
break;
|
||||
case self::HTTP_METHOD_HEAD:
|
||||
$curlOptions[CURLOPT_NOBODY] = true;
|
||||
case self::HTTP_METHOD_DELETE:
|
||||
case self::HTTP_METHOD_GET:
|
||||
if (strpos($url, '?') === false) {
|
||||
$url .= '?';
|
||||
}
|
||||
if (is_array($params)) {
|
||||
$url .= http_build_query($params, null, '&');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
$curlOptions[CURLOPT_URL] = $url;
|
||||
|
||||
$curlOptHttpHeader = array();
|
||||
foreach ($httpHeaders as $key => $value) {
|
||||
$curlOptHttpHeader[] = "{$key}: {$value}";
|
||||
}
|
||||
$curlOptions[CURLOPT_HTTPHEADER] = $curlOptHttpHeader;
|
||||
|
||||
$ch = curl_init();
|
||||
curl_setopt_array($ch, $curlOptions);
|
||||
|
||||
curl_setopt($ch, CURLOPT_HEADER, 1);
|
||||
|
||||
if (!empty($this->certificateFile)) {
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
|
||||
curl_setopt($ch, CURLOPT_CAINFO, $this->certificateFile);
|
||||
} else {
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
|
||||
}
|
||||
|
||||
if (!empty($this->curlOptions)) {
|
||||
curl_setopt_array($ch, $this->curlOptions);
|
||||
}
|
||||
|
||||
$response = curl_exec($ch);
|
||||
|
||||
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||
$contentType = curl_getinfo($ch, CURLINFO_CONTENT_TYPE);
|
||||
$headerSize = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
|
||||
|
||||
$responceHeader = substr($response, 0, $headerSize);
|
||||
$responceBody = substr($response, $headerSize);
|
||||
|
||||
$resultArray = null;
|
||||
|
||||
if ($curlError = curl_error($ch)) {
|
||||
throw new \Exception($curlError);
|
||||
} else {
|
||||
$resultArray = json_decode($responceBody, true);
|
||||
}
|
||||
curl_close($ch);
|
||||
|
||||
return array(
|
||||
'result' => (null !== $resultArray) ? $resultArray: $responceBody,
|
||||
'code' => intval($httpCode),
|
||||
'contentType' => $contentType,
|
||||
'header' => $responceHeader,
|
||||
);
|
||||
}
|
||||
|
||||
public function getAccessToken($url, $grantType, array $params)
|
||||
{
|
||||
$params['grant_type'] = $grantType;
|
||||
|
||||
$httpHeaders = array();
|
||||
switch ($this->tokenType) {
|
||||
case self::AUTH_TYPE_URI:
|
||||
case self::AUTH_TYPE_FORM:
|
||||
$params['client_id'] = $this->clientId;
|
||||
$params['client_secret'] = $this->clientSecret;
|
||||
break;
|
||||
case self::AUTH_TYPE_AUTHORIZATION_BASIC:
|
||||
$params['client_id'] = $this->clientId;
|
||||
$httpHeaders['Authorization'] = 'Basic ' . base64_encode($this->clientId . ':' . $this->clientSecret);
|
||||
break;
|
||||
default:
|
||||
throw new \Exception();
|
||||
}
|
||||
|
||||
return $this->execute($url, $params, self::HTTP_METHOD_POST, $httpHeaders);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM - Open Source CRM application.
|
||||
* Copyright (C) 2014 Yuri Kuznetsov, Taras Machyshyn, Oleksiy Avramenko
|
||||
* 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
|
||||
@@ -23,162 +23,164 @@
|
||||
namespace Espo\Core;
|
||||
|
||||
use \Espo\Core\Exceptions\Error,
|
||||
\Espo\Core\Utils\Util;
|
||||
\Espo\Core\Utils\Util;
|
||||
|
||||
class HookManager
|
||||
{
|
||||
private $container;
|
||||
private $container;
|
||||
|
||||
private $data;
|
||||
private $data;
|
||||
|
||||
private $hooks;
|
||||
private $hooks;
|
||||
|
||||
protected $cacheFile = 'data/cache/application/hooks.php';
|
||||
protected $cacheFile = 'data/cache/application/hooks.php';
|
||||
|
||||
/**
|
||||
/**
|
||||
* List of defined hooks
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $hookList = array(
|
||||
'beforeSave',
|
||||
'afterSave',
|
||||
'beforeRemove',
|
||||
'afterRemove',
|
||||
);
|
||||
protected $hookList = array(
|
||||
'beforeSave',
|
||||
'afterSave',
|
||||
'beforeRemove',
|
||||
'afterRemove',
|
||||
);
|
||||
|
||||
protected $paths = array(
|
||||
'corePath' => 'application/Espo/Hooks',
|
||||
'modulePath' => 'application/Espo/Modules/{*}/Hooks',
|
||||
'customPath' => 'custom/Espo/Custom/Hooks',
|
||||
);
|
||||
protected $paths = array(
|
||||
'corePath' => 'application/Espo/Hooks',
|
||||
'modulePath' => 'application/Espo/Modules/{*}/Hooks',
|
||||
'customPath' => 'custom/Espo/Custom/Hooks',
|
||||
);
|
||||
|
||||
|
||||
public function __construct(Container $container)
|
||||
{
|
||||
$this->container = $container;
|
||||
$this->loadHooks();
|
||||
$this->container = $container;
|
||||
$this->loadHooks();
|
||||
}
|
||||
|
||||
protected function getConfig()
|
||||
{
|
||||
return $this->container->get('config');
|
||||
return $this->container->get('config');
|
||||
}
|
||||
|
||||
protected function getFileManager()
|
||||
{
|
||||
return $this->container->get('fileManager');
|
||||
}
|
||||
protected function getFileManager()
|
||||
{
|
||||
return $this->container->get('fileManager');
|
||||
}
|
||||
|
||||
protected function loadHooks()
|
||||
{
|
||||
if ($this->getConfig()->get('useCache') && file_exists($this->cacheFile)) {
|
||||
$this->data = $this->getFileManager()->getContents($this->cacheFile);
|
||||
return;
|
||||
}
|
||||
if ($this->getConfig()->get('useCache') && file_exists($this->cacheFile)) {
|
||||
$this->data = $this->getFileManager()->getPhpContents($this->cacheFile);
|
||||
return;
|
||||
}
|
||||
|
||||
$metadata = $this->container->get('metadata');
|
||||
$metadata = $this->container->get('metadata');
|
||||
|
||||
$this->data = $this->getHookData($this->paths['corePath']);
|
||||
$this->data = $this->getHookData($this->paths['corePath']);
|
||||
|
||||
foreach ($metadata->getModuleList() as $moduleName) {
|
||||
$modulePath = str_replace('{*}', $moduleName, $this->paths['modulePath']);
|
||||
$this->data = array_merge($this->data, $this->getHookData($modulePath));
|
||||
}
|
||||
foreach ($metadata->getModuleList() as $moduleName) {
|
||||
$modulePath = str_replace('{*}', $moduleName, $this->paths['modulePath']);
|
||||
$this->data = array_merge_recursive($this->data, $this->getHookData($modulePath));
|
||||
}
|
||||
|
||||
$this->data = array_merge($this->data, $this->getHookData($this->paths['customPath']));
|
||||
$this->data = array_merge_recursive($this->data, $this->getHookData($this->paths['customPath']));
|
||||
|
||||
if ($this->getConfig()->get('useCache')) {
|
||||
$this->getFileManager()->putContentsPHP($this->cacheFile, $this->data);
|
||||
}
|
||||
if ($this->getConfig()->get('useCache')) {
|
||||
$this->getFileManager()->putPhpContents($this->cacheFile, $this->data);
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
if ($scope != 'Common') {
|
||||
$this->process('Common', $hookName, $injection, $options);
|
||||
}
|
||||
|
||||
if (!empty($this->data[$scope])) {
|
||||
if (!empty($this->data[$scope][$hookName])) {
|
||||
foreach ($this->data[$scope][$hookName] as $className) {
|
||||
if (empty($this->hooks[$className])) {
|
||||
$this->hooks[$className] = $this->createHookByClassName($className);
|
||||
}
|
||||
$hook = $this->hooks[$className];
|
||||
$hook->$hookName($injection);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!empty($this->data[$scope])) {
|
||||
if (!empty($this->data[$scope][$hookName])) {
|
||||
foreach ($this->data[$scope][$hookName] as $className) {
|
||||
if (empty($this->hooks[$className])) {
|
||||
$this->hooks[$className] = $this->createHookByClassName($className);
|
||||
}
|
||||
$hook = $this->hooks[$className];
|
||||
$hook->$hookName($injection, $options);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function createHookByClassName($className)
|
||||
{
|
||||
if (class_exists($className)) {
|
||||
$hook = new $className();
|
||||
$dependencies = $hook->getDependencyList();
|
||||
foreach ($dependencies as $name) {
|
||||
$hook->inject($name, $this->container->get($name));
|
||||
}
|
||||
return $hook;
|
||||
}
|
||||
throw new Error("Class '$className' does not exist");
|
||||
}
|
||||
public function createHookByClassName($className)
|
||||
{
|
||||
if (class_exists($className)) {
|
||||
$hook = new $className();
|
||||
$dependencies = $hook->getDependencyList();
|
||||
foreach ($dependencies as $name) {
|
||||
$hook->inject($name, $this->container->get($name));
|
||||
}
|
||||
return $hook;
|
||||
}
|
||||
throw new Error("Class '$className' does not exist");
|
||||
}
|
||||
|
||||
/**
|
||||
* Get and merge hook data by checking the files exist in $hookDirs
|
||||
*
|
||||
* @param array $hookDirs - it can be an array('Espo/Hooks', 'Espo/Custom/Hooks', 'Espo/Modules/Crm/Hooks')
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getHookData($hookDirs)
|
||||
{
|
||||
if (is_string($hookDirs)) {
|
||||
$hookDirs = (array) $hookDirs;
|
||||
}
|
||||
*
|
||||
* @param array $hookDirs - it can be an array('Espo/Hooks', 'Espo/Custom/Hooks', 'Espo/Modules/Crm/Hooks')
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getHookData($hookDirs)
|
||||
{
|
||||
if (is_string($hookDirs)) {
|
||||
$hookDirs = (array) $hookDirs;
|
||||
}
|
||||
|
||||
$hooks = array();
|
||||
$hooks = array();
|
||||
|
||||
foreach ($hookDirs as $hookDir) {
|
||||
foreach ($hookDirs as $hookDir) {
|
||||
|
||||
if (file_exists($hookDir)) {
|
||||
$fileList = $this->getFileManager()->getFileList($hookDir, 1, '\.php$', 'file');
|
||||
if (file_exists($hookDir)) {
|
||||
$fileList = $this->getFileManager()->getFileList($hookDir, 1, '\.php$', true);
|
||||
|
||||
foreach ($fileList as $scopeName => $hookFiles) {
|
||||
foreach ($fileList as $scopeName => $hookFiles) {
|
||||
|
||||
$hookScopeDirPath = Util::concatPath($hookDir, $scopeName);
|
||||
$hookScopeDirPath = Util::concatPath($hookDir, $scopeName);
|
||||
|
||||
$scopeHooks = array();
|
||||
foreach($hookFiles as $hookFile) {
|
||||
$hookFilePath = Util::concatPath($hookScopeDirPath, $hookFile);
|
||||
$className = Util::getClassName($hookFilePath);
|
||||
$scopeHooks = array();
|
||||
foreach($hookFiles as $hookFile) {
|
||||
$hookFilePath = Util::concatPath($hookScopeDirPath, $hookFile);
|
||||
$className = Util::getClassName($hookFilePath);
|
||||
|
||||
foreach($this->hookList as $hookName) {
|
||||
if (method_exists($className, $hookName)) {
|
||||
$scopeHooks[$hookName][$className::$order][] = $className;
|
||||
}
|
||||
}
|
||||
}
|
||||
foreach($this->hookList as $hookName) {
|
||||
if (method_exists($className, $hookName)) {
|
||||
$scopeHooks[$hookName][$className::$order][] = $className;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//sort hooks by order
|
||||
foreach ($scopeHooks as $hookName => $hookList) {
|
||||
ksort($hookList);
|
||||
//sort hooks by order
|
||||
foreach ($scopeHooks as $hookName => $hookList) {
|
||||
ksort($hookList);
|
||||
|
||||
$sortedHookList = array();
|
||||
foreach($hookList as $hookDetails) {
|
||||
$sortedHookList = array_merge($sortedHookList, $hookDetails);
|
||||
}
|
||||
$sortedHookList = array();
|
||||
foreach($hookList as $hookDetails) {
|
||||
$sortedHookList = array_merge($sortedHookList, $hookDetails);
|
||||
}
|
||||
|
||||
$hooks[$scopeName][$hookName] = isset($hooks[$scopeName][$hookName]) ? array_merge($hooks[$scopeName][$hookName], $sortedHookList) : $sortedHookList;
|
||||
}
|
||||
}
|
||||
}
|
||||
$normalizedScopeName = Util::normilizeScopeName($scopeName);
|
||||
|
||||
}
|
||||
$hooks[$normalizedScopeName][$hookName] = isset($hooks[$normalizedScopeName][$hookName]) ? array_merge($hooks[$normalizedScopeName][$hookName], $sortedHookList) : $sortedHookList;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $hooks;
|
||||
}
|
||||
}
|
||||
|
||||
return $hooks;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM - Open Source CRM application.
|
||||
* Copyright (C) 2014 Yuri Kuznetsov, Taras Machyshyn, Oleksiy Avramenko
|
||||
* 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
|
||||
@@ -24,72 +24,77 @@ namespace Espo\Core\Hooks;
|
||||
|
||||
use \Espo\Core\Interfaces\Injectable;
|
||||
|
||||
class Base implements Injectable
|
||||
abstract class Base implements Injectable
|
||||
{
|
||||
protected $dependencies = array(
|
||||
'entityManager',
|
||||
'config',
|
||||
'metadata',
|
||||
'acl',
|
||||
'user',
|
||||
);
|
||||
protected $dependencies = array(
|
||||
'entityManager',
|
||||
'config',
|
||||
'metadata',
|
||||
'acl',
|
||||
'user',
|
||||
);
|
||||
|
||||
protected $injections = array();
|
||||
protected $injections = array();
|
||||
|
||||
public static $order = 9;
|
||||
public static $order = 9;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->init();
|
||||
}
|
||||
public function __construct()
|
||||
{
|
||||
$this->init();
|
||||
}
|
||||
|
||||
protected function init()
|
||||
{
|
||||
}
|
||||
protected function init()
|
||||
{
|
||||
}
|
||||
|
||||
public function getDependencyList()
|
||||
{
|
||||
return $this->dependencies;
|
||||
}
|
||||
public function getDependencyList()
|
||||
{
|
||||
return $this->dependencies;
|
||||
}
|
||||
|
||||
protected function getInjection($name)
|
||||
{
|
||||
return $this->injections[$name];
|
||||
}
|
||||
protected function addDependency($name)
|
||||
{
|
||||
$this->dependencies[] = $name;
|
||||
}
|
||||
|
||||
public function inject($name, $object)
|
||||
{
|
||||
$this->injections[$name] = $object;
|
||||
}
|
||||
protected function getInjection($name)
|
||||
{
|
||||
return $this->injections[$name];
|
||||
}
|
||||
|
||||
protected function getEntityManager()
|
||||
{
|
||||
return $this->injections['entityManager'];
|
||||
}
|
||||
public function inject($name, $object)
|
||||
{
|
||||
$this->injections[$name] = $object;
|
||||
}
|
||||
|
||||
protected function getUser()
|
||||
{
|
||||
return $this->injections['user'];
|
||||
}
|
||||
protected function getEntityManager()
|
||||
{
|
||||
return $this->injections['entityManager'];
|
||||
}
|
||||
|
||||
protected function getAcl()
|
||||
{
|
||||
return $this->injections['acl'];
|
||||
}
|
||||
protected function getUser()
|
||||
{
|
||||
return $this->injections['user'];
|
||||
}
|
||||
|
||||
protected function getConfig()
|
||||
{
|
||||
return $this->injections['config'];
|
||||
}
|
||||
protected function getAcl()
|
||||
{
|
||||
return $this->injections['acl'];
|
||||
}
|
||||
|
||||
protected function getMetadata()
|
||||
{
|
||||
return $this->injections['metadata'];
|
||||
}
|
||||
protected function getConfig()
|
||||
{
|
||||
return $this->injections['config'];
|
||||
}
|
||||
|
||||
protected function getRepository()
|
||||
{
|
||||
return $this->getEntityManager()->getRepository($this->entityName);
|
||||
}
|
||||
protected function getMetadata()
|
||||
{
|
||||
return $this->injections['metadata'];
|
||||
}
|
||||
|
||||
protected function getRepository()
|
||||
{
|
||||
return $this->getEntityManager()->getRepository($this->entityName);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM - Open Source CRM application.
|
||||
* Copyright (C) 2014 Yuri Kuznetsov, Taras Machyshyn, Oleksiy Avramenko
|
||||
* 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
|
||||
@@ -24,8 +24,8 @@ namespace Espo\Core\Interfaces;
|
||||
|
||||
interface Injectable
|
||||
{
|
||||
public function getDependencyList();
|
||||
|
||||
public function inject($name, $object);
|
||||
public function getDependencyList();
|
||||
|
||||
public function inject($name, $object);
|
||||
}
|
||||
|
||||
|
||||
29
application/Espo/Core/Interfaces/Loader.php
Normal file
29
application/Espo/Core/Interfaces/Loader.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\Interfaces;
|
||||
|
||||
interface Loader
|
||||
{
|
||||
public function load();
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM - Open Source CRM application.
|
||||
* Copyright (C) 2014 Yuri Kuznetsov, Taras Machyshyn, Oleksiy Avramenko
|
||||
* 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
|
||||
@@ -24,47 +24,46 @@ namespace Espo\Core\Jobs;
|
||||
|
||||
use \Espo\Core\Container;
|
||||
|
||||
|
||||
abstract class Base
|
||||
{
|
||||
private $container;
|
||||
private $container;
|
||||
|
||||
protected function getContainer()
|
||||
{
|
||||
return $this->container;
|
||||
}
|
||||
protected function getContainer()
|
||||
{
|
||||
return $this->container;
|
||||
}
|
||||
|
||||
protected function getEntityManager()
|
||||
{
|
||||
return $this->getContainer()->get('entityManager');
|
||||
}
|
||||
protected function getEntityManager()
|
||||
{
|
||||
return $this->getContainer()->get('entityManager');
|
||||
}
|
||||
|
||||
protected function getServiceFactory()
|
||||
{
|
||||
return $this->getContainer()->get('serviceFactory');
|
||||
}
|
||||
protected function getServiceFactory()
|
||||
{
|
||||
return $this->getContainer()->get('serviceFactory');
|
||||
}
|
||||
|
||||
protected function getConfig()
|
||||
{
|
||||
return $this->getContainer()->get('config');
|
||||
}
|
||||
protected function getConfig()
|
||||
{
|
||||
return $this->getContainer()->get('config');
|
||||
}
|
||||
|
||||
protected function getMetadata()
|
||||
{
|
||||
return $this->getContainer()->get('metadata');
|
||||
}
|
||||
protected function getMetadata()
|
||||
{
|
||||
return $this->getContainer()->get('metadata');
|
||||
}
|
||||
|
||||
protected function getUser()
|
||||
{
|
||||
return $this->getContainer()->get('user');
|
||||
}
|
||||
protected function getUser()
|
||||
{
|
||||
return $this->getContainer()->get('user');
|
||||
}
|
||||
|
||||
public function __construct(Container $container)
|
||||
{
|
||||
$this->container = $container;
|
||||
}
|
||||
public function __construct(Container $container)
|
||||
{
|
||||
$this->container = $container;
|
||||
}
|
||||
|
||||
abstract public function run();
|
||||
abstract public function run();
|
||||
|
||||
}
|
||||
|
||||
|
||||
38
application/Espo/Core/Loaders/Base.php
Normal file
38
application/Espo/Core/Loaders/Base.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?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\Loaders;
|
||||
|
||||
abstract class Base implements \Espo\Core\Interfaces\Loader
|
||||
{
|
||||
private $container;
|
||||
|
||||
public function __construct(\Espo\Core\Container $container)
|
||||
{
|
||||
$this->container = $container;
|
||||
}
|
||||
|
||||
protected function getContainer()
|
||||
{
|
||||
return $this->container;
|
||||
}
|
||||
}
|
||||
@@ -3,7 +3,7 @@
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM - Open Source CRM application.
|
||||
* Copyright (C) 2014 Yuri Kuznetsov, Taras Machyshyn, Oleksiy Avramenko
|
||||
* 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
|
||||
@@ -22,43 +22,30 @@
|
||||
|
||||
namespace Espo\Core\Loaders;
|
||||
|
||||
use Doctrine\ORM\Tools\Setup,
|
||||
Espo\Core\Doctrine\ORM\Mapping\Driver\EspoPHPDriver;
|
||||
|
||||
class EntityManager
|
||||
class EntityManager extends Base
|
||||
{
|
||||
private $container;
|
||||
public function load()
|
||||
{
|
||||
$config = $this->getContainer()->get('config');
|
||||
|
||||
public function __construct(\Espo\Core\Container $container)
|
||||
{
|
||||
$this->container = $container;
|
||||
}
|
||||
$params = array(
|
||||
'host' => $config->get('database.host'),
|
||||
'port' => $config->get('database.port'),
|
||||
'dbname' => $config->get('database.dbname'),
|
||||
'user' => $config->get('database.user'),
|
||||
'password' => $config->get('database.password'),
|
||||
'metadata' => $this->getContainer()->get('metadata')->getOrmMetadata(),
|
||||
'repositoryFactoryClassName' => '\\Espo\\Core\\ORM\\RepositoryFactory',
|
||||
'driver' => $config->get('database.driver'),
|
||||
'platform' => $config->get('database.platform')
|
||||
);
|
||||
|
||||
protected function getContainer()
|
||||
{
|
||||
return $this->container;
|
||||
}
|
||||
$entityManager = new \Espo\Core\ORM\EntityManager($params);
|
||||
$entityManager->setEspoMetadata($this->getContainer()->get('metadata'));
|
||||
$entityManager->setHookManager($this->getContainer()->get('hookManager'));
|
||||
$entityManager->setContainer($this->getContainer());
|
||||
|
||||
public function load()
|
||||
{
|
||||
$config = $this->getContainer()->get('config');
|
||||
|
||||
$params = array(
|
||||
'host' => $config->get('database.host'),
|
||||
'port' => $config->get('database.port'),
|
||||
'dbname' => $config->get('database.dbname'),
|
||||
'user' => $config->get('database.user'),
|
||||
'password' => $config->get('database.password'),
|
||||
'metadata' => $this->getContainer()->get('metadata')->getOrmMetadata(),
|
||||
'repositoryFactoryClassName' => '\\Espo\\Core\\ORM\\RepositoryFactory',
|
||||
);
|
||||
|
||||
$entityManager = new \Espo\Core\ORM\EntityManager($params);
|
||||
$entityManager->setEspoMetadata($this->getContainer()->get('metadata'));
|
||||
$entityManager->setHookManager($this->getContainer()->get('hookManager'));
|
||||
$entityManager->setContainer($this->getContainer());
|
||||
|
||||
return $entityManager;
|
||||
}
|
||||
return $entityManager;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
38
application/Espo/Core/Loaders/EntityManagerUtil.php
Normal file
38
application/Espo/Core/Loaders/EntityManagerUtil.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?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\Loaders;
|
||||
|
||||
class EntityManagerUtil extends Base
|
||||
{
|
||||
public function load()
|
||||
{
|
||||
$entityManager = new \Espo\Core\Utils\EntityManager(
|
||||
$this->getContainer()->get('metadata'),
|
||||
$this->getContainer()->get('language'),
|
||||
$this->getContainer()->get('fileManager')
|
||||
);
|
||||
|
||||
return $entityManager;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,64 +0,0 @@
|
||||
<?php
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM - Open Source CRM application.
|
||||
* Copyright (C) 2014 Yuri Kuznetsov, Taras Machyshyn, Oleksiy Avramenko
|
||||
* Website: http://www.espocrm.com
|
||||
*
|
||||
* EspoCRM is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* EspoCRM is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with EspoCRM. If not, see http://www.gnu.org/licenses/.
|
||||
************************************************************************/
|
||||
|
||||
namespace Espo\Core\Loaders;
|
||||
|
||||
use Espo\Core\Utils,
|
||||
Espo\Core\Utils\Log\Monolog\Handler;
|
||||
|
||||
class Log
|
||||
{
|
||||
private $container;
|
||||
|
||||
public function __construct(\Espo\Core\Container $container)
|
||||
{
|
||||
$this->container = $container;
|
||||
}
|
||||
|
||||
protected function getContainer()
|
||||
{
|
||||
return $this->container;
|
||||
}
|
||||
|
||||
public function load()
|
||||
{
|
||||
$logConfig = $this->getContainer()->get('config')->get('logger');
|
||||
|
||||
$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;
|
||||
}
|
||||
}
|
||||
|
||||
389
application/Espo/Core/Mail/Importer.php
Normal file
389
application/Espo/Core/Mail/Importer.php
Normal file
@@ -0,0 +1,389 @@
|
||||
<?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;
|
||||
|
||||
use \Zend\Mime\Mime as Mime;
|
||||
|
||||
use \Espo\ORM\Entity;
|
||||
|
||||
class Importer
|
||||
{
|
||||
private $entityManager;
|
||||
|
||||
private $fileManager;
|
||||
|
||||
private $config;
|
||||
|
||||
public function __construct($entityManager, $fileManager, $config)
|
||||
{
|
||||
$this->entityManager = $entityManager;
|
||||
$this->fileManager = $fileManager;
|
||||
$this->config = $config;
|
||||
}
|
||||
|
||||
protected function getEntityManager()
|
||||
{
|
||||
return $this->entityManager;
|
||||
}
|
||||
protected function getConfig()
|
||||
{
|
||||
return $this->config;
|
||||
}
|
||||
|
||||
protected function getFileManager()
|
||||
{
|
||||
return $this->fileManager;
|
||||
}
|
||||
|
||||
public function importMessage($message, $userId, $teamsIds = array())
|
||||
{
|
||||
try {
|
||||
$email = $this->getEntityManager()->getEntity('Email');
|
||||
|
||||
$subject = $message->subject;
|
||||
if ($subject !== '0' && empty($subject)) {
|
||||
$subject = '(No Subject)';
|
||||
}
|
||||
|
||||
$email->set('isHtml', false);
|
||||
$email->set('name', $subject);
|
||||
$email->set('status', 'Archived');
|
||||
$email->set('attachmentsIds', array());
|
||||
$email->set('assignedUserId', $userId);
|
||||
$email->set('teamsIds', $teamsIds);
|
||||
|
||||
$fromArr = $this->getAddressListFromMessage($message, 'from');
|
||||
if (isset($message->from)) {
|
||||
$email->set('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(';', $toArr));
|
||||
$email->set('cc', implode(';', $ccArr));
|
||||
|
||||
if (isset($message->messageId) && !empty($message->messageId)) {
|
||||
$email->set('messageId', $message->messageId);
|
||||
if (isset($message->deliveredTo)) {
|
||||
$email->set('messageIdInternal', $message->messageId . '-' . $message->deliveredTo);
|
||||
}
|
||||
}
|
||||
|
||||
if ($duplicate = $this->findDuplicate($email)) {
|
||||
$duplicate->loadLinkMultipleField('users');
|
||||
$usersIds = $duplicate->get('usersIds');
|
||||
$usersIds[] = $userId;
|
||||
$duplicate->set('usersIds', $usersIds);
|
||||
$this->getEntityManager()->saveEntity($duplicate);
|
||||
|
||||
if (!empty($teamsIds)) {
|
||||
foreach ($teamsIds as $teamId) {
|
||||
$this->getEntityManager()->getRepository('Email')->relate($duplicate, 'teams', $teamId);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
if (isset($message->date)) {
|
||||
$dt = new \DateTime($message->date);
|
||||
if ($dt) {
|
||||
$dateSent = $dt->setTimezone(new \DateTimeZone('UTC'))->format('Y-m-d H:i:s');
|
||||
$email->set('dateSent', $dateSent);
|
||||
}
|
||||
} else {
|
||||
$email->set('dateSent', date('Y-m-d H:i:s'));
|
||||
}
|
||||
if (isset($message->deliveryDate)) {
|
||||
$dt = new \DateTime($message->deliveryDate);
|
||||
if ($dt) {
|
||||
$deliveryDate = $dt->setTimezone(new \DateTimeZone('UTC'))->format('Y-m-d H:i:s');
|
||||
$email->set('deliveryDate', $deliveryDate);
|
||||
}
|
||||
}
|
||||
|
||||
$inlineIds = array();
|
||||
|
||||
if ($message->isMultipart()) {
|
||||
foreach (new \RecursiveIteratorIterator($message) as $part) {
|
||||
$this->importPartDataToEmail($email, $part, $inlineIds);
|
||||
}
|
||||
} else {
|
||||
$this->importPartDataToEmail($email, $message, $inlineIds, 'text/plain');
|
||||
}
|
||||
|
||||
$body = $email->get('body');
|
||||
if (!empty($body)) {
|
||||
foreach ($inlineIds as $cid => $attachmentId) {
|
||||
$body = str_replace('cid:' . $cid, '?entryPoint=attachment&id=' . $attachmentId, $body);
|
||||
}
|
||||
$email->set('body', $body);
|
||||
}
|
||||
|
||||
$parentFound = false;
|
||||
|
||||
if (isset($message->references) && !empty($message->references)) {
|
||||
$reference = str_replace(array('/', '@'), " ", trim($message->references, '<>'));
|
||||
$parentType = $parentId = null;
|
||||
$emailSent = PHP_INT_MAX;
|
||||
$n = sscanf($reference, '%s %s %d %d espo', $parentType, $parentId, $emailSent, $number);
|
||||
if ($n == 4 && $emailSent < time()) {
|
||||
if (!empty($parentType) && !empty($parentId)) {
|
||||
$email->set('parentType', $parentType);
|
||||
$email->set('parentId', $parentId);
|
||||
$parentFound = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!$parentFound) {
|
||||
$from = $email->get('from');
|
||||
if ($from) {
|
||||
$parentFound = $this->findParent($email, $from);
|
||||
}
|
||||
if (!$parentFound) {
|
||||
if (!empty($toArr)) {
|
||||
$parentFound = $this->findParent($email, $toArr[0]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->getEntityManager()->saveEntity($email);
|
||||
|
||||
return $email;
|
||||
|
||||
} catch (\Exception $e) {}
|
||||
}
|
||||
|
||||
protected function findParent(Entity $email, $emailAddress)
|
||||
{
|
||||
$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(
|
||||
'messageId' => $email->get('messageId')
|
||||
))->findOne();
|
||||
if ($duplicate) {
|
||||
return $duplicate;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected function getAddressListFromMessage($message, $type)
|
||||
{
|
||||
$addressList = array();
|
||||
if (isset($message->$type)) {
|
||||
|
||||
$list = $message->getHeader($type)->getAddressList();
|
||||
foreach ($list as $address) {
|
||||
$addressList[] = $address->getEmail();
|
||||
}
|
||||
}
|
||||
return $addressList;
|
||||
}
|
||||
|
||||
protected function importPartDataToEmail(\Espo\Entities\Email $email, $part, &$inlineIds = array(), $defaultContentType = null)
|
||||
{
|
||||
try {
|
||||
$type = null;
|
||||
|
||||
if ($part->getHeaders() && isset($part->contentType)) {
|
||||
$type = strtok($part->contentType, ';');
|
||||
}
|
||||
|
||||
if (empty($type)) {
|
||||
if (!empty($defaultContentType)) {
|
||||
$type = $defaultContentType;
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
$encoding = null;
|
||||
|
||||
$isAttachment = true;
|
||||
|
||||
if ($type == 'text/plain' || $type == 'text/html') {
|
||||
|
||||
$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);
|
||||
}
|
||||
}
|
||||
} else if ($type == 'text/html') {
|
||||
if ($email->get('isHtml')) {
|
||||
$isAttachment = true;
|
||||
} else {
|
||||
$email->set('body', $content);
|
||||
$email->set('isHtml', true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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';
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($part->contentTransferEncoding)) {
|
||||
$encoding = strtolower($part->getHeader('Content-Transfer-Encoding')->getTransferEncoding());
|
||||
}
|
||||
|
||||
$attachment = $this->getEntityManager()->getEntity('Attachment');
|
||||
$attachment->set('name', $fileName);
|
||||
$attachment->set('type', $type);
|
||||
|
||||
if ($disposition == 'inline') {
|
||||
$attachment->set('role', 'Inline Attachment');
|
||||
} else {
|
||||
$attachment->set('role', 'Attachment');
|
||||
}
|
||||
|
||||
if ($encoding == 'base64') {
|
||||
$content = base64_decode($content);
|
||||
}
|
||||
|
||||
$attachment->set('size', strlen($content));
|
||||
|
||||
$this->getEntityManager()->saveEntity($attachment);
|
||||
|
||||
$path = 'data/upload/' . $attachment->id;
|
||||
$this->getFileManager()->putContents($path, $content);
|
||||
|
||||
if ($disposition == 'attachment') {
|
||||
$attachmentsIds = $email->get('attachmentsIds');
|
||||
$attachmentsIds[] = $attachment->id;
|
||||
$email->set('attachmentsIds', $attachmentsIds);
|
||||
} else if ($disposition == 'inline') {
|
||||
$inlineIds[$contentId] = $attachment->id;
|
||||
}
|
||||
}
|
||||
} catch (\Exception $e) {}
|
||||
}
|
||||
|
||||
protected function getContentFromPart($part)
|
||||
{
|
||||
if ($part instanceof \Zend\Mime\Part) {
|
||||
$content = $part->getRawContent();
|
||||
if (strtolower($part->charset) != 'utf-8') {
|
||||
$content = mb_convert_encoding($content, 'UTF-8', $part->charset);
|
||||
}
|
||||
} else {
|
||||
$content = $part->getContent();
|
||||
|
||||
$encoding = null;
|
||||
|
||||
if (isset($part->contentTransferEncoding)) {
|
||||
$cteHeader = $part->getHeader('Content-Transfer-Encoding');
|
||||
$encoding = strtolower($cteHeader->getTransferEncoding());
|
||||
}
|
||||
|
||||
if ($encoding == 'base64') {
|
||||
$content = base64_decode($content);
|
||||
}
|
||||
|
||||
$charset = 'UTF-8';
|
||||
|
||||
if (isset($part->contentType)) {
|
||||
$ctHeader = $part->getHeader('Content-Type');
|
||||
$charsetParamValue = $ctHeader->getParameter('charset');
|
||||
if (!empty($charsetParamValue)) {
|
||||
$charset = strtoupper($charsetParamValue);
|
||||
}
|
||||
}
|
||||
|
||||
if (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;
|
||||
}
|
||||
}
|
||||
41
application/Espo/Core/Mail/Mail/Storage/Imap.php
Normal file
41
application/Espo/Core/Mail/Mail/Storage/Imap.php
Normal file
@@ -0,0 +1,41 @@
|
||||
<?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;
|
||||
|
||||
class Imap extends \Zend\Mail\Storage\Imap
|
||||
{
|
||||
protected $messageClass = '\\Espo\\Core\\Mail\\Mail\\Storage\\Message';
|
||||
|
||||
public function getIdsFromUID($uid)
|
||||
{
|
||||
$uid = intval($uid) + 1;
|
||||
return $this->protocol->search(array('UID ' . $uid . ':*'));
|
||||
}
|
||||
|
||||
public function getIdsFromDate($date)
|
||||
{
|
||||
return $this->protocol->search(array('SINCE "' . $date . '"'));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM - Open Source CRM application.
|
||||
* Copyright (C) 2014 Yuri Kuznetsov, Taras Machyshyn, Oleksiy Avramenko
|
||||
* 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
|
||||
@@ -36,221 +36,296 @@ use \Espo\Core\Exceptions\Error;
|
||||
|
||||
class Sender
|
||||
{
|
||||
protected $config;
|
||||
protected $config;
|
||||
|
||||
protected $transport;
|
||||
protected $transport;
|
||||
|
||||
protected $isGlobal = false;
|
||||
protected $isGlobal = false;
|
||||
|
||||
protected $params = array();
|
||||
protected $params = array();
|
||||
|
||||
public function __construct($config)
|
||||
{
|
||||
$this->config = $config;
|
||||
$this->useGlobal();
|
||||
}
|
||||
public function __construct($config)
|
||||
{
|
||||
$this->config = $config;
|
||||
$this->useGlobal();
|
||||
}
|
||||
|
||||
public function resetParams()
|
||||
{
|
||||
$this->params = array();
|
||||
return $this;
|
||||
}
|
||||
public function resetParams()
|
||||
{
|
||||
$this->params = array();
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setParams(array $params = array())
|
||||
{
|
||||
$this->params = array_merge($this->params, $params);
|
||||
return $this;
|
||||
}
|
||||
public function setParams(array $params = array())
|
||||
{
|
||||
$this->params = array_merge($this->params, $params);
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function useSmtp(array $params = array())
|
||||
{
|
||||
$this->isGlobal = false;
|
||||
$this->params = $params;
|
||||
public function useSmtp(array $params = array())
|
||||
{
|
||||
$this->isGlobal = false;
|
||||
$this->params = $params;
|
||||
|
||||
$this->transport = new SmtpTransport();
|
||||
$this->transport = new SmtpTransport();
|
||||
|
||||
$opts = array(
|
||||
'name' => 'admin',
|
||||
'host' => $params['server'],
|
||||
'port' => $params['port'],
|
||||
'connection_config' => array()
|
||||
);
|
||||
if ($params['auth']) {
|
||||
$opts['connection_class'] = 'login';
|
||||
$opts['connection_config']['username'] = $params['username'];
|
||||
$opts['connection_config']['password'] = $params['password'];
|
||||
}
|
||||
if ($params['security']) {
|
||||
$opts['connection_config']['ssl'] = strtolower($params['security']);
|
||||
}
|
||||
$opts = array(
|
||||
'name' => 'admin',
|
||||
'host' => $params['server'],
|
||||
'port' => $params['port'],
|
||||
'connection_config' => array()
|
||||
);
|
||||
if ($params['auth']) {
|
||||
$opts['connection_class'] = 'login';
|
||||
$opts['connection_config']['username'] = $params['username'];
|
||||
$opts['connection_config']['password'] = $params['password'];
|
||||
}
|
||||
if ($params['security']) {
|
||||
$opts['connection_config']['ssl'] = strtolower($params['security']);
|
||||
}
|
||||
|
||||
$options = new SmtpOptions($opts);
|
||||
$this->transport->setOptions($options);
|
||||
if (in_array('fromName', $params)) {
|
||||
$this->params['fromName'] = $params['fromName'];
|
||||
}
|
||||
if (in_array('fromAddress', $params)) {
|
||||
$this->params['fromAddress'] = $params['fromAddress'];
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
$options = new SmtpOptions($opts);
|
||||
$this->transport->setOptions($options);
|
||||
|
||||
public function useGlobal()
|
||||
{
|
||||
$this->params = array();
|
||||
if ($this->isGlobal) {
|
||||
return $this;
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
$this->transport = new SmtpTransport();
|
||||
public function useGlobal()
|
||||
{
|
||||
$this->params = array();
|
||||
if ($this->isGlobal) {
|
||||
return $this;
|
||||
}
|
||||
|
||||
$config = $this->config;
|
||||
$this->transport = new SmtpTransport();
|
||||
|
||||
$opts = array(
|
||||
'name' => 'admin',
|
||||
'host' => $config->get('smtpServer'),
|
||||
'port' => $config->get('smtpPort'),
|
||||
'connection_config' => array()
|
||||
);
|
||||
if ($config->get('smtpAuth')) {
|
||||
$opts['connection_class'] = 'login';
|
||||
$opts['connection_config']['username'] = $config->get('smtpUsername');
|
||||
$opts['connection_config']['password'] = $config->get('smtpPassword');
|
||||
}
|
||||
if ($config->get('smtpSecurity')) {
|
||||
$opts['connection_config']['ssl'] = strtolower($config->get('smtpSecurity'));
|
||||
}
|
||||
$config = $this->config;
|
||||
|
||||
$options = new SmtpOptions($opts);
|
||||
$this->transport->setOptions($options);
|
||||
$opts = array(
|
||||
'name' => 'admin',
|
||||
'host' => $config->get('smtpServer'),
|
||||
'port' => $config->get('smtpPort'),
|
||||
'connection_config' => array()
|
||||
);
|
||||
if ($config->get('smtpAuth')) {
|
||||
$opts['connection_class'] = 'login';
|
||||
$opts['connection_config']['username'] = $config->get('smtpUsername');
|
||||
$opts['connection_config']['password'] = $config->get('smtpPassword');
|
||||
}
|
||||
if ($config->get('smtpSecurity')) {
|
||||
$opts['connection_config']['ssl'] = strtolower($config->get('smtpSecurity'));
|
||||
}
|
||||
|
||||
$this->isGlobal = true;
|
||||
$options = new SmtpOptions($opts);
|
||||
$this->transport->setOptions($options);
|
||||
|
||||
return $this;
|
||||
}
|
||||
$this->isGlobal = true;
|
||||
|
||||
public function send(Email $email)
|
||||
{
|
||||
$message = new Message();
|
||||
return $this;
|
||||
}
|
||||
|
||||
$config = $this->config;
|
||||
public function send(Email $email, $params = array())
|
||||
{
|
||||
$message = new Message();
|
||||
$config = $this->config;
|
||||
$params = $this->params + $params;
|
||||
|
||||
if ($email->get('from')) {
|
||||
$fromName = null;
|
||||
if (!empty($this->params['fromName'])) {
|
||||
$fromName = $this->params['fromName'];
|
||||
} else {
|
||||
$fromName = $config->get('outboundEmailFromName');
|
||||
}
|
||||
$message->addFrom(trim($email->get('from')), $fromName);
|
||||
} else {
|
||||
if (!empty($this->params['fromAddress'])) {
|
||||
$fromAddress = $this->params['fromAddress'];
|
||||
} else {
|
||||
if (!$config->get('outboundEmailFromAddress')) {
|
||||
throw new Error('outboundEmailFromAddress is not specified in config.');
|
||||
}
|
||||
$fromAddress = $config->get('outboundEmailFromAddress');
|
||||
}
|
||||
if ($email->get('from')) {
|
||||
$fromName = null;
|
||||
if (!empty($params['fromName'])) {
|
||||
$fromName = $params['fromName'];
|
||||
} else {
|
||||
$fromName = $config->get('outboundEmailFromName');
|
||||
}
|
||||
$message->addFrom(trim($email->get('from')), $fromName);
|
||||
} else {
|
||||
if (!empty($params['fromAddress'])) {
|
||||
$fromAddress = $params['fromAddress'];
|
||||
} else {
|
||||
if (!$config->get('outboundEmailFromAddress')) {
|
||||
throw new Error('outboundEmailFromAddress is not specified in config.');
|
||||
}
|
||||
$fromAddress = $config->get('outboundEmailFromAddress');
|
||||
}
|
||||
|
||||
if (!empty($this->params['fromName'])) {
|
||||
$fromName = $this->params['fromName'];
|
||||
} else {
|
||||
$fromName = $config->get('outboundEmailFromName');
|
||||
}
|
||||
if (!empty($params['fromName'])) {
|
||||
$fromName = $params['fromName'];
|
||||
} else {
|
||||
$fromName = $config->get('outboundEmailFromName');
|
||||
}
|
||||
|
||||
$message->addFrom($fromAddress, $fromName);
|
||||
}
|
||||
$message->addFrom($fromAddress, $fromName);
|
||||
}
|
||||
|
||||
$value = $email->get('to');
|
||||
if ($value) {
|
||||
$arr = explode(';', $value);
|
||||
if (is_array($arr)) {
|
||||
foreach ($arr as $address) {
|
||||
$message->addTo(trim($address));
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!$email->get('from')) {
|
||||
$email->set('from', $fromAddress);
|
||||
}
|
||||
|
||||
$value = $email->get('cc');
|
||||
if ($value) {
|
||||
$arr = explode(';', $value);
|
||||
if (is_array($arr)) {
|
||||
foreach ($arr as $address) {
|
||||
$message->addCC(trim($address));
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!empty($params['replyToAddress'])) {
|
||||
$replyToName = null;
|
||||
if (!empty($params['replyToName'])) {
|
||||
$replyToName = $params['replyToName'];
|
||||
}
|
||||
$message->setReplyTo($params['replyToAddress'], $replyToName);
|
||||
}
|
||||
|
||||
$value = $email->get('bcc');
|
||||
if ($value) {
|
||||
$arr = explode(';', $value);
|
||||
if (is_array($arr)) {
|
||||
foreach ($arr as $address) {
|
||||
$message->addBCC(trim($address));
|
||||
}
|
||||
}
|
||||
}
|
||||
$value = $email->get('to');
|
||||
if ($value) {
|
||||
$arr = explode(';', $value);
|
||||
if (is_array($arr)) {
|
||||
foreach ($arr as $address) {
|
||||
$message->addTo(trim($address));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$message->setSubject($email->get('name'));
|
||||
$value = $email->get('cc');
|
||||
if ($value) {
|
||||
$arr = explode(';', $value);
|
||||
if (is_array($arr)) {
|
||||
foreach ($arr as $address) {
|
||||
$message->addCC(trim($address));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$body = new MimeMessage;
|
||||
$parts = array();
|
||||
|
||||
$value = $email->get('bcc');
|
||||
if ($value) {
|
||||
$arr = explode(';', $value);
|
||||
if (is_array($arr)) {
|
||||
foreach ($arr as $address) {
|
||||
$message->addBCC(trim($address));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($email->get('isHtml')) {
|
||||
$bodyPart = new MimePart($email->getBodyForSending());
|
||||
$bodyPart->type = 'text/html';
|
||||
$bodyPart->charset = 'utf-8';
|
||||
} else {
|
||||
if ($email->get('bodyPlain')) {
|
||||
$bodyPart = new MimePart($email->get('bodyPlain'));
|
||||
} else {
|
||||
$bodyPart = new MimePart($email->get('body'));
|
||||
}
|
||||
$bodyPart->type = 'text/plain';
|
||||
$bodyPart->charset = 'utf-8';
|
||||
}
|
||||
$attachmentPartList = array();
|
||||
$attachmentCollection = $email->get('attachments');
|
||||
$attachmentInlineCollection = $email->getInlineAttachments();
|
||||
|
||||
$parts[] = $bodyPart;
|
||||
if (!empty($attachmentCollection)) {
|
||||
foreach ($attachmentCollection as $a) {
|
||||
$fileName = 'data/upload/' . $a->id;
|
||||
$attachment = new MimePart(file_get_contents($fileName));
|
||||
$attachment->disposition = Mime::DISPOSITION_ATTACHMENT;
|
||||
$attachment->encoding = Mime::ENCODING_BASE64;
|
||||
$attachment->filename = $a->get('name');
|
||||
if ($a->get('type')) {
|
||||
$attachment->type = $a->get('type');
|
||||
}
|
||||
$attachmentPartList[] = $attachment;
|
||||
}
|
||||
}
|
||||
|
||||
$aCollection = $email->get('attachments');
|
||||
if (!empty($aCollection)) {
|
||||
foreach ($aCollection as $a) {
|
||||
$fileName = 'data/upload/' . $a->id;
|
||||
$attachment = new MimePart(file_get_contents($fileName));
|
||||
$attachment->disposition = Mime::DISPOSITION_ATTACHMENT;
|
||||
$attachment->encoding = Mime::ENCODING_BASE64;
|
||||
$attachment->filename = $a->get('name');
|
||||
if ($a->get('type')) {
|
||||
$attachment->type = $a->get('type');
|
||||
}
|
||||
$parts[] = $attachment;
|
||||
}
|
||||
}
|
||||
|
||||
$aCollection = $email->getInlineAttachments();
|
||||
if (!empty($aCollection)) {
|
||||
foreach ($aCollection as $a) {
|
||||
$fileName = 'data/upload/' . $a->id;
|
||||
$attachment = new MimePart(file_get_contents($fileName));
|
||||
$attachment->disposition = Mime::DISPOSITION_INLINE;
|
||||
$attachment->encoding = Mime::ENCODING_BASE64;
|
||||
$attachment->id = $a->id;
|
||||
if ($a->get('type')) {
|
||||
$attachment->type = $a->get('type');
|
||||
}
|
||||
$parts[] = $attachment;
|
||||
}
|
||||
}
|
||||
if (!empty($attachmentInlineCollection)) {
|
||||
foreach ($attachmentInlineCollection as $a) {
|
||||
$fileName = 'data/upload/' . $a->id;
|
||||
$attachment = new MimePart(file_get_contents($fileName));
|
||||
$attachment->disposition = Mime::DISPOSITION_INLINE;
|
||||
$attachment->encoding = Mime::ENCODING_BASE64;
|
||||
$attachment->id = $a->id;
|
||||
if ($a->get('type')) {
|
||||
$attachment->type = $a->get('type');
|
||||
}
|
||||
$attachmentPartList[] = $attachment;
|
||||
}
|
||||
}
|
||||
|
||||
$body->setParts($parts);
|
||||
$message->setBody($body);
|
||||
|
||||
try {
|
||||
$this->transport->send($message);
|
||||
$email->set('status', 'Sent');
|
||||
$email->set('dateSent', date("Y-m-d H:i:s"));
|
||||
} catch (\Exception $e) {
|
||||
throw new Error($e->getMessage(), 500);
|
||||
}
|
||||
$message->setSubject($email->get('name'));
|
||||
|
||||
$this->useGlobal();
|
||||
}
|
||||
$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;
|
||||
$htmlPart->type = 'text/html';
|
||||
$htmlPart->charset = 'utf-8';
|
||||
}
|
||||
|
||||
if (!empty($attachmentPartList)) {
|
||||
$messageType = 'multipart/related';
|
||||
if ($email->get('isHtml')) {
|
||||
$content = new MimeMessage();
|
||||
$content->addPart($textPart);
|
||||
$content->addPart($htmlPart);
|
||||
|
||||
$messageType = 'multipart/mixed';
|
||||
|
||||
$contentPart = new MimePart($content->generateMessage());
|
||||
$contentPart->type = "multipart/alternative;\n boundary=\"" . $content->getMime()->boundary() . '"';
|
||||
|
||||
$body->addPart($contentPart);
|
||||
} else {
|
||||
$body->addPart($textPart);
|
||||
}
|
||||
|
||||
foreach ($attachmentPartList as $attachmentPart) {
|
||||
$body->addPart($attachmentPart);
|
||||
}
|
||||
|
||||
} else {
|
||||
if ($email->get('isHtml')) {
|
||||
$body->setParts(array($textPart, $htmlPart));
|
||||
$messageType = 'multipart/alternative';
|
||||
} else {
|
||||
$body = $email->getBodyPlainForSending();
|
||||
$messageType = 'text/plain';
|
||||
}
|
||||
}
|
||||
|
||||
$message->setBody($body);
|
||||
|
||||
if ($messageType == 'text/plain') {
|
||||
if ($message->getHeaders()->has('content-type')) {
|
||||
$message->getHeaders()->removeHeader('content-type');
|
||||
}
|
||||
$message->getHeaders()->addHeaderLine('Content-Type', 'text/plain; charset=UTF-8');
|
||||
} else {
|
||||
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 {
|
||||
$rand = mt_rand(1000, 9999);
|
||||
|
||||
if ($email->get('parentType') && $email->get('parentId')) {
|
||||
$messageId = '' . $email->get('parentType') .'/' . $email->get('parentId') . '/' . time() . '/' . $rand . '@espo';
|
||||
} else {
|
||||
$messageId = '' . md5($email->get('name')) . '/' . time() . '/' . $rand . '@espo';
|
||||
}
|
||||
|
||||
$messageIdHeader = new \Zend\Mail\Header\MessageId();
|
||||
$messageIdHeader->setId($messageId);
|
||||
$message->getHeaders()->addHeader($messageIdHeader);
|
||||
|
||||
$this->transport->send($message);
|
||||
|
||||
$email->set('messageId', '<' . $messageId . '>');
|
||||
$email->set('status', 'Sent');
|
||||
$email->set('dateSent', date("Y-m-d H:i:s"));
|
||||
} catch (\Exception $e) {
|
||||
throw new Error($e->getMessage(), 500);
|
||||
}
|
||||
|
||||
$this->useGlobal();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,29 +0,0 @@
|
||||
<?php
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM - Open Source CRM application.
|
||||
* Copyright (C) 2014 Yuri Kuznetsov, Taras Machyshyn, Oleksiy Avramenko
|
||||
* Website: http://www.espocrm.com
|
||||
*
|
||||
* EspoCRM is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* EspoCRM is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with EspoCRM. If not, see http://www.gnu.org/licenses/.
|
||||
************************************************************************/
|
||||
|
||||
namespace Espo\Core\ORM\DB;
|
||||
|
||||
class MysqlMapper extends \Espo\ORM\DB\MysqlMapper
|
||||
{
|
||||
protected $returnCollection = false;
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM - Open Source CRM application.
|
||||
* Copyright (C) 2014 Yuri Kuznetsov, Taras Machyshyn, Oleksiy Avramenko
|
||||
* 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
|
||||
@@ -18,46 +18,49 @@
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with EspoCRM. If not, see http://www.gnu.org/licenses/.
|
||||
************************************************************************/
|
||||
************************************************************************/
|
||||
|
||||
namespace Espo\Core\ORM;
|
||||
|
||||
class Entity extends \Espo\ORM\Entity
|
||||
{
|
||||
public function loadLinkMultipleField($field, $columns = null)
|
||||
{
|
||||
if ($this->hasRelation($field) && $this->hasField($field . 'Ids')) {
|
||||
|
||||
$defs = array();
|
||||
if (!empty($columns)) {
|
||||
$defs['additionalColumns'] = $columns;
|
||||
}
|
||||
|
||||
$collection = $this->get($field, $defs);
|
||||
$ids = array();
|
||||
$names = new \stdClass();
|
||||
if (!empty($columns)) {
|
||||
$columnsData = new \stdClass();
|
||||
}
|
||||
|
||||
foreach ($collection as $e) {
|
||||
$id = $e->id;
|
||||
$ids[] = $id;
|
||||
$names->$id = $e->get('name');
|
||||
if (!empty($columns)) {
|
||||
$columnsData->$id = new \stdClass();
|
||||
foreach ($columns as $column => $f) {
|
||||
$columnsData->$id->$column = $e->get($f);
|
||||
}
|
||||
}
|
||||
}
|
||||
$this->set($field . 'Ids', $ids);
|
||||
$this->set($field . 'Names', $names);
|
||||
if (!empty($columns)) {
|
||||
$this->set($field . 'Columns', $columnsData);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public function loadLinkMultipleField($field, $columns = null)
|
||||
{
|
||||
if ($this->hasRelation($field) && $this->hasField($field . 'Ids')) {
|
||||
|
||||
$defs = array();
|
||||
if (!empty($columns)) {
|
||||
$defs['additionalColumns'] = $columns;
|
||||
}
|
||||
|
||||
$collection = $this->get($field, $defs);
|
||||
$ids = array();
|
||||
$names = new \stdClass();
|
||||
if (!empty($columns)) {
|
||||
$columnsData = new \stdClass();
|
||||
}
|
||||
|
||||
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)) {
|
||||
$this->set($field . 'Columns', $columnsData);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM - Open Source CRM application.
|
||||
* Copyright (C) 2014 Yuri Kuznetsov, Taras Machyshyn, Oleksiy Avramenko
|
||||
* 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
|
||||
@@ -18,7 +18,7 @@
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with EspoCRM. If not, see http://www.gnu.org/licenses/.
|
||||
************************************************************************/
|
||||
************************************************************************/
|
||||
|
||||
namespace Espo\Core\ORM;
|
||||
|
||||
@@ -26,80 +26,80 @@ use \Espo\Core\Utils\Util;
|
||||
|
||||
class EntityManager extends \Espo\ORM\EntityManager
|
||||
{
|
||||
protected $espoMetadata;
|
||||
|
||||
private $hookManager;
|
||||
|
||||
protected $user;
|
||||
|
||||
protected $container;
|
||||
|
||||
private $repositoryClassNameHash = array();
|
||||
|
||||
private $entityClassNameHash = array();
|
||||
|
||||
public function setContainer(\Espo\Core\Container $container)
|
||||
{
|
||||
$this->container = $container;
|
||||
}
|
||||
|
||||
public function getContainer()
|
||||
{
|
||||
return $this->container;
|
||||
}
|
||||
|
||||
public function setUser($user)
|
||||
{
|
||||
$this->user = $user;
|
||||
}
|
||||
|
||||
public function getUser()
|
||||
{
|
||||
return $this->user;
|
||||
}
|
||||
|
||||
public function getEspoMetadata()
|
||||
{
|
||||
return $this->espoMetadata;
|
||||
}
|
||||
protected $espoMetadata;
|
||||
|
||||
public function setEspoMetadata($espoMetadata)
|
||||
{
|
||||
$this->espoMetadata = $espoMetadata;
|
||||
}
|
||||
|
||||
public function setHookManager(\Espo\Core\HookManager $hookManager)
|
||||
{
|
||||
$this->hookManager = $hookManager;
|
||||
}
|
||||
|
||||
public function getHookManager()
|
||||
{
|
||||
return $this->hookManager;
|
||||
}
|
||||
private $hookManager;
|
||||
|
||||
public function normalizeRepositoryName($name)
|
||||
{
|
||||
if (empty($this->repositoryClassNameHash[$name])) {
|
||||
$className = '\\Espo\\Custom\\Repositories\\' . Util::normilizeClassName($name);
|
||||
if (!class_exists($className)) {
|
||||
$className = $this->espoMetadata->getRepositoryPath($name);
|
||||
}
|
||||
$this->repositoryClassNameHash[$name] = $className;
|
||||
}
|
||||
return $this->repositoryClassNameHash[$name];
|
||||
}
|
||||
|
||||
public function normalizeEntityName($name)
|
||||
{
|
||||
if (empty($this->entityClassNameHash[$name])) {
|
||||
$className = '\\Espo\\Custom\\Entities\\' . Util::normilizeClassName($name);
|
||||
if (!class_exists($className)) {
|
||||
$className = $this->espoMetadata->getEntityPath($name);
|
||||
}
|
||||
$this->entityClassNameHash[$name] = $className;
|
||||
}
|
||||
return $this->entityClassNameHash[$name];
|
||||
}
|
||||
protected $user;
|
||||
|
||||
protected $container;
|
||||
|
||||
private $repositoryClassNameHash = array();
|
||||
|
||||
private $entityClassNameHash = array();
|
||||
|
||||
public function setContainer(\Espo\Core\Container $container)
|
||||
{
|
||||
$this->container = $container;
|
||||
}
|
||||
|
||||
public function getContainer()
|
||||
{
|
||||
return $this->container;
|
||||
}
|
||||
|
||||
public function setUser($user)
|
||||
{
|
||||
$this->user = $user;
|
||||
}
|
||||
|
||||
public function getUser()
|
||||
{
|
||||
return $this->user;
|
||||
}
|
||||
|
||||
public function getEspoMetadata()
|
||||
{
|
||||
return $this->espoMetadata;
|
||||
}
|
||||
|
||||
public function setEspoMetadata($espoMetadata)
|
||||
{
|
||||
$this->espoMetadata = $espoMetadata;
|
||||
}
|
||||
|
||||
public function setHookManager(\Espo\Core\HookManager $hookManager)
|
||||
{
|
||||
$this->hookManager = $hookManager;
|
||||
}
|
||||
|
||||
public function getHookManager()
|
||||
{
|
||||
return $this->hookManager;
|
||||
}
|
||||
|
||||
public function normalizeRepositoryName($name)
|
||||
{
|
||||
if (empty($this->repositoryClassNameHash[$name])) {
|
||||
$className = '\\Espo\\Custom\\Repositories\\' . Util::normilizeClassName($name);
|
||||
if (!class_exists($className)) {
|
||||
$className = $this->espoMetadata->getRepositoryPath($name);
|
||||
}
|
||||
$this->repositoryClassNameHash[$name] = $className;
|
||||
}
|
||||
return $this->repositoryClassNameHash[$name];
|
||||
}
|
||||
|
||||
public function normalizeEntityName($name)
|
||||
{
|
||||
if (empty($this->entityClassNameHash[$name])) {
|
||||
$className = '\\Espo\\Custom\\Entities\\' . Util::normilizeClassName($name);
|
||||
if (!class_exists($className)) {
|
||||
$className = $this->espoMetadata->getEntityPath($name);
|
||||
}
|
||||
$this->entityClassNameHash[$name] = $className;
|
||||
}
|
||||
return $this->entityClassNameHash[$name];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM - Open Source CRM application.
|
||||
* Copyright (C) 2014 Yuri Kuznetsov, Taras Machyshyn, Oleksiy Avramenko
|
||||
* 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
|
||||
@@ -26,260 +26,334 @@ use \Espo\ORM\EntityManager;
|
||||
use \Espo\ORM\EntityFactory;
|
||||
use \Espo\ORM\Entity;
|
||||
use \Espo\ORM\IEntity;
|
||||
use Espo\Core\Utils\Util;
|
||||
|
||||
use \Espo\Core\Interfaces\Injectable;
|
||||
|
||||
class RDB extends \Espo\ORM\Repositories\RDB implements Injectable
|
||||
{
|
||||
public static $mapperClassName = '\\Espo\\Core\\ORM\\DB\\MysqlMapper';
|
||||
protected $dependencies = array(
|
||||
'metadata'
|
||||
);
|
||||
|
||||
protected $dependencies = array(
|
||||
'metadata'
|
||||
);
|
||||
protected $injections = array();
|
||||
|
||||
protected $injections = array();
|
||||
private $restoreData = null;
|
||||
|
||||
public function inject($name, $object)
|
||||
{
|
||||
$this->injections[$name] = $object;
|
||||
}
|
||||
public function inject($name, $object)
|
||||
{
|
||||
$this->injections[$name] = $object;
|
||||
}
|
||||
|
||||
protected function getInjection($name)
|
||||
{
|
||||
return $this->injections[$name];
|
||||
}
|
||||
protected function getInjection($name)
|
||||
{
|
||||
return $this->injections[$name];
|
||||
}
|
||||
|
||||
public function getDependencyList()
|
||||
{
|
||||
return $this->dependencies;
|
||||
}
|
||||
public function getDependencyList()
|
||||
{
|
||||
return $this->dependencies;
|
||||
}
|
||||
|
||||
protected function getMetadata()
|
||||
{
|
||||
return $this->getInjection('metadata');
|
||||
}
|
||||
protected function getMetadata()
|
||||
{
|
||||
return $this->getInjection('metadata');
|
||||
}
|
||||
|
||||
public function handleSelectParams(&$params)
|
||||
{
|
||||
$this->handleEmailAddressParams($params);
|
||||
$this->handlePhoneNumberParams($params);
|
||||
}
|
||||
public function handleSelectParams(&$params)
|
||||
{
|
||||
$this->handleEmailAddressParams($params);
|
||||
$this->handlePhoneNumberParams($params);
|
||||
$this->handleCurrencyParams($params);
|
||||
}
|
||||
|
||||
protected function handleEmailAddressParams(&$params)
|
||||
{
|
||||
$entityName = $this->entityName;
|
||||
protected function handleCurrencyParams(&$params)
|
||||
{
|
||||
$entityName = $this->entityName;
|
||||
|
||||
$defs = $this->getEntityManager()->getMetadata()->get($entityName);
|
||||
if (!empty($defs['relations']) && array_key_exists('emailAddresses', $defs['relations'])) {
|
||||
if (empty($params['leftJoins'])) {
|
||||
$params['leftJoins'] = array();
|
||||
}
|
||||
if (empty($params['whereClause'])) {
|
||||
$params['whereClause'] = array();
|
||||
}
|
||||
if (empty($params['joinConditions'])) {
|
||||
$params['joinConditions'] = array();
|
||||
}
|
||||
$params['leftJoins'][] = 'emailAddresses';
|
||||
$params['joinConditions']['emailAddresses'] = array(
|
||||
'primary' => 1
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
protected function handlePhoneNumberParams(&$params)
|
||||
{
|
||||
$entityName = $this->entityName;
|
||||
$metadata = $this->getMetadata();
|
||||
|
||||
$defs = $this->getEntityManager()->getMetadata()->get($entityName);
|
||||
if (!empty($defs['relations']) && array_key_exists('phoneNumbers', $defs['relations'])) {
|
||||
if (empty($params['leftJoins'])) {
|
||||
$params['leftJoins'] = array();
|
||||
}
|
||||
if (empty($params['whereClause'])) {
|
||||
$params['whereClause'] = array();
|
||||
}
|
||||
if (empty($params['joinConditions'])) {
|
||||
$params['joinConditions'] = array();
|
||||
}
|
||||
$params['leftJoins'][] = 'phoneNumbers';
|
||||
$params['joinConditions']['phoneNumbers'] = array(
|
||||
'primary' => 1
|
||||
);
|
||||
}
|
||||
}
|
||||
if (!$metadata) {
|
||||
return;
|
||||
}
|
||||
|
||||
protected function beforeRemove(Entity $entity)
|
||||
{
|
||||
parent::beforeRemove($entity);
|
||||
$this->getEntityManager()->getHookManager()->process($this->entityName, 'beforeRemove', $entity);
|
||||
}
|
||||
$defs = $metadata->get('entityDefs.' . $entityName);
|
||||
|
||||
protected function afterRemove(Entity $entity)
|
||||
{
|
||||
parent::afterRemove($entity);
|
||||
$this->getEntityManager()->getHookManager()->process($this->entityName, 'afterRemove', $entity);
|
||||
}
|
||||
foreach ($defs['fields'] as $field => $d) {
|
||||
if (isset($d['type']) && $d['type'] == 'currency') {
|
||||
if (!empty($d['notStorable'])) {
|
||||
continue;
|
||||
}
|
||||
if (empty($params['customJoin'])) {
|
||||
$params['customJoin'] = '';
|
||||
}
|
||||
$alias = Util::toUnderScore($field) . "_currency_alias";
|
||||
$params['customJoin'] .= "
|
||||
LEFT JOIN currency AS `{$alias}` ON {$alias}.id = ".Util::toUnderScore($entityName).".".Util::toUnderScore($field)."_currency
|
||||
";
|
||||
}
|
||||
}
|
||||
|
||||
public function remove(Entity $entity)
|
||||
{
|
||||
$this->getEntityManager()->getHookManager()->process($this->entityName, 'beforeRemove', $entity);
|
||||
}
|
||||
|
||||
$result = parent::remove($entity);
|
||||
if ($result) {
|
||||
$this->getEntityManager()->getHookManager()->process($this->entityName, 'afterRemove', $entity);
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
protected function handleEmailAddressParams(&$params)
|
||||
{
|
||||
$entityName = $this->entityName;
|
||||
|
||||
protected function beforeSave(Entity $entity)
|
||||
{
|
||||
parent::beforeSave($entity);
|
||||
$this->getEntityManager()->getHookManager()->process($this->entityName, 'beforeSave', $entity);
|
||||
}
|
||||
$defs = $this->getEntityManager()->getMetadata()->get($entityName);
|
||||
if (!empty($defs['relations']) && array_key_exists('emailAddresses', $defs['relations'])) {
|
||||
if (empty($params['leftJoins'])) {
|
||||
$params['leftJoins'] = array();
|
||||
}
|
||||
if (empty($params['whereClause'])) {
|
||||
$params['whereClause'] = array();
|
||||
}
|
||||
if (empty($params['joinConditions'])) {
|
||||
$params['joinConditions'] = array();
|
||||
}
|
||||
$params['leftJoins'][] = 'emailAddresses';
|
||||
$params['joinConditions']['emailAddresses'] = array(
|
||||
'primary' => 1
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
protected function afterSave(Entity $entity)
|
||||
{
|
||||
parent::afterSave($entity);
|
||||
$this->getEntityManager()->getHookManager()->process($this->entityName, 'afterSave', $entity);
|
||||
}
|
||||
protected function handlePhoneNumberParams(&$params)
|
||||
{
|
||||
$entityName = $this->entityName;
|
||||
|
||||
public function save(Entity $entity)
|
||||
{
|
||||
$nowString = date('Y-m-d H:i:s', time());
|
||||
$restoreData = array();
|
||||
$defs = $this->getEntityManager()->getMetadata()->get($entityName);
|
||||
if (!empty($defs['relations']) && array_key_exists('phoneNumbers', $defs['relations'])) {
|
||||
if (empty($params['leftJoins'])) {
|
||||
$params['leftJoins'] = array();
|
||||
}
|
||||
if (empty($params['whereClause'])) {
|
||||
$params['whereClause'] = array();
|
||||
}
|
||||
if (empty($params['joinConditions'])) {
|
||||
$params['joinConditions'] = array();
|
||||
}
|
||||
$params['leftJoins'][] = 'phoneNumbers';
|
||||
$params['joinConditions']['phoneNumbers'] = array(
|
||||
'primary' => 1
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if ($entity->isNew()) {
|
||||
if (!$entity->has('id')) {
|
||||
$entity->set('id', uniqid());
|
||||
}
|
||||
protected function beforeRemove(Entity $entity, array $options = array())
|
||||
{
|
||||
parent::beforeRemove($entity, $options);
|
||||
$this->getEntityManager()->getHookManager()->process($this->entityName, 'beforeRemove', $entity, $options);
|
||||
|
||||
if ($entity->hasField('createdAt')) {
|
||||
$entity->set('createdAt', $nowString);
|
||||
}
|
||||
if ($entity->hasField('createdById')) {
|
||||
$entity->set('createdById', $this->entityManager->getUser()->id);
|
||||
}
|
||||
$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);
|
||||
}
|
||||
}
|
||||
|
||||
if ($entity->has('modifiedById')) {
|
||||
$restoreData['modifiedById'] = $entity->get('modifiedById');
|
||||
}
|
||||
if ($entity->has('modifiedAt')) {
|
||||
$restoreData['modifiedAt'] = $entity->get('modifiedAt');
|
||||
}
|
||||
$entity->clear('modifiedById');
|
||||
$entity->clear('modifiedAt');
|
||||
} else {
|
||||
if ($entity->hasField('modifiedAt')) {
|
||||
$entity->set('modifiedAt', $nowString);
|
||||
}
|
||||
if ($entity->hasField('modifiedById')) {
|
||||
$entity->set('modifiedById', $this->entityManager->getUser()->id);
|
||||
}
|
||||
protected function afterRemove(Entity $entity, array $options = array())
|
||||
{
|
||||
parent::afterRemove($entity, $options);
|
||||
$this->getEntityManager()->getHookManager()->process($this->entityName, 'afterRemove', $entity, $options);
|
||||
}
|
||||
|
||||
if ($entity->has('createdById')) {
|
||||
$restoreData['createdById'] = $entity->get('createdById');
|
||||
}
|
||||
if ($entity->has('createdAt')) {
|
||||
$restoreData['createdAt'] = $entity->get('createdAt');
|
||||
}
|
||||
$entity->clear('createdById');
|
||||
$entity->clear('createdAt');
|
||||
}
|
||||
$result = parent::save($entity);
|
||||
public function remove(Entity $entity, array $options = array())
|
||||
{
|
||||
$result = parent::remove($entity, $options);
|
||||
if ($result) {
|
||||
$this->getEntityManager()->getHookManager()->process($this->entityName, 'afterRemove', $entity, $options);
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
$entity->set($restoreData);
|
||||
protected function beforeSave(Entity $entity, array $options = array())
|
||||
{
|
||||
parent::beforeSave($entity, $options);
|
||||
|
||||
$this->handleEmailAddressSave($entity);
|
||||
$this->handlePhoneNumberSave($entity);
|
||||
$this->handleSpecifiedRelations($entity);
|
||||
$this->getEntityManager()->getHookManager()->process($this->entityName, 'beforeSave', $entity, $options);
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
protected function afterSave(Entity $entity, array $options = array())
|
||||
{
|
||||
if (!empty($this->restoreData)) {
|
||||
$entity->set($this->restoreData);
|
||||
$this->restoreData = null;
|
||||
}
|
||||
parent::afterSave($entity, $options);
|
||||
|
||||
protected function handleEmailAddressSave(Entity $entity)
|
||||
{
|
||||
if ($entity->hasRelation('emailAddresses') && $entity->hasField('emailAddress')) {
|
||||
$emailAddressRepository = $this->getEntityManager()->getRepository('EmailAddress')->storeEntityEmailAddress($entity);
|
||||
}
|
||||
}
|
||||
|
||||
protected function handlePhoneNumberSave(Entity $entity)
|
||||
{
|
||||
if ($entity->hasRelation('phoneNumbers') && $entity->hasField('phoneNumber')) {
|
||||
$emailAddressRepository = $this->getEntityManager()->getRepository('PhoneNumber')->storeEntityPhoneNumber($entity);
|
||||
}
|
||||
}
|
||||
$this->handleEmailAddressSave($entity);
|
||||
$this->handlePhoneNumberSave($entity);
|
||||
$this->handleSpecifiedRelations($entity);
|
||||
|
||||
protected function handleSpecifiedRelations(Entity $entity)
|
||||
{
|
||||
$relationTypes = array($entity::HAS_MANY, $entity::MANY_MANY, $entity::HAS_CHILDREN);
|
||||
foreach ($entity->getRelations() as $name => $defs) {
|
||||
if (in_array($defs['type'], $relationTypes)) {
|
||||
$fieldName = $name . 'Ids';
|
||||
if ($entity->has($fieldName)) {
|
||||
$specifiedIds = $entity->get($fieldName);
|
||||
if (is_array($specifiedIds)) {
|
||||
$toRemoveIds = array();
|
||||
$existingIds = array();
|
||||
$toUpdateIds = array();
|
||||
$existingColumnsData = new \stdClass();
|
||||
|
||||
$defs = array();
|
||||
$columns = $this->getMetadata()->get("entityDefs." . $entity->getEntityName() . ".fields.{$name}.columns");
|
||||
if (!empty($columns)) {
|
||||
$columnData = $entity->get($name . 'Columns');
|
||||
$defs['additionalColumns'] = $columns;
|
||||
$this->getEntityManager()->getHookManager()->process($this->entityName, 'afterSave', $entity, $options);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
foreach ($entity->get($name, $defs) as $foreignEntity) {
|
||||
$existingIds[] = $foreignEntity->id;
|
||||
if (!empty($columns)) {
|
||||
$data = new \stdClass();
|
||||
foreach ($columns as $columnName => $columnField) {
|
||||
$foreignId = $foreignEntity->id;
|
||||
$data->$columnName = $foreignEntity->get($columnField);
|
||||
}
|
||||
$existingColumnsData->$foreignId = $data;
|
||||
}
|
||||
|
||||
}
|
||||
foreach ($existingIds as $id) {
|
||||
if (!in_array($id, $specifiedIds)) {
|
||||
$toRemoveIds[] = $id;
|
||||
} else {
|
||||
if (!empty($columns)) {
|
||||
foreach ($columns as $columnName => $columnField) {
|
||||
if ($columnData->$id->$columnName != $existingColumnsData->$id->$columnName) {
|
||||
$toUpdateIds[] = $id;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
foreach ($specifiedIds as $id) {
|
||||
if (!in_array($id, $existingIds)) {
|
||||
$data = null;
|
||||
if (!empty($columns)) {
|
||||
$data = $columnData->$id;
|
||||
}
|
||||
$this->relate($entity, $name, $id, $data);
|
||||
}
|
||||
}
|
||||
foreach ($toRemoveIds as $id) {
|
||||
$this->unrelate($entity, $name, $id);
|
||||
}
|
||||
if (!empty($columns)) {
|
||||
foreach ($toUpdateIds as $id) {
|
||||
$data = $columnData->$id;
|
||||
$this->updateRelation($entity, $name, $id, $data);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
public function save(Entity $entity, array $options = array())
|
||||
{
|
||||
$nowString = date('Y-m-d H:i:s', time());
|
||||
$restoreData = array();
|
||||
|
||||
if ($entity->isNew()) {
|
||||
if (!$entity->has('id')) {
|
||||
$entity->set('id', Util::generateId());
|
||||
}
|
||||
|
||||
if ($entity->hasField('createdAt')) {
|
||||
$entity->set('createdAt', $nowString);
|
||||
}
|
||||
if ($entity->hasField('modifiedAt')) {
|
||||
$entity->set('modifiedAt', $nowString);
|
||||
}
|
||||
if ($entity->hasField('createdById')) {
|
||||
$entity->set('createdById', $this->entityManager->getUser()->id);
|
||||
}
|
||||
|
||||
if ($entity->has('modifiedById')) {
|
||||
$restoreData['modifiedById'] = $entity->get('modifiedById');
|
||||
}
|
||||
if ($entity->has('modifiedAt')) {
|
||||
$restoreData['modifiedAt'] = $entity->get('modifiedAt');
|
||||
}
|
||||
$entity->clear('modifiedById');
|
||||
} else {
|
||||
if (empty($options['silent'])) {
|
||||
if ($entity->hasField('modifiedAt')) {
|
||||
$entity->set('modifiedAt', $nowString);
|
||||
}
|
||||
if ($entity->hasField('modifiedById')) {
|
||||
$entity->set('modifiedById', $this->entityManager->getUser()->id);
|
||||
}
|
||||
}
|
||||
|
||||
if ($entity->has('createdById')) {
|
||||
$restoreData['createdById'] = $entity->get('createdById');
|
||||
}
|
||||
if ($entity->has('createdAt')) {
|
||||
$restoreData['createdAt'] = $entity->get('createdAt');
|
||||
}
|
||||
$entity->clear('createdById');
|
||||
$entity->clear('createdAt');
|
||||
}
|
||||
$this->restoreData = $restoreData;
|
||||
|
||||
$result = parent::save($entity, $options);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
protected function handleEmailAddressSave(Entity $entity)
|
||||
{
|
||||
if ($entity->hasRelation('emailAddresses') && $entity->hasField('emailAddress')) {
|
||||
$emailAddressRepository = $this->getEntityManager()->getRepository('EmailAddress')->storeEntityEmailAddress($entity);
|
||||
}
|
||||
}
|
||||
|
||||
protected function handlePhoneNumberSave(Entity $entity)
|
||||
{
|
||||
if ($entity->hasRelation('phoneNumbers') && $entity->hasField('phoneNumber')) {
|
||||
$emailAddressRepository = $this->getEntityManager()->getRepository('PhoneNumber')->storeEntityPhoneNumber($entity);
|
||||
}
|
||||
}
|
||||
|
||||
protected function handleSpecifiedRelations(Entity $entity)
|
||||
{
|
||||
$relationTypes = array($entity::HAS_MANY, $entity::MANY_MANY, $entity::HAS_CHILDREN);
|
||||
foreach ($entity->getRelations() as $name => $defs) {
|
||||
if (in_array($defs['type'], $relationTypes)) {
|
||||
$fieldName = $name . 'Ids';
|
||||
$columnsFieldsName = $name . 'Columns';
|
||||
|
||||
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 {
|
||||
$specifiedIds = array();
|
||||
foreach ($entity->get($columnsFieldsName) as $id => $d) {
|
||||
$specifiedIds[] = $id;
|
||||
}
|
||||
}
|
||||
if (is_array($specifiedIds)) {
|
||||
$toRemoveIds = array();
|
||||
$existingIds = array();
|
||||
$toUpdateIds = array();
|
||||
$existingColumnsData = new \stdClass();
|
||||
|
||||
$defs = array();
|
||||
$columns = $this->getMetadata()->get("entityDefs." . $entity->getEntityType() . ".fields.{$name}.columns");
|
||||
if (!empty($columns)) {
|
||||
$columnData = $entity->get($columnsFieldsName);
|
||||
$defs['additionalColumns'] = $columns;
|
||||
}
|
||||
|
||||
$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);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
} else {
|
||||
if (!empty($columns)) {
|
||||
foreach ($columns as $columnName => $columnField) {
|
||||
if ($columnData->$id->$columnName != $existingColumnsData->$id->$columnName) {
|
||||
$toUpdateIds[] = $id;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
foreach ($specifiedIds as $id) {
|
||||
if (!in_array($id, $existingIds)) {
|
||||
$data = null;
|
||||
if (!empty($columns) && isset($columnData->$id)) {
|
||||
$data = $columnData->$id;
|
||||
}
|
||||
$this->relate($entity, $name, $id, $data);
|
||||
}
|
||||
}
|
||||
foreach ($toRemoveIds as $id) {
|
||||
$this->unrelate($entity, $name, $id);
|
||||
}
|
||||
if (!empty($columns)) {
|
||||
foreach ($toUpdateIds as $id) {
|
||||
$data = $columnData->$id;
|
||||
$this->updateRelation($entity, $name, $id, $data);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM - Open Source CRM application.
|
||||
* Copyright (C) 2014 Yuri Kuznetsov, Taras Machyshyn, Oleksiy Avramenko
|
||||
* 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
|
||||
@@ -18,7 +18,7 @@
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with EspoCRM. If not, see http://www.gnu.org/licenses/.
|
||||
************************************************************************/
|
||||
************************************************************************/
|
||||
|
||||
namespace Espo\Core\ORM;
|
||||
|
||||
@@ -26,23 +26,23 @@ use \Espo\Core\Interfaces\Injectable;
|
||||
|
||||
abstract class Repository extends \Espo\ORM\Repository implements Injectable
|
||||
{
|
||||
protected $dependencies = array();
|
||||
|
||||
protected $injections = array();
|
||||
|
||||
public function inject($name, $object)
|
||||
{
|
||||
$this->injections[$name] = $object;
|
||||
}
|
||||
|
||||
protected function getInjection($name)
|
||||
{
|
||||
return $this->injections[$name];
|
||||
}
|
||||
|
||||
public function getDependencyList()
|
||||
{
|
||||
return $this->dependencies;
|
||||
}
|
||||
protected $dependencies = array();
|
||||
|
||||
protected $injections = array();
|
||||
|
||||
public function inject($name, $object)
|
||||
{
|
||||
$this->injections[$name] = $object;
|
||||
}
|
||||
|
||||
protected function getInjection($name)
|
||||
{
|
||||
return $this->injections[$name];
|
||||
}
|
||||
|
||||
public function getDependencyList()
|
||||
{
|
||||
return $this->dependencies;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM - Open Source CRM application.
|
||||
* Copyright (C) 2014 Yuri Kuznetsov, Taras Machyshyn, Oleksiy Avramenko
|
||||
* 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
|
||||
@@ -18,23 +18,23 @@
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with EspoCRM. If not, see http://www.gnu.org/licenses/.
|
||||
************************************************************************/
|
||||
************************************************************************/
|
||||
|
||||
namespace Espo\Core\ORM;
|
||||
|
||||
class RepositoryFactory extends \Espo\ORM\RepositoryFactory
|
||||
{
|
||||
protected $defaultRepositoryClassName = '\\Espo\\Core\\ORM\\Repositories\\RDB';
|
||||
{
|
||||
protected $defaultRepositoryClassName = '\\Espo\\Core\\ORM\\Repositories\\RDB';
|
||||
|
||||
public function create($name)
|
||||
{
|
||||
$repository = parent::create($name);
|
||||
|
||||
$dependencies = $repository->getDependencyList();
|
||||
foreach ($dependencies as $name) {
|
||||
$repository->inject($name, $this->entityManager->getContainer()->get($name));
|
||||
}
|
||||
return $repository;
|
||||
}
|
||||
public function create($name)
|
||||
{
|
||||
$repository = parent::create($name);
|
||||
|
||||
$dependencies = $repository->getDependencyList();
|
||||
foreach ($dependencies as $name) {
|
||||
$repository->inject($name, $this->entityManager->getContainer()->get($name));
|
||||
}
|
||||
return $repository;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
95
application/Espo/Core/Repositories/CategoryTree.php
Normal file
95
application/Espo/Core/Repositories/CategoryTree.php
Normal file
@@ -0,0 +1,95 @@
|
||||
<?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\Repositories;
|
||||
|
||||
use \Espo\Core\Entities\CategoryTreeItem as Entity;
|
||||
|
||||
class CategoryTree extends \Espo\Core\ORM\Repositories\RDB
|
||||
{
|
||||
public function afterSave(Entity $entity, $options)
|
||||
{
|
||||
parent::afterSave($entity, $options);
|
||||
|
||||
$pdo = $this->getEntityManager()->getPDO();
|
||||
$query = $this->getEntityManager()->getQuery();
|
||||
|
||||
$parentId = $entity->get('parentId');
|
||||
$pathsTableName = $query->toDb($entity->getEntityType() . 'Path');
|
||||
|
||||
if ($entity->isNew()) {
|
||||
if ($parentId) {
|
||||
$sql = "
|
||||
INSERT INTO `".$pathsTableName."` (ascendor_id, descendor_id)
|
||||
SELECT ascendor_id, ".$pdo->quote($entity->id)."
|
||||
FROM `".$pathsTableName."`
|
||||
WHERE descendor_id = ".$pdo->quote($parentId)."
|
||||
UNION ALL
|
||||
SELECT ".$pdo->quote($entity->id).", ".$pdo->quote($entity->id)."
|
||||
";
|
||||
} else {
|
||||
$sql = "
|
||||
INSERT INTO `".$pathsTableName."` (ascendor_id, descendor_id)
|
||||
VALUES
|
||||
(".$pdo->quote($entity->id).", ".$pdo->quote($entity->id).")
|
||||
";
|
||||
}
|
||||
$pdo->query($sql);
|
||||
} else {
|
||||
if ($entity->isFieldChanged('parentId')) {
|
||||
$sql = "
|
||||
DELETE a FROM `".$pathsTableName."` AS a
|
||||
JOIN `".$pathsTableName."` AS d ON a.descendor_id = d.descendor_id
|
||||
LEFT JOIN `".$pathsTableName."` AS x ON x.ascendor_id = d.ascendor_id AND x.descendor_id = a.ascendor_id
|
||||
WHERE d.ascendor_id = ".$pdo->quote($entity->id)." AND x.ascendor_id IS NULL
|
||||
";
|
||||
$pdo->query($sql);
|
||||
if (!empty($parentId)) {
|
||||
$sql = "
|
||||
INSERT INTO `".$pathsTableName."` (ascendor_id, descendor_id)
|
||||
SELECT supertree.ascendor_id, subtree.descendor_id
|
||||
FROM `".$pathsTableName."` AS supertree
|
||||
JOIN `".$pathsTableName."` AS subtree
|
||||
WHERE
|
||||
subtree.ascendor_id = ".$pdo->quote($entity->id)." AND
|
||||
supertree.descendor_id = ".$pdo->quote($parentId)."
|
||||
";
|
||||
$pdo->query($sql);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function afterRemove(Entity $entity, $options)
|
||||
{
|
||||
parent::afterRemove($entity, $options);
|
||||
|
||||
$pdo = $this->getEntityManager()->getPDO();
|
||||
$query = $this->getEntityManager()->getQuery();
|
||||
|
||||
$pathsTableName = $query->toDb($entity->getEntityType() . 'Path');
|
||||
|
||||
$sql = "DELETE FROM `".$pathsTableName."` WHERE descendor_id = ".$pdo->quote($entity->id)."";
|
||||
$pdo->query($sql);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM - Open Source CRM application.
|
||||
* Copyright (C) 2014 Yuri Kuznetsov, Taras Machyshyn, Oleksiy Avramenko
|
||||
* 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
|
||||
@@ -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;
|
||||
|
||||
@@ -28,41 +28,43 @@ use \Espo\Core\Utils\Util;
|
||||
|
||||
class SelectManagerFactory
|
||||
{
|
||||
private $entityManager;
|
||||
|
||||
private $user;
|
||||
|
||||
private $acl;
|
||||
|
||||
private $metadata;
|
||||
private $entityManager;
|
||||
|
||||
private $user;
|
||||
|
||||
private $acl;
|
||||
|
||||
private $metadata;
|
||||
|
||||
public function __construct($entityManager, \Espo\Entities\User $user, Acl $acl, $metadata)
|
||||
{
|
||||
$this->entityManager = $entityManager;
|
||||
$this->user = $user;
|
||||
$this->acl = $acl;
|
||||
$this->metadata = $metadata;
|
||||
$this->entityManager = $entityManager;
|
||||
$this->user = $user;
|
||||
$this->acl = $acl;
|
||||
$this->metadata = $metadata;
|
||||
}
|
||||
|
||||
public function create($entityType)
|
||||
{
|
||||
$normalizedName = Util::normilizeClassName($entityType);
|
||||
|
||||
$className = '\\Espo\\Custom\\SelectManagers\\' . $normalizedName;
|
||||
if (!class_exists($className)) {
|
||||
$moduleName = $this->metadata->getScopeModuleName($entityType);
|
||||
if ($moduleName) {
|
||||
$className = '\\Espo\\Modules\\' . $moduleName . '\\SelectManagers\\' . $normalizedName;
|
||||
} else {
|
||||
$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->setEntityType($entityType);
|
||||
|
||||
return $selectManager;
|
||||
}
|
||||
|
||||
public function create($entityName)
|
||||
{
|
||||
$className = '\\Espo\\Custom\\SelectManagers\\' . Util::normilizeClassName($entityName);
|
||||
if (!class_exists($className)) {
|
||||
$moduleName = $this->metadata->getScopeModuleName($entityName);
|
||||
if ($moduleName) {
|
||||
$className = '\\Espo\\Modules\\' . $moduleName . '\\SelectManagers\\' . Util::normilizeClassName($entityName);
|
||||
} else {
|
||||
$className = '\\Espo\\SelectManagers\\' . Util::normilizeClassName($entityName);
|
||||
}
|
||||
if (!class_exists($className)) {
|
||||
$className = '\\Espo\\Core\\SelectManagers\\Base';
|
||||
}
|
||||
}
|
||||
|
||||
$selectManager = new $className($this->entityManager, $this->user, $this->acl, $this->metadata);
|
||||
$selectManager->setEntityName($entityName);
|
||||
|
||||
return $selectManager;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM - Open Source CRM application.
|
||||
* Copyright (C) 2014 Yuri Kuznetsov, Taras Machyshyn, Oleksiy Avramenko
|
||||
* 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
|
||||
@@ -28,271 +28,656 @@ use \Espo\Core\Acl;
|
||||
|
||||
class Base
|
||||
{
|
||||
protected $container;
|
||||
protected $container;
|
||||
|
||||
protected $user;
|
||||
protected $user;
|
||||
|
||||
protected $acl;
|
||||
protected $acl;
|
||||
|
||||
protected $entityManager;
|
||||
protected $entityManager;
|
||||
|
||||
protected $entityName;
|
||||
protected $entityType;
|
||||
|
||||
protected $metadata;
|
||||
protected $metadata;
|
||||
|
||||
private $seed = null;
|
||||
|
||||
private $userTimeZone = null;
|
||||
|
||||
const MIN_LENGTH_FOR_CONTENT_SEARCH = 4;
|
||||
|
||||
public function __construct($entityManager, \Espo\Entities\User $user, Acl $acl, $metadata)
|
||||
{
|
||||
$this->entityManager = $entityManager;
|
||||
$this->user = $user;
|
||||
$this->acl = $acl;
|
||||
$this->metadata = $metadata;
|
||||
$this->entityManager = $entityManager;
|
||||
$this->user = $user;
|
||||
$this->acl = $acl;
|
||||
|
||||
$this->metadata = $metadata;
|
||||
}
|
||||
|
||||
public function setEntityName($entityName)
|
||||
protected function getEntityManager()
|
||||
{
|
||||
$this->entityName = $entityName;
|
||||
return $this->entityManager;
|
||||
}
|
||||
|
||||
protected function getUser()
|
||||
{
|
||||
return $this->user;
|
||||
}
|
||||
|
||||
public function setEntityType($entityType)
|
||||
{
|
||||
$this->entityType = $entityType;
|
||||
}
|
||||
|
||||
protected function getEntityType()
|
||||
{
|
||||
return $this->entityType;
|
||||
}
|
||||
|
||||
protected function limit($params, &$result)
|
||||
{
|
||||
if (isset($params['offset']) && !is_null($params['offset'])) {
|
||||
$result['offset'] = $params['offset'];
|
||||
}
|
||||
if (isset($params['maxSize']) && !is_null($params['maxSize'])) {
|
||||
$result['limit'] = $params['maxSize'];
|
||||
}
|
||||
if (isset($params['offset']) && !is_null($params['offset'])) {
|
||||
$result['offset'] = $params['offset'];
|
||||
}
|
||||
if (isset($params['maxSize']) && !is_null($params['maxSize'])) {
|
||||
$result['limit'] = $params['maxSize'];
|
||||
}
|
||||
}
|
||||
|
||||
protected function order($params, &$result)
|
||||
{
|
||||
if (!empty($params['sortBy'])) {
|
||||
$result['orderBy'] = $params['sortBy'];
|
||||
$type = $this->metadata->get("entityDefs.{$this->entityName}.fields." . $result['orderBy'] . ".type");
|
||||
if ($type == 'link') {
|
||||
$result['orderBy'] .= 'Name';
|
||||
} else if ($type == 'linkParent') {
|
||||
$result['orderBy'] .= 'Type';
|
||||
}
|
||||
}
|
||||
if (isset($params['asc'])) {
|
||||
if ($params['asc']) {
|
||||
$result['order'] = 'ASC';
|
||||
} else {
|
||||
$result['order'] = 'DESC';
|
||||
}
|
||||
}
|
||||
if (!empty($params['sortBy'])) {
|
||||
$result['orderBy'] = $params['sortBy'];
|
||||
$type = $this->metadata->get("entityDefs.{$this->entityType}.fields." . $result['orderBy'] . ".type");
|
||||
if ($type == 'link') {
|
||||
$result['orderBy'] .= 'Name';
|
||||
} else if ($type == 'linkParent') {
|
||||
$result['orderBy'] .= 'Type';
|
||||
}
|
||||
}
|
||||
if (isset($params['asc'])) {
|
||||
if ($params['asc']) {
|
||||
$result['order'] = 'ASC';
|
||||
} else {
|
||||
$result['order'] = 'DESC';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected function getTextFilterFields()
|
||||
{
|
||||
return $this->metadata->get("entityDefs.{$this->entityType}.collection.textFilterFields", array('name'));
|
||||
}
|
||||
|
||||
protected function getSeed()
|
||||
{
|
||||
if (empty($this->seed)) {
|
||||
$this->seed = $this->entityManager->getEntity($this->entityType);
|
||||
}
|
||||
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();
|
||||
if (!empty($params['where']) && is_array($params['where'])) {
|
||||
$where = array();
|
||||
|
||||
foreach ($params['where'] as $item) {
|
||||
if ($item['type'] == 'boolFilters' && !empty($item['value']) && is_array($item['value'])) {
|
||||
foreach ($item['value'] as $filter) {
|
||||
$p = $this->getBoolFilterWhere($filter);
|
||||
if (!empty($p)) {
|
||||
$params['where'][] = $p;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
foreach ($params['where'] as $item) {
|
||||
if ($item['type'] == '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'])) {
|
||||
$this->textFilter($item['value'], $result);
|
||||
}
|
||||
} else if ($item['type'] == 'primary' && !empty($item['value'])) {
|
||||
$this->primaryFilter($item['value'], $result);
|
||||
}
|
||||
}
|
||||
|
||||
$linkedWith = array();
|
||||
$ignoreList = array('linkedWith', 'boolFilters');
|
||||
foreach ($params['where'] as $item) {
|
||||
if (!in_array($item['type'], $ignoreList)) {
|
||||
$part = $this->getWherePart($item);
|
||||
if (!empty($part)) {
|
||||
$where[] = $part;
|
||||
}
|
||||
} else {
|
||||
if ($item['type'] == 'linkedWith' && !empty($item['value'])) {
|
||||
$linkedWith[$item['field']] = $item['value'];
|
||||
}
|
||||
}
|
||||
}
|
||||
$linkedWith = array();
|
||||
$inCategory = array();
|
||||
|
||||
if (!empty($linkedWith)) {
|
||||
$joins = array();
|
||||
$ignoreList = ['linkedWith', 'inCategory', 'bool', 'primary'];
|
||||
foreach ($params['where'] as $item) {
|
||||
if (!in_array($item['type'], $ignoreList)) {
|
||||
$part = $this->getWherePart($item);
|
||||
if (!empty($part)) {
|
||||
$where[] = $part;
|
||||
}
|
||||
} else {
|
||||
if ($item['type'] == 'linkedWith' && !empty($item['value'])) {
|
||||
$linkedWith[$item['field']] = $item['value'];
|
||||
} else if ($item['type'] == 'inCategory' && !empty($item['value'])) {
|
||||
$inCategory[$item['field']] = $item['value'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$part = array();
|
||||
foreach ($linkedWith as $link => $ids) {
|
||||
$joins[] = $link;
|
||||
$defs = $this->entityManager->getMetadata()->get($this->entityName);
|
||||
$result['whereClause'] = array_merge($result['whereClause'], $where);
|
||||
|
||||
$entityName = $defs['relations'][$link]['entity'];
|
||||
if ($entityName) {
|
||||
$part[$entityName . '.id'] = $ids;
|
||||
}
|
||||
}
|
||||
if (!empty($linkedWith)) {
|
||||
$this->handleLinkedWith($linkedWith, $result);
|
||||
}
|
||||
if (!empty($inCategory)) {
|
||||
$this->handleInCategory($inCategory, $result);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($part)) {
|
||||
$where[] = $part;
|
||||
}
|
||||
$result['joins'] = $joins;
|
||||
$result['distinct'] = true;
|
||||
protected function handleLinkedWith($linkedWith, &$result)
|
||||
{
|
||||
$joins = [];
|
||||
|
||||
}
|
||||
$part = array();
|
||||
foreach ($linkedWith as $link => $idsValue) {
|
||||
if (is_array($idsValue) && count($idsValue) == 1) {
|
||||
$idsValue = $idsValue[0];
|
||||
}
|
||||
|
||||
$relDefs = $this->getSeed()->getRelations();
|
||||
|
||||
if (!empty($relDefs[$link])) {
|
||||
$defs = $relDefs[$link];
|
||||
if ($defs['type'] == 'manyMany') {
|
||||
$joins[] = $link;
|
||||
if (!empty($defs['midKeys'])) {
|
||||
$key = $defs['midKeys'][1];
|
||||
$part[$link . 'Middle.' . $key] = $idsValue;
|
||||
}
|
||||
} else if ($defs['type'] == 'belongsTo') {
|
||||
if (!empty($defs['key'])) {
|
||||
$key = $defs['key'];
|
||||
$part[$key] = $idsValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($part)) {
|
||||
$result['whereClause'][] = $part;
|
||||
}
|
||||
$result['joins'] = array_merge($result['joins'], $joins);
|
||||
$result['distinct'] = true;
|
||||
}
|
||||
|
||||
protected function handleInCategory($inCategory, &$result)
|
||||
{
|
||||
$joins = [];
|
||||
|
||||
$part = array();
|
||||
|
||||
$query = $this->getEntityManager()->getQuery();
|
||||
|
||||
$tableName = $query->toDb($this->getSeed()->getEntityType());
|
||||
|
||||
foreach ($inCategory as $link => $val) {
|
||||
|
||||
$relDefs = $this->getSeed()->getRelations();
|
||||
|
||||
if (!empty($relDefs[$link])) {
|
||||
$defs = $relDefs[$link];
|
||||
|
||||
$foreignEntity = $defs['entity'];
|
||||
if (empty($foreignEntity)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$pathName = lcfirst($query->sanitize($foreignEntity . 'Path'));
|
||||
|
||||
if ($defs['type'] == 'manyMany') {
|
||||
|
||||
if (!empty($defs['relationName']) && !empty($defs['midKeys'])) {
|
||||
$result['distinct'] = true;
|
||||
$result['joins'][] = $link;
|
||||
$key = $defs['midKeys'][1];
|
||||
|
||||
$relationName = lcfirst($defs['relationName']);
|
||||
|
||||
$result['customJoin'] .= "
|
||||
JOIN " . $query->toDb($pathName) . " AS `{$pathName}` ON {$pathName}.descendor_id = ".$query->sanitize($relationName) . "." . $query->toDb($key) . "
|
||||
";
|
||||
$part[$pathName . '.ascendorId'] = $val;
|
||||
}
|
||||
} else if ($defs['type'] == 'belongsTo') {
|
||||
if (!empty($defs['key'])) {
|
||||
$key = $defs['key'];
|
||||
$result['customJoin'] .= "
|
||||
JOIN " . $query->toDb($pathName) . " AS `{$pathName}` ON {$pathName}.descendor_id = {$tableName}." . $query->toDb($key) . "
|
||||
";
|
||||
$part[$pathName . '.ascendorId'] = $val;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (!empty($part)) {
|
||||
$result['whereClause'][] = $part;
|
||||
}
|
||||
|
||||
$result['whereClause'] = $where;
|
||||
}
|
||||
}
|
||||
|
||||
protected function q($params, &$result)
|
||||
{
|
||||
if (!empty($params['q'])) {
|
||||
if (empty($result['whereClause'])) {
|
||||
$result['whereClause'] = array();
|
||||
}
|
||||
$result['whereClause']['name*'] = $params['q'] . '%';
|
||||
}
|
||||
}
|
||||
if (!empty($params['q'])) {
|
||||
$fieldDefs = $this->getSeed()->getFields();
|
||||
|
||||
$value = $params['q'];
|
||||
|
||||
$fieldList = $this->getTextFilterFields();
|
||||
$d = array();
|
||||
foreach ($fieldList as $field) {
|
||||
if (
|
||||
strlen($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 access(&$result)
|
||||
{
|
||||
if ($this->acl->checkReadOnlyOwn($this->entityName)) {
|
||||
if ($this->acl->checkReadOnlyOwn($this->entityType)) {
|
||||
$this->accessOnlyOwn($result);
|
||||
}
|
||||
if (!$this->user->isAdmin() && $this->acl->checkReadOnlyTeam($this->entityType)) {
|
||||
$this->accessOnlyTeam($result);
|
||||
}
|
||||
}
|
||||
|
||||
if (!array_key_exists('whereClause', $result)) {
|
||||
$result['whereClause'] = array();
|
||||
}
|
||||
$result['whereClause']['assignedUserId'] = $this->user->id;
|
||||
}
|
||||
if ($this->acl->checkReadOnlyTeam($this->entityName)) {
|
||||
if (!array_key_exists('whereClause', $result)) {
|
||||
$result['whereClause'] = array();
|
||||
}
|
||||
if (!array_key_exists('joins', $result)) {
|
||||
$result['joins'] = array();
|
||||
}
|
||||
if (!in_array('teams', $result['joins'])) {
|
||||
$result['joins'][] = 'teams';
|
||||
}
|
||||
protected function accessOnlyOwn(&$result)
|
||||
{
|
||||
if (!$this->getSeed()->hasField('assignedUserId')) {
|
||||
return;
|
||||
}
|
||||
$result['whereClause'][] = array(
|
||||
'assignedUserId' => $this->getUser()->id
|
||||
);
|
||||
}
|
||||
|
||||
$result['whereClause']['Team.id'] = $this->user->get('teamsIds');
|
||||
}
|
||||
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();
|
||||
$this->access($result);
|
||||
return $result;
|
||||
$result = array();
|
||||
$this->access($result);
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function getSelectParams(array $params, $withAcl = false)
|
||||
{
|
||||
$result = array();
|
||||
public function getSelectParams(array $params, $withAcl = false)
|
||||
{
|
||||
$result = array(
|
||||
'joins' => [],
|
||||
'leftJoins' => [],
|
||||
'whereClause' => [],
|
||||
'customJoin' => ''
|
||||
);
|
||||
|
||||
$this->order($params, $result);
|
||||
$this->limit($params, $result);
|
||||
$this->where($params, $result);
|
||||
$this->q($params, $result);
|
||||
$this->order($params, $result);
|
||||
$this->limit($params, $result);
|
||||
$this->where($params, $result);
|
||||
$this->q($params, $result);
|
||||
|
||||
if ($withAcl) {
|
||||
$this->access($result);
|
||||
}
|
||||
if ($withAcl) {
|
||||
$this->access($result);
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
protected function getWherePart($item)
|
||||
{
|
||||
$part = array();
|
||||
protected function getUserTimeZone()
|
||||
{
|
||||
if (empty($this->userTimeZone)) {
|
||||
$preferences = $this->getEntityManager()->getEntity('Preferences', $this->getUser()->id);
|
||||
$timeZone = $preferences->get('timeZone');
|
||||
$this->userTimeZone = $timeZone;
|
||||
}
|
||||
|
||||
if (!empty($item['type'])) {
|
||||
switch ($item['type']) {
|
||||
case 'or':
|
||||
case 'and':
|
||||
if (is_array($item['value'])) {
|
||||
$arr = array();
|
||||
foreach ($item['value'] as $i) {
|
||||
$a = $this->getWherePart($i);
|
||||
foreach ($a as $left => $right) {
|
||||
if (!empty($right)) {
|
||||
$arr[$left] = $right;
|
||||
}
|
||||
}
|
||||
}
|
||||
$part[strtoupper($item['type'])] = $arr;
|
||||
}
|
||||
break;
|
||||
case 'like':
|
||||
$part[$item['field'] . '*'] = $item['value'];
|
||||
break;
|
||||
case 'equals':
|
||||
case 'on':
|
||||
$part[$item['field'] . '='] = $item['value'];
|
||||
break;
|
||||
case 'notEquals':
|
||||
case 'notOn':
|
||||
$part[$item['field'] . '!='] = $item['value'];
|
||||
break;
|
||||
case 'greaterThan':
|
||||
case 'after':
|
||||
$part[$item['field'] . '>'] = $item['value'];
|
||||
break;
|
||||
case 'lessThan':
|
||||
case 'before':
|
||||
$part[$item['field'] . '<'] = $item['value'];
|
||||
break;
|
||||
case 'greaterThanOrEquals':
|
||||
$part[$item['field'] . '>='] = $item['value'];
|
||||
break;
|
||||
case 'lessThanOrEquals':
|
||||
$part[$item['field'] . '<'] = $item['value'];
|
||||
break;
|
||||
case 'in':
|
||||
$part[$item['field'] . '='] = $item['value'];
|
||||
break;
|
||||
case 'notIn':
|
||||
$part[$item['field'] . '!='] = $item['value'];
|
||||
break;
|
||||
case 'isTrue':
|
||||
$part[$item['field'] . '='] = true;
|
||||
break;
|
||||
case 'isFalse':
|
||||
$part[$item['field'] . '='] = false;
|
||||
break;
|
||||
case 'today':
|
||||
$part[$item['field'] . '='] = date('Y-m-d');
|
||||
break;
|
||||
case 'past':
|
||||
$part[$item['field'] . '<'] = date('Y-m-d');
|
||||
break;
|
||||
case 'future':
|
||||
$part[$item['field'] . '>'] = date('Y-m-d');
|
||||
break;
|
||||
case 'between':
|
||||
if (is_array($item['value'])) {
|
||||
$part['AND'] = array(
|
||||
$item['field'] . '>=' => $item['value'][0],
|
||||
$item['field'] . '<=' => $item['value'][1],
|
||||
);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
return $this->userTimeZone;
|
||||
}
|
||||
|
||||
return $part;
|
||||
}
|
||||
protected function convertDateTimeWhere($item)
|
||||
{
|
||||
$format = 'Y-m-d H:i:s';
|
||||
|
||||
protected function getBoolFilterWhere($filterName)
|
||||
{
|
||||
$method = 'getBoolFilterWhere' . ucfirst($filterName);
|
||||
if (method_exists($this, $method)) {
|
||||
return $this->$method();
|
||||
}
|
||||
}
|
||||
$value = null;
|
||||
$timeZone = 'UTC';
|
||||
|
||||
protected function getBoolFilterWhereOnlyMy()
|
||||
{
|
||||
return array(
|
||||
'type' => 'equals',
|
||||
'field' => 'assignedUserId',
|
||||
'value' => $this->user->id,
|
||||
);
|
||||
}
|
||||
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':
|
||||
case 'and':
|
||||
if (is_array($item['value'])) {
|
||||
$arr = array();
|
||||
foreach ($item['value'] as $i) {
|
||||
$a = $this->getWherePart($i);
|
||||
foreach ($a as $left => $right) {
|
||||
if (!empty($right)) {
|
||||
$arr[] = array($left => $right);
|
||||
}
|
||||
}
|
||||
}
|
||||
$part[strtoupper($item['type'])] = $arr;
|
||||
}
|
||||
break;
|
||||
case 'like':
|
||||
$part[$item['field'] . '*'] = $item['value'];
|
||||
break;
|
||||
case 'equals':
|
||||
case 'on':
|
||||
$part[$item['field'] . '='] = $item['value'];
|
||||
break;
|
||||
case 'startsWith':
|
||||
$part[$item['field'] . '*'] = $item['value'] . '%';
|
||||
break;
|
||||
case 'contains':
|
||||
$part[$item['field'] . '*'] = '%' . $item['value'] . '%';
|
||||
break;
|
||||
case 'notEquals':
|
||||
case 'notOn':
|
||||
$part[$item['field'] . '!='] = $item['value'];
|
||||
break;
|
||||
case 'greaterThan':
|
||||
case 'after':
|
||||
$part[$item['field'] . '>'] = $item['value'];
|
||||
break;
|
||||
case 'lessThan':
|
||||
case 'before':
|
||||
$part[$item['field'] . '<'] = $item['value'];
|
||||
break;
|
||||
case 'greaterThanOrEquals':
|
||||
$part[$item['field'] . '>='] = $item['value'];
|
||||
break;
|
||||
case 'lessThanOrEquals':
|
||||
$part[$item['field'] . '<'] = $item['value'];
|
||||
break;
|
||||
case 'in':
|
||||
$part[$item['field'] . '='] = $item['value'];
|
||||
break;
|
||||
case 'notIn':
|
||||
$part[$item['field'] . '!='] = $item['value'];
|
||||
break;
|
||||
case 'isNull':
|
||||
$part[$item['field'] . '='] = null;
|
||||
break;
|
||||
case 'isNotNull':
|
||||
$part[$item['field'] . '!='] = null;
|
||||
break;
|
||||
case 'isTrue':
|
||||
$part[$item['field'] . '='] = true;
|
||||
break;
|
||||
case 'isFalse':
|
||||
$part[$item['field'] . '='] = false;
|
||||
break;
|
||||
case 'today':
|
||||
$part[$item['field'] . '='] = date('Y-m-d');
|
||||
break;
|
||||
case 'past':
|
||||
$part[$item['field'] . '<'] = date('Y-m-d');
|
||||
break;
|
||||
case 'future':
|
||||
$part[$item['field'] . '>='] = date('Y-m-d');
|
||||
break;
|
||||
case 'currentMonth':
|
||||
$dt = new \DateTime();
|
||||
$part['AND'] = array(
|
||||
$item['field'] . '>=' => $dt->modify('first day of this month')->format('Y-m-d'),
|
||||
$item['field'] . '<' => $dt->add(new \DateInterval('P1M'))->format('Y-m-d'),
|
||||
);
|
||||
break;
|
||||
case 'lastMonth':
|
||||
$dt = new \DateTime();
|
||||
$part['AND'] = array(
|
||||
$item['field'] . '>=' => $dt->modify('first day of last month')->format('Y-m-d'),
|
||||
$item['field'] . '<' => $dt->add(new \DateInterval('P1M'))->format('Y-m-d'),
|
||||
);
|
||||
break;
|
||||
case 'currentQuarter':
|
||||
$dt = new \DateTime();
|
||||
$quarter = ceil($dt->format('m') / 3);
|
||||
$dt->modify('first day of January this year');
|
||||
$part['AND'] = array(
|
||||
$item['field'] . '>=' => $dt->add(new \DateInterval('P'.(($quarter - 1) * 3).'M'))->format('Y-m-d'),
|
||||
$item['field'] . '<' => $dt->add(new \DateInterval('P3M'))->format('Y-m-d'),
|
||||
);
|
||||
break;
|
||||
case 'lastQuarter':
|
||||
$dt = new \DateTime();
|
||||
$quarter = ceil($dt->format('m') / 3);
|
||||
$dt->modify('first day of January this year');
|
||||
$quarter--;
|
||||
if ($quarter == 0) {
|
||||
$quarter = 4;
|
||||
$dt->sub('P1Y');
|
||||
}
|
||||
$part['AND'] = array(
|
||||
$item['field'] . '>=' => $dt->add(new \DateInterval('P'.(($quarter - 1) * 3).'M'))->format('Y-m-d'),
|
||||
$item['field'] . '<' => $dt->add(new \DateInterval('P3M'))->format('Y-m-d'),
|
||||
);
|
||||
break;
|
||||
case 'currentYear':
|
||||
$dt = new \DateTime();
|
||||
$part['AND'] = array(
|
||||
$item['field'] . '>=' => $dt->modify('first day of January this year')->format('Y-m-d'),
|
||||
$item['field'] . '<' => $dt->add(new \DateInterval('P1Y'))->format('Y-m-d'),
|
||||
);
|
||||
break;
|
||||
case 'lastYear':
|
||||
$dt = new \DateTime();
|
||||
$part['AND'] = array(
|
||||
$item['field'] . '>=' => $dt->modify('first day of January last year')->format('Y-m-d'),
|
||||
$item['field'] . '<' => $dt->add(new \DateInterval('P1Y'))->format('Y-m-d'),
|
||||
);
|
||||
break;
|
||||
case 'between':
|
||||
if (is_array($item['value'])) {
|
||||
$part['AND'] = array(
|
||||
$item['field'] . '>=' => $item['value'][0],
|
||||
$item['field'] . '<=' => $item['value'][1],
|
||||
);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return $part;
|
||||
}
|
||||
|
||||
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);
|
||||
if (method_exists($this, $method)) {
|
||||
return $this->$method();
|
||||
}
|
||||
}
|
||||
|
||||
protected function boolFilterOnlyMy(&$result)
|
||||
{
|
||||
$result['whereClause'][] = array(
|
||||
'assignedUserId' => $this->getUser()->id
|
||||
);
|
||||
}
|
||||
|
||||
protected function filterFollowed(&$result)
|
||||
{
|
||||
$query = $this->getEntityManager()->getQuery();
|
||||
$result['customJoin'] .= "
|
||||
JOIN subscription ON
|
||||
subscription.entity_type = ".$query->quote($this->getEntityType())." AND
|
||||
subscription.entity_id = ".$query->toDb($this->getEntityType()).".id AND
|
||||
subscription.user_id = ".$query->quote($this->getUser()->id)."
|
||||
";
|
||||
}
|
||||
|
||||
protected function boolFilterFollowed(&$result)
|
||||
{
|
||||
$this->filterFollowed($result);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM - Open Source CRM application.
|
||||
* Copyright (C) 2014 Yuri Kuznetsov, Taras Machyshyn, Oleksiy Avramenko
|
||||
* 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
|
||||
@@ -28,127 +28,83 @@ use \Espo\Core\Utils\Util;
|
||||
|
||||
class ServiceFactory
|
||||
{
|
||||
private $container;
|
||||
private $container;
|
||||
|
||||
protected $cacheFile = 'data/cache/application/services.php';
|
||||
protected $cacheFile = 'data/cache/application/services.php';
|
||||
|
||||
/**
|
||||
/**
|
||||
* @var array - path to Service files
|
||||
*/
|
||||
protected $paths = array(
|
||||
'corePath' => 'application/Espo/Services',
|
||||
'modulePath' => 'application/Espo/Modules/{*}/Services',
|
||||
'customPath' => 'custom/Espo/Custom/Services',
|
||||
);
|
||||
protected $paths = array(
|
||||
'corePath' => 'application/Espo/Services',
|
||||
'modulePath' => 'application/Espo/Modules/{*}/Services',
|
||||
'customPath' => 'custom/Espo/Custom/Services',
|
||||
);
|
||||
|
||||
protected $data;
|
||||
protected $data;
|
||||
|
||||
public function __construct(Container $container)
|
||||
{
|
||||
$this->container = $container;
|
||||
$this->container = $container;
|
||||
}
|
||||
|
||||
protected function init()
|
||||
{
|
||||
$config = $this->getContainer()->get('config');
|
||||
protected function getFileManager()
|
||||
{
|
||||
return $this->container->get('fileManager');
|
||||
}
|
||||
|
||||
if (file_exists($this->cacheFile) && $config->get('useCache')) {
|
||||
$this->data = $this->getFileManager()->getContents($this->cacheFile);
|
||||
} else {
|
||||
$this->data = $this->getClassNameHash($this->paths['corePath']);
|
||||
protected function getContainer()
|
||||
{
|
||||
return $this->container;
|
||||
}
|
||||
|
||||
foreach ($this->getContainer()->get('metadata')->getModuleList() as $moduleName) {
|
||||
$path = str_replace('{*}', $moduleName, $this->paths['modulePath']);
|
||||
$this->data = array_merge($this->data, $this->getClassNameHash($path));
|
||||
}
|
||||
protected function init()
|
||||
{
|
||||
$classParser = $this->getContainer()->get('classParser');
|
||||
$classParser->setAllowedMethods(null);
|
||||
$this->data = $classParser->getData($this->paths, $this->cacheFile);
|
||||
}
|
||||
|
||||
$this->data = array_merge($this->data, $this->getClassNameHash($this->paths['customPath']));
|
||||
protected function getClassName($name)
|
||||
{
|
||||
if (!isset($this->data)) {
|
||||
$this->init();
|
||||
}
|
||||
|
||||
if ($config->get('useCache')) {
|
||||
$result = $this->getFileManager()->putContentsPHP($this->cacheFile, $this->data);
|
||||
if ($result == false) {
|
||||
throw new \Espo\Core\Exceptions\Error();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected function getFileManager()
|
||||
{
|
||||
return $this->container->get('fileManager');
|
||||
}
|
||||
|
||||
protected function getContainer()
|
||||
{
|
||||
return $this->container;
|
||||
}
|
||||
|
||||
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];
|
||||
}
|
||||
if (isset($this->data[$name])) {
|
||||
return $this->data[$name];
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public function checkExists($name) {
|
||||
$className = $this->getClassName($name);
|
||||
if (!empty($className)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
public function checkExists($name) {
|
||||
$className = $this->getClassName($name);
|
||||
if (!empty($className)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public function create($name)
|
||||
{
|
||||
$className = $this->getClassName($name);
|
||||
if (empty($className)) {
|
||||
throw new Error();
|
||||
}
|
||||
return $this->createByClassName($className);
|
||||
$className = $this->getClassName($name);
|
||||
if (empty($className)) {
|
||||
throw new Error();
|
||||
}
|
||||
return $this->createByClassName($className);
|
||||
}
|
||||
|
||||
protected function createByClassName($className)
|
||||
{
|
||||
if (class_exists($className)) {
|
||||
$service = new $className();
|
||||
$dependencies = $service->getDependencyList();
|
||||
foreach ($dependencies as $name) {
|
||||
$service->inject($name, $this->container->get($name));
|
||||
}
|
||||
return $service;
|
||||
}
|
||||
throw new Error("Class '$className' does not exist");
|
||||
}
|
||||
|
||||
// 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$', 'file');
|
||||
foreach ($fileList as $file) {
|
||||
$filePath = Util::concatPath($dir, $file);
|
||||
$className = Util::getClassName($filePath);
|
||||
$fileName = $this->getFileManager()->getFileName($filePath);
|
||||
$data[$fileName] = $className;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
protected function createByClassName($className)
|
||||
{
|
||||
if (class_exists($className)) {
|
||||
$service = new $className();
|
||||
$dependencies = $service->getDependencyList();
|
||||
foreach ($dependencies as $name) {
|
||||
$service->inject($name, $this->container->get($name));
|
||||
}
|
||||
return $service;
|
||||
}
|
||||
throw new Error("Class '$className' does not exist");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM - Open Source CRM application.
|
||||
* Copyright (C) 2014 Yuri Kuznetsov, Taras Machyshyn, Oleksiy Avramenko
|
||||
* 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
|
||||
@@ -18,7 +18,7 @@
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with EspoCRM. If not, see http://www.gnu.org/licenses/.
|
||||
************************************************************************/
|
||||
************************************************************************/
|
||||
|
||||
namespace Espo\Core\Services;
|
||||
|
||||
@@ -26,32 +26,56 @@ use \Espo\Core\Interfaces\Injectable;
|
||||
|
||||
abstract class Base implements Injectable
|
||||
{
|
||||
protected $dependencies = array();
|
||||
|
||||
protected $injections = array();
|
||||
|
||||
public function inject($name, $object)
|
||||
{
|
||||
$this->injections[$name] = $object;
|
||||
}
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->init();
|
||||
}
|
||||
|
||||
protected function init()
|
||||
{
|
||||
}
|
||||
|
||||
protected function getInjection($name)
|
||||
{
|
||||
return $this->injections[$name];
|
||||
}
|
||||
|
||||
public function getDependencyList()
|
||||
{
|
||||
return $this->dependencies;
|
||||
}
|
||||
protected $dependencies = array(
|
||||
'config',
|
||||
'entityManager',
|
||||
'user',
|
||||
);
|
||||
|
||||
protected $injections = array();
|
||||
|
||||
public function inject($name, $object)
|
||||
{
|
||||
$this->injections[$name] = $object;
|
||||
}
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->init();
|
||||
}
|
||||
|
||||
protected function init()
|
||||
{
|
||||
}
|
||||
|
||||
protected function getInjection($name)
|
||||
{
|
||||
return $this->injections[$name];
|
||||
}
|
||||
|
||||
protected function addDependency($name)
|
||||
{
|
||||
$this->dependencies[] = $name;
|
||||
}
|
||||
|
||||
public function getDependencyList()
|
||||
{
|
||||
return $this->dependencies;
|
||||
}
|
||||
|
||||
protected function getEntityManager()
|
||||
{
|
||||
return $this->getInjection('entityManager');
|
||||
}
|
||||
|
||||
protected function getConfig()
|
||||
{
|
||||
return $this->getInjection('config');
|
||||
}
|
||||
|
||||
protected function getUser()
|
||||
{
|
||||
return $this->getInjection('user');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
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/CategoryTree.php
Normal file
30
application/Espo/Core/Templates/Controllers/CategoryTree.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 CategoryTree extends \Espo\Core\Controllers\RecordTree
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
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/CategoryTree.php
Normal file
29
application/Espo/Core/Templates/Entities/CategoryTree.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 CategoryTree extends \Espo\Core\Entities\CategoryTreeItem
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user