refactoring
This commit is contained in:
@@ -94,6 +94,7 @@ class EntryPointManager
|
||||
protected function getClassName(string $name) : ?string
|
||||
{
|
||||
$name = ucfirst($name);
|
||||
|
||||
return $this->classFinder->find('EntryPoints', $name);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,6 +37,7 @@ use Espo\Core\EntryPoints\EntryPoint;
|
||||
use Espo\Core\Di;
|
||||
|
||||
use Espo\Core\Api\Request;
|
||||
use Espo\Core\Api\Response;
|
||||
|
||||
class Attachment implements EntryPoint,
|
||||
Di\EntityManagerAware,
|
||||
@@ -52,7 +53,7 @@ class Attachment implements EntryPoint,
|
||||
'image/webp',
|
||||
];
|
||||
|
||||
public function run(Request $request)
|
||||
public function run(Request $request, Response $response) : void
|
||||
{
|
||||
$id = $request->get('id');
|
||||
|
||||
@@ -88,7 +89,9 @@ class Attachment implements EntryPoint,
|
||||
|
||||
header('Pragma: public');
|
||||
header('Content-Length: ' . filesize($fileName));
|
||||
|
||||
readfile($fileName);
|
||||
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,15 +29,13 @@
|
||||
|
||||
namespace Espo\EntryPoints;
|
||||
|
||||
use Espo\Core\Exceptions\NotFound;
|
||||
use Espo\Core\Exceptions\Forbidden;
|
||||
use Espo\Core\Exceptions\BadRequest;
|
||||
use Espo\Core\Exceptions\Error;
|
||||
|
||||
use Espo\Core\EntryPoints\NotStrictAuth;
|
||||
use Espo\Core\Di;
|
||||
|
||||
use Espo\Core\Api\Request;
|
||||
use Espo\Core\Api\Response;
|
||||
|
||||
class Avatar extends Image implements Di\MetadataAware
|
||||
{
|
||||
@@ -73,7 +71,7 @@ class Avatar extends Image implements Di\MetadataAware
|
||||
return $colorList[$index];
|
||||
}
|
||||
|
||||
public function run(Request $request)
|
||||
public function run(Request $request, Response $response) : void
|
||||
{
|
||||
$userId = $request->get('id');
|
||||
$size = $request->get('size') ?? null;
|
||||
|
||||
@@ -29,8 +29,6 @@
|
||||
|
||||
namespace Espo\EntryPoints;
|
||||
|
||||
use Espo\Core\Exceptions\NotFound;
|
||||
use Espo\Core\Exceptions\Forbidden;
|
||||
use Espo\Core\Exceptions\BadRequest;
|
||||
use Espo\Core\Exceptions\Error;
|
||||
|
||||
@@ -43,6 +41,7 @@ use Espo\Core\{
|
||||
Utils\ClientManager,
|
||||
ServiceFactory,
|
||||
Api\Request,
|
||||
Api\Response,
|
||||
};
|
||||
|
||||
class ConfirmOptIn implements EntryPoint
|
||||
@@ -58,19 +57,23 @@ class ConfirmOptIn implements EntryPoint
|
||||
$this->serviceFactory = $serviceFactory;
|
||||
}
|
||||
|
||||
public function run(Request $request)
|
||||
public function run(Request $request, Response $response) : void
|
||||
{
|
||||
$id = $request->get('id');
|
||||
|
||||
if (!$id) throw new BadRequest();
|
||||
if (!$id) {
|
||||
throw new BadRequest();
|
||||
}
|
||||
|
||||
$data = $this->serviceFactory->create('LeadCapture')->confirmOptIn($id);
|
||||
|
||||
if ($data->status === 'success') {
|
||||
$action = 'optInConfirmationSuccess';
|
||||
} else if ($data->status === 'expired') {
|
||||
}
|
||||
else if ($data->status === 'expired') {
|
||||
$action = 'optInConfirmationExpired';
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
throw new Error();
|
||||
}
|
||||
|
||||
|
||||
@@ -40,10 +40,10 @@ use Espo\Core\EntryPoints\{
|
||||
use Espo\Core\{
|
||||
Acl,
|
||||
ORM\EntityManager,
|
||||
Api\Request,
|
||||
Api\Response,
|
||||
};
|
||||
|
||||
use Espo\Core\Api\Request;
|
||||
|
||||
class Download implements EntryPoint
|
||||
{
|
||||
protected $fileTypesToShowInline = [
|
||||
@@ -66,11 +66,13 @@ class Download implements EntryPoint
|
||||
$this->entityManager = $entityManager;
|
||||
}
|
||||
|
||||
public function run(Request $request)
|
||||
public function run(Request $request, Response $response) : void
|
||||
{
|
||||
$id = $request->get('id');
|
||||
|
||||
if (!$id) throw new BadRequest();
|
||||
if (!$id) {
|
||||
throw new BadRequest();
|
||||
}
|
||||
|
||||
$attachment = $this->entityManager->getEntity('Attachment', $id);
|
||||
|
||||
@@ -82,34 +84,42 @@ class Download implements EntryPoint
|
||||
throw new Forbidden();
|
||||
}
|
||||
|
||||
$sourceId = $attachment->getSourceId();
|
||||
|
||||
if ($this->entityManager->getRepository('Attachment')->hasDownloadUrl($attachment)) {
|
||||
$downloadUrl = $this->entityManager->getRepository('Attachment')->getDownloadUrl($attachment);
|
||||
$downloadUrl = $this->entityManager
|
||||
->getRepository('Attachment')
|
||||
->getDownloadUrl($attachment);
|
||||
|
||||
header('Location: ' . $downloadUrl);
|
||||
|
||||
exit;
|
||||
}
|
||||
|
||||
$fileName = $this->entityManager->getRepository('Attachment')->getFilePath($attachment);
|
||||
$fileName = $this->entityManager
|
||||
->getRepository('Attachment')
|
||||
->getFilePath($attachment);
|
||||
|
||||
if (!file_exists($fileName)) {
|
||||
throw new NotFound();
|
||||
}
|
||||
|
||||
$outputFileName = $attachment->get('name');
|
||||
|
||||
$outputFileName = str_replace("\"", "\\\"", $outputFileName);
|
||||
|
||||
$type = $attachment->get('type');
|
||||
|
||||
$disposition = 'attachment';
|
||||
|
||||
if (in_array($type, $this->fileTypesToShowInline)) {
|
||||
$disposition = 'inline';
|
||||
}
|
||||
|
||||
header('Content-Description: File Transfer');
|
||||
|
||||
if ($type) {
|
||||
header('Content-Type: ' . $type);
|
||||
}
|
||||
|
||||
header("Content-Disposition: " . $disposition . ";filename=\"" . $outputFileName . "\"");
|
||||
header('Expires: 0');
|
||||
header('Cache-Control: must-revalidate');
|
||||
@@ -117,6 +127,7 @@ class Download implements EntryPoint
|
||||
header('Content-Length: ' . filesize($fileName));
|
||||
|
||||
readfile($fileName);
|
||||
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,6 +38,7 @@ use Espo\Core\Exceptions\Error;
|
||||
use Espo\Core\EntryPoints\EntryPoint;
|
||||
|
||||
use Espo\Core\Api\Request;
|
||||
use Espo\Core\Api\Response;
|
||||
|
||||
use Espo\Core\Di;
|
||||
|
||||
@@ -76,7 +77,7 @@ class Image implements EntryPoint,
|
||||
|
||||
protected $allowedFieldList = null;
|
||||
|
||||
public function run(Request $request)
|
||||
public function run(Request $request, Response $response) : void
|
||||
{
|
||||
$id = $request->get('id');
|
||||
$size = $request->get('size') ?? null;
|
||||
|
||||
@@ -30,15 +30,15 @@
|
||||
namespace Espo\EntryPoints;
|
||||
|
||||
use Espo\Core\Exceptions\NotFound;
|
||||
use Espo\Core\Exceptions\Forbidden;
|
||||
use Espo\Core\Exceptions\BadRequest;
|
||||
use Espo\Core\Exceptions\Error;
|
||||
|
||||
use Espo\Core\EntryPoints\{
|
||||
NoAuth,
|
||||
};
|
||||
|
||||
use Espo\Core\Api\Request;
|
||||
use Espo\Core\{
|
||||
Api\Request,
|
||||
Api\Response,
|
||||
};
|
||||
|
||||
use Espo\Core\Di;
|
||||
|
||||
@@ -51,7 +51,7 @@ class LogoImage extends Image implements Di\ConfigAware
|
||||
|
||||
protected $allowedFieldList = ['companyLogo'];
|
||||
|
||||
public function run(Request $request)
|
||||
public function run(Request $request, Response $response) : void
|
||||
{
|
||||
$id = $request->get('id');
|
||||
$size = $request->get('size') ?? null;
|
||||
|
||||
@@ -40,6 +40,7 @@ use Espo\Core\{
|
||||
ORM\EntityManager,
|
||||
ServiceFactory,
|
||||
Api\Request,
|
||||
Api\Response,
|
||||
};
|
||||
|
||||
class Pdf implements EntryPoint
|
||||
@@ -53,7 +54,7 @@ class Pdf implements EntryPoint
|
||||
$this->serviceFactory = $serviceFactory;
|
||||
}
|
||||
|
||||
public function run(Request $request)
|
||||
public function run(Request $request, Response $response) : void
|
||||
{
|
||||
$entityId = $request->get('entityId');
|
||||
$entityType = $request->get('entityType');
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
* 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/.phpppph
|
||||
* along with EspoCRM. If not, see http://www.gnu.org/licenses/.
|
||||
*
|
||||
* The interactive user interfaces in modified source and object code versions
|
||||
* of this program must display Appropriate Legal Notices, as required under
|
||||
@@ -29,12 +29,8 @@
|
||||
|
||||
namespace Espo\Modules\Crm\EntryPoints;
|
||||
|
||||
use Espo\Core\Utils\Util;
|
||||
|
||||
use Espo\Core\Exceptions\NotFound;
|
||||
use Espo\Core\Exceptions\Forbidden;
|
||||
use Espo\Core\Exceptions\BadRequest;
|
||||
use Espo\Core\Exceptions\Error;
|
||||
|
||||
use Espo\Core\EntryPoints\{
|
||||
EntryPoint,
|
||||
@@ -42,6 +38,8 @@ use Espo\Core\EntryPoints\{
|
||||
};
|
||||
|
||||
use Espo\Core\{
|
||||
Api\Request,
|
||||
Api\Response,
|
||||
ORM\EntityManager,
|
||||
ServiceFactory,
|
||||
};
|
||||
@@ -59,10 +57,13 @@ class CampaignTrackOpened implements EntryPoint
|
||||
$this->serviceFactory = $serviceFactory;
|
||||
}
|
||||
|
||||
public function run($request)
|
||||
public function run(Request $request, Response $response) : void
|
||||
{
|
||||
$id = $request->get('id');
|
||||
if (!$id) throw new BadRequest();
|
||||
|
||||
if (!$id) {
|
||||
throw new BadRequest();
|
||||
}
|
||||
|
||||
$queueItemId = $id;
|
||||
|
||||
@@ -83,28 +84,45 @@ class CampaignTrackOpened implements EntryPoint
|
||||
}
|
||||
|
||||
$massEmailId = $queueItem->get('massEmailId');
|
||||
if (!$massEmailId) return;
|
||||
|
||||
if (!$massEmailId) {
|
||||
return;
|
||||
}
|
||||
|
||||
$massEmail = $this->entityManager->getEntity('MassEmail', $massEmailId);
|
||||
if (!$massEmail) return;
|
||||
|
||||
if (!$massEmail) {
|
||||
return;
|
||||
}
|
||||
|
||||
$campaignId = $massEmail->get('campaignId');
|
||||
if (!$campaignId) return;
|
||||
|
||||
if (!$campaignId) {
|
||||
return;
|
||||
}
|
||||
|
||||
$campaign = $this->entityManager->getEntity('Campaign', $campaignId);
|
||||
if (!$campaign) return;
|
||||
|
||||
if (!$campaign) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!$target) {
|
||||
return;
|
||||
}
|
||||
|
||||
$campaignService = $this->serviceFactory->create('Campaign');
|
||||
|
||||
$campaignService->logOpened($campaignId, $queueItemId, $target, null, $queueItem->get('isTest'));
|
||||
|
||||
header('Content-Type: image/png');
|
||||
|
||||
$img = imagecreatetruecolor(1, 1);
|
||||
|
||||
imagesavealpha($img, true);
|
||||
|
||||
$color = imagecolorallocatealpha($img, 127, 127, 127, 127);
|
||||
|
||||
imagefill($img, 0, 0, $color);
|
||||
|
||||
imagepng($img);
|
||||
|
||||
@@ -29,10 +29,7 @@
|
||||
|
||||
namespace Espo\Modules\Crm\EntryPoints;
|
||||
|
||||
use Espo\Core\Utils\Util;
|
||||
|
||||
use Espo\Core\Exceptions\NotFound;
|
||||
use Espo\Core\Exceptions\Forbidden;
|
||||
use Espo\Core\Exceptions\BadRequest;
|
||||
use Espo\Core\Exceptions\Error;
|
||||
|
||||
@@ -42,6 +39,8 @@ use Espo\Core\EntryPoints\{
|
||||
};
|
||||
|
||||
use Espo\Core\{
|
||||
Api\Request,
|
||||
Api\Response,
|
||||
ORM\EntityManager,
|
||||
Utils\ClientManager,
|
||||
HookManager,
|
||||
@@ -61,7 +60,7 @@ class EventConfirmation implements EntryPoint
|
||||
$this->hookManager = $hookManager;
|
||||
}
|
||||
|
||||
public function run($request)
|
||||
public function run(Request $request, Response $response) : void
|
||||
{
|
||||
$uid = $request->get('uid') ?? null;
|
||||
$action = $request->get('action') ?? null;
|
||||
@@ -102,6 +101,7 @@ class EventConfirmation implements EntryPoint
|
||||
|
||||
$status = 'None';
|
||||
$hookMethodName = 'afterConfirmation';
|
||||
|
||||
if ($action == 'accept') {
|
||||
$status = 'Accepted';
|
||||
} else if ($action == 'decline') {
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
* 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/.phpppph
|
||||
* along with EspoCRM. If not, see http://www.gnu.org/licenses/.
|
||||
*
|
||||
* The interactive user interfaces in modified source and object code versions
|
||||
* of this program must display Appropriate Legal Notices, as required under
|
||||
@@ -29,12 +29,8 @@
|
||||
|
||||
namespace Espo\Modules\Crm\EntryPoints;
|
||||
|
||||
use Espo\Core\Utils\Util;
|
||||
|
||||
use Espo\Core\Exceptions\NotFound;
|
||||
use Espo\Core\Exceptions\Forbidden;
|
||||
use Espo\Core\Exceptions\BadRequest;
|
||||
use Espo\Core\Exceptions\Error;
|
||||
|
||||
use Espo\Core\EntryPoints\{
|
||||
EntryPoint,
|
||||
@@ -42,6 +38,8 @@ use Espo\Core\EntryPoints\{
|
||||
};
|
||||
|
||||
use Espo\Core\{
|
||||
Api\Request,
|
||||
Api\Response,
|
||||
ORM\EntityManager,
|
||||
Utils\ClientManager,
|
||||
HookManager,
|
||||
@@ -77,7 +75,7 @@ class SubscribeAgain implements EntryPoint
|
||||
$this->hasher = $hasher;
|
||||
}
|
||||
|
||||
public function run($request)
|
||||
public function run(Request $request, Response $response) : void
|
||||
{
|
||||
$id = $request->get('id') ?? null;
|
||||
$emailAddress = $request->get('emailAddress') ?? null;
|
||||
@@ -92,6 +90,7 @@ class SubscribeAgain implements EntryPoint
|
||||
if (!$id) {
|
||||
throw new BadRequest();
|
||||
}
|
||||
|
||||
$queueItemId = $id;
|
||||
|
||||
$queueItem = $this->entityManager->getEntity('EmailQueueItem', $queueItemId);
|
||||
@@ -104,10 +103,13 @@ class SubscribeAgain implements EntryPoint
|
||||
$target = null;
|
||||
|
||||
$massEmailId = $queueItem->get('massEmailId');
|
||||
|
||||
if ($massEmailId) {
|
||||
$massEmail = $this->entityManager->getEntity('MassEmail', $massEmailId);
|
||||
|
||||
if ($massEmail) {
|
||||
$campaignId = $massEmail->get('campaignId');
|
||||
|
||||
if ($campaignId) {
|
||||
$campaign = $this->entityManager->getEntity('Campaign', $campaignId);
|
||||
}
|
||||
@@ -124,6 +126,7 @@ class SubscribeAgain implements EntryPoint
|
||||
|
||||
if ($massEmail->get('optOutEntirely')) {
|
||||
$emailAddress = $target->get('emailAddress');
|
||||
|
||||
if ($emailAddress) {
|
||||
$ea = $this->entityManager->getRepository('EmailAddress')->getByAddress($emailAddress);
|
||||
|
||||
@@ -190,7 +193,6 @@ class SubscribeAgain implements EntryPoint
|
||||
$this->entityManager->removeEntity($logRecord);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected function display(array $actionData)
|
||||
@@ -214,8 +216,6 @@ class SubscribeAgain implements EntryPoint
|
||||
|
||||
protected function processWithHash(string $emailAddress, string $hash)
|
||||
{
|
||||
$secretKey = $this->config->get('hashSecretKey');
|
||||
|
||||
$hash2 = $this->hasher->hash($emailAddress);
|
||||
|
||||
if ($hash2 !== $hash) {
|
||||
@@ -242,7 +242,8 @@ class SubscribeAgain implements EntryPoint
|
||||
'emailAddress' => $emailAddress,
|
||||
'hash' => $hash,
|
||||
]);
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
throw new NotFound();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,12 +29,8 @@
|
||||
|
||||
namespace Espo\Modules\Crm\EntryPoints;
|
||||
|
||||
use Espo\Core\Utils\Util;
|
||||
|
||||
use Espo\Core\Exceptions\NotFound;
|
||||
use Espo\Core\Exceptions\Forbidden;
|
||||
use Espo\Core\Exceptions\BadRequest;
|
||||
use Espo\Core\Exceptions\Error;
|
||||
|
||||
use Espo\Core\EntryPoints\{
|
||||
EntryPoint,
|
||||
@@ -42,6 +38,8 @@ use Espo\Core\EntryPoints\{
|
||||
};
|
||||
|
||||
use Espo\Core\{
|
||||
Api\Request,
|
||||
Api\Response,
|
||||
ORM\EntityManager,
|
||||
Utils\ClientManager,
|
||||
HookManager,
|
||||
@@ -81,7 +79,7 @@ class Unsubscribe implements EntryPoint
|
||||
$this->serviceFactory = $serviceFactory;
|
||||
}
|
||||
|
||||
public function run($request)
|
||||
public function run(Request $request, Response $response) : void
|
||||
{
|
||||
$id = $request->get('id') ?? null;
|
||||
$emailAddress = $request->get('emailAddress') ?? null;
|
||||
@@ -89,12 +87,14 @@ class Unsubscribe implements EntryPoint
|
||||
|
||||
if ($emailAddress && $hash) {
|
||||
$this->processWithHash($emailAddress, $hash);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (!$id) {
|
||||
throw new BadRequest();
|
||||
}
|
||||
|
||||
$queueItemId = $id;
|
||||
|
||||
$queueItem = $this->entityManager->getEntity('EmailQueueItem', $queueItemId);
|
||||
@@ -107,10 +107,13 @@ class Unsubscribe implements EntryPoint
|
||||
$target = null;
|
||||
|
||||
$massEmailId = $queueItem->get('massEmailId');
|
||||
|
||||
if ($massEmailId) {
|
||||
$massEmail = $this->entityManager->getEntity('MassEmail', $massEmailId);
|
||||
|
||||
if ($massEmail) {
|
||||
$campaignId = $massEmail->get('campaignId');
|
||||
|
||||
if ($campaignId) {
|
||||
$campaign = $this->entityManager->getEntity('Campaign', $campaignId);
|
||||
}
|
||||
@@ -127,8 +130,10 @@ class Unsubscribe implements EntryPoint
|
||||
|
||||
if ($massEmail->get('optOutEntirely')) {
|
||||
$emailAddress = $target->get('emailAddress');
|
||||
|
||||
if ($emailAddress) {
|
||||
$ea = $this->entityManager->getRepository('EmailAddress')->getByAddress($emailAddress);
|
||||
|
||||
if ($ea) {
|
||||
$ea->set('optOut', true);
|
||||
$this->entityManager->saveEntity($ea);
|
||||
@@ -181,6 +186,7 @@ class Unsubscribe implements EntryPoint
|
||||
|
||||
if ($campaign && $target) {
|
||||
$campaignService = $this->serviceFactory->create('Campaign');
|
||||
|
||||
$campaignService->logOptedOut(
|
||||
$campaignId, $queueItemId, $target, $queueItem->get('emailAddress'), null, $queueItem->get('isTest')
|
||||
);
|
||||
@@ -208,8 +214,6 @@ class Unsubscribe implements EntryPoint
|
||||
|
||||
protected function processWithHash(string $emailAddress, string $hash)
|
||||
{
|
||||
$secretKey = $this->config->get('hashSecretKey');
|
||||
|
||||
$hash2 = $this->hasher->hash($emailAddress);
|
||||
|
||||
if ($hash2 !== $hash) {
|
||||
@@ -236,8 +240,8 @@ class Unsubscribe implements EntryPoint
|
||||
'emailAddress' => $emailAddress,
|
||||
'hash' => $hash,
|
||||
]);
|
||||
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
throw new NotFound();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user