-
-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #830 from glensc/register-legacy-extensions
- Loading branch information
Showing
12 changed files
with
308 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
db/migrations/20200505135053_register_legacy_extensions.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Eventum (Issue Tracking System) package. | ||
* | ||
* @copyright (c) Eventum Team | ||
* @license GNU General Public License, version 2 or later (GPL-2+) | ||
* | ||
* For the full copyright and license information, | ||
* please see the COPYING and AUTHORS files | ||
* that were distributed with this source code. | ||
*/ | ||
|
||
use Eventum\Db\AbstractMigration; | ||
use Eventum\Extension\Legacy; | ||
use Eventum\Extension\RegisterExtension; | ||
|
||
class RegisterLegacyExtensions extends AbstractMigration | ||
{ | ||
private const EXTENSIONS = [ | ||
Legacy\CustomerLegacyExtension::class, | ||
Legacy\WorkflowLegacyExtension::class, | ||
]; | ||
|
||
public function up(): void | ||
{ | ||
$register = new RegisterExtension(); | ||
$register->register(...self::EXTENSIONS); | ||
} | ||
|
||
public function down(): void | ||
{ | ||
$register = new RegisterExtension(); | ||
$register->unregister(...self::EXTENSIONS); | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
db/migrations/20200506031942_eventum_register_audit_trail_extension.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Eventum (Issue Tracking System) package. | ||
* | ||
* @copyright (c) Eventum Team | ||
* @license GNU General Public License, version 2 or later (GPL-2+) | ||
* | ||
* For the full copyright and license information, | ||
* please see the COPYING and AUTHORS files | ||
* that were distributed with this source code. | ||
*/ | ||
|
||
use Eventum\Db\AbstractMigration; | ||
use Eventum\Extension\AuditTrailExtension; | ||
use Eventum\Extension\RegisterExtension; | ||
use Eventum\ServiceContainer; | ||
|
||
class EventumRegisterAuditTrailExtension extends AbstractMigration | ||
{ | ||
private const EXTENSION = AuditTrailExtension::class; | ||
|
||
public function up(): void | ||
{ | ||
$enabled = ServiceContainer::getConfig()['audit_trail'] === 'enabled'; | ||
if (!$enabled) { | ||
return; | ||
} | ||
|
||
$register = new RegisterExtension(); | ||
$register->register(self::EXTENSION); | ||
} | ||
|
||
public function down(): void | ||
{ | ||
$register = new RegisterExtension(); | ||
$register->unregister(self::EXTENSION); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Eventum (Issue Tracking System) package. | ||
* | ||
* @copyright (c) Eventum Team | ||
* @license GNU General Public License, version 2 or later (GPL-2+) | ||
* | ||
* For the full copyright and license information, | ||
* please see the COPYING and AUTHORS files | ||
* that were distributed with this source code. | ||
*/ | ||
|
||
namespace Eventum\Extension; | ||
|
||
use Date_Helper; | ||
use DB_Helper; | ||
use Eventum\Db\DatabaseException; | ||
use Eventum\Event\ResultableEvent; | ||
use Eventum\Event\SystemEvents; | ||
use Symfony\Component\EventDispatcher\EventSubscriberInterface; | ||
|
||
class AuditTrailExtension implements Provider\SubscriberProvider, EventSubscriberInterface | ||
{ | ||
public function getSubscribers(): array | ||
{ | ||
return [ | ||
self::class, | ||
]; | ||
} | ||
|
||
public static function getSubscribedEvents(): array | ||
{ | ||
return [ | ||
/** @see AuditTrailExtension::canAccessIssue */ | ||
// This should be with lowest priority to log final result | ||
SystemEvents::ACCESS_ISSUE => ['canAccessIssue', PHP_INT_MIN], | ||
]; | ||
} | ||
|
||
/** | ||
* @see Workflow::canAccessIssue | ||
*/ | ||
public function canAccessIssue(ResultableEvent $event): void | ||
{ | ||
if (!$event['internal']) { | ||
$this->log($event->getResult(), $event['issue_id'], $event['usr_id'], $_SERVER['REQUEST_URI'] ?? ''); | ||
} | ||
} | ||
|
||
private function log(bool $return, int $issue_id, int $usr_id, string $url): void | ||
{ | ||
[$item, $item_id] = $this->extractInfoFromURL($url); | ||
|
||
$sql = 'INSERT INTO | ||
`issue_access_log` | ||
SET | ||
alg_iss_id = ?, | ||
alg_usr_id = ?, | ||
alg_created = ?, | ||
alg_ip_address = ?, | ||
alg_failed = ?, | ||
alg_item = ?, | ||
alg_item_id = ?, | ||
alg_url = ?'; | ||
$params = [ | ||
$issue_id, | ||
$usr_id, | ||
Date_Helper::getCurrentDateGMT(), | ||
$_SERVER['REMOTE_ADDR'] ?? null, | ||
(int)!$return, | ||
$item, | ||
$item_id, | ||
$url, | ||
]; | ||
try { | ||
DB_Helper::getInstance()->query($sql, $params); | ||
} catch (DatabaseException $e) { | ||
// do nothing besides log it | ||
} | ||
} | ||
|
||
private function extractInfoFromURL(string $url) | ||
{ | ||
if (preg_match("/view_note\.php\?id=(?P<item_id>\d+)/", $url, $matches)) { | ||
return ['note', $matches[1]]; | ||
} | ||
|
||
if (preg_match("/view_email\.php\?ema_id=\d+&id=(?P<item_id>\d+)/", $url, $matches)) { | ||
return ['email', $matches[1]]; | ||
} | ||
|
||
if (preg_match("/download\.php\?cat=attachment&id=(?P<item_id>\d+)/", $url, $matches)) { | ||
return ['file', $matches[1]]; | ||
} | ||
|
||
if (preg_match("/update\.php/", $url, $matches)) { | ||
return ['update', null]; | ||
} | ||
|
||
return [null, null]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Eventum (Issue Tracking System) package. | ||
* | ||
* @copyright (c) Eventum Team | ||
* @license GNU General Public License, version 2 or later (GPL-2+) | ||
* | ||
* For the full copyright and license information, | ||
* please see the COPYING and AUTHORS files | ||
* that were distributed with this source code. | ||
*/ | ||
|
||
namespace Eventum\Extension\Legacy; | ||
|
||
use Eventum\Extension\Provider; | ||
|
||
/** | ||
* Extension that adds integration of legacy Customer classes to Extension events | ||
*/ | ||
class CustomerLegacyExtension implements Provider\SubscriberProvider | ||
{ | ||
public function getSubscribers(): array | ||
{ | ||
return [ | ||
]; | ||
} | ||
} |
Oops, something went wrong.