-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ref #5: enable Gedmo Loggable & log User attributes
- Loading branch information
Showing
6 changed files
with
81 additions
and
0 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
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,33 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace DoctrineMigrations; | ||
|
||
use Doctrine\DBAL\Schema\Schema; | ||
use Doctrine\Migrations\AbstractMigration; | ||
|
||
final class Version20240326220159 extends AbstractMigration | ||
{ | ||
public function getDescription(): string | ||
{ | ||
return 'Create activity logs table'; | ||
} | ||
|
||
public function up(Schema $schema): void | ||
{ | ||
$this->addSql('CREATE SEQUENCE log_activity_id_seq INCREMENT BY 1 MINVALUE 1 START 1'); | ||
$this->addSql('CREATE TABLE log_activity (id INT NOT NULL, action VARCHAR(8) NOT NULL, logged_at TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL, object_id VARCHAR(64) DEFAULT NULL, object_class VARCHAR(191) NOT NULL, version INT NOT NULL, data TEXT DEFAULT NULL, username VARCHAR(191) DEFAULT NULL, PRIMARY KEY(id))'); | ||
$this->addSql('CREATE INDEX log_activity_user_index ON log_activity (username)'); | ||
$this->addSql('CREATE INDEX log_activity_class_index ON log_activity (object_class)'); | ||
$this->addSql('CREATE INDEX log_activity_date_index ON log_activity (logged_at)'); | ||
$this->addSql('CREATE INDEX log_activity_version_index ON log_activity (object_id, object_class, version)'); | ||
$this->addSql('COMMENT ON COLUMN log_activity.data IS \'(DC2Type:array)\''); | ||
} | ||
|
||
public function down(Schema $schema): void | ||
{ | ||
$this->addSql('DROP SEQUENCE log_activity_id_seq CASCADE'); | ||
$this->addSql('DROP TABLE log_activity'); | ||
} | ||
} |
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,16 @@ | ||
<?php | ||
|
||
namespace App\Entity; | ||
|
||
use App\Repository\LogActivityRepository; | ||
use Doctrine\ORM\Mapping as ORM; | ||
use Gedmo\Loggable\Entity\MappedSuperclass\AbstractLogEntry; | ||
|
||
#[ORM\Entity(repositoryClass: LogActivityRepository::class)] | ||
#[ORM\Index(columns: ['username'], name: 'log_activity_user_index')] | ||
#[ORM\Index(columns: ['object_class'], name: 'log_activity_class_index')] | ||
#[ORM\Index(columns: ['logged_at'], name: 'log_activity_date_index')] | ||
#[ORM\Index(columns: ['object_id', 'object_class', 'version'], name: 'log_activity_version_index')] | ||
class LogActivity extends AbstractLogEntry | ||
{ | ||
} |
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,25 @@ | ||
<?php | ||
|
||
namespace App\Repository; | ||
|
||
use App\Entity\LogActivity; | ||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepositoryInterface; | ||
use Doctrine\Persistence\ManagerRegistry; | ||
use Gedmo\Loggable\Entity\Repository\LogEntryRepository; | ||
|
||
/** | ||
* @implements ServiceEntityRepositoryInterface<LogActivity> | ||
* | ||
* @method LogActivity|null find($id, $lockMode = null, $lockVersion = null) | ||
* @method LogActivity|null findOneBy(array $criteria, array $orderBy = null) | ||
* @method LogActivity[] findAll() | ||
* @method LogActivity[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null) | ||
*/ | ||
class LogActivityRepository extends LogEntryRepository implements ServiceEntityRepositoryInterface | ||
{ | ||
public function __construct(ManagerRegistry $registry) | ||
{ | ||
$logActivityManager = $registry->getManagerForClass(LogActivity::class); | ||
parent::__construct($logActivityManager, $logActivityManager->getClassMetadata(LogActivity::class)); | ||
} | ||
} |