Skip to content

Commit

Permalink
Merge pull request #453 from koillection/1.3
Browse files Browse the repository at this point in the history
1.3
  • Loading branch information
benjaminjonard authored Jul 27, 2022
2 parents 43be0ef + 5d32103 commit e66cba1
Show file tree
Hide file tree
Showing 44 changed files with 436 additions and 195 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/docker-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,6 @@ jobs:
with:
context: .
push: true
build-args: GITHUB_RELEASE=1.3.6
tags: docker.io/koillection/koillection:latest,docker.io/koillection/koillection:1.3.6
build-args: GITHUB_RELEASE=1.3.7
tags: docker.io/koillection/koillection:latest,docker.io/koillection/koillection:1.3.7
platforms: linux/amd64,linux/arm64
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
# Changelog
All notable changes to this project will be documented in this file.

## [1.3.7] / 2022-07-27
### Features
- Add possibility to choose which columns to display in collection list view based on items metadata (Benjamin Jonard)
- Add new choice list type (Benjamin Jonard)
- Add possibility to order s collection's items on text, list and country metadata types (Benjamin Jonard)

### Miscellaneous
- Update JS dependencies, fix CVE-2022-25858 (Benjamin Jonard)
- Remove update logs, add create/delete logs for more entities (Benjamin Jonard)

## [1.3.6] / 2022-07-20
### Features
- Add sorting feature on collections; sorting is available on item name and data of type Date, Number and Rating (Benjamin Jonard)
Expand Down
3 changes: 2 additions & 1 deletion config/services.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
parameters:
release: '1.3.6'
release: '1.3.7'
locale: 'en-GB'
uuid_regex: '[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$'

Expand Down Expand Up @@ -87,6 +87,7 @@ services:
tags:
- { name: doctrine.event_listener, event: prePersist, lazy: true, priority: -5 }
- { name: doctrine.event_listener, event: preRemove, lazy: true, priority: -5 }
- { name: doctrine.event_listener, event: postRemove, lazy: true, priority: -5 }

App\EventListener\VisibilityListener:
tags:
Expand Down
4 changes: 2 additions & 2 deletions fixtures/loans.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ App\Entity\Loan:
loan_admin_{1..5}:
item: "@item_admin_<current()>"
lentTo: "<name()>"
lentAt: <(new \DateTime())>
lentAt: <(new \DateTimeImmutable())>
owner: "@admin"

loan_user_{1..5}:
item: "@item_user_<current()>"
lentTo: "<name()>"
lentAt: <(new \DateTime())>
lentAt: <(new \DateTimeImmutable())>
owner: "@user"
42 changes: 42 additions & 0 deletions migrations/Mysql/Version20220725204054.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

declare(strict_types=1);

namespace App\Migrations\Mysql;

use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;

final class Version20220725204054 extends AbstractMigration
{
public function getDescription(): string
{
return '[Mysql] Change all datetimes to immutable datetimes';
}

public function up(Schema $schema): void
{
$this->skipIf('mysql' !== $this->connection->getDatabasePlatform()->getName(), 'Migration can only be executed safely on \'mysql\'.');

$this->addSql('ALTER TABLE koi_album CHANGE created_at created_at DATETIME NOT NULL COMMENT \'(DC2Type:datetime_immutable)\', CHANGE updated_at updated_at DATETIME DEFAULT NULL COMMENT \'(DC2Type:datetime_immutable)\'');
$this->addSql('ALTER TABLE koi_choice_list CHANGE created_at created_at DATETIME NOT NULL COMMENT \'(DC2Type:datetime_immutable)\', CHANGE updated_at updated_at DATETIME DEFAULT NULL COMMENT \'(DC2Type:datetime_immutable)\'');
$this->addSql('ALTER TABLE koi_collection CHANGE created_at created_at DATETIME NOT NULL COMMENT \'(DC2Type:datetime_immutable)\', CHANGE updated_at updated_at DATETIME DEFAULT NULL COMMENT \'(DC2Type:datetime_immutable)\'');
$this->addSql('ALTER TABLE koi_datum CHANGE created_at created_at DATETIME NOT NULL COMMENT \'(DC2Type:datetime_immutable)\', CHANGE updated_at updated_at DATETIME DEFAULT NULL COMMENT \'(DC2Type:datetime_immutable)\'');
$this->addSql('ALTER TABLE koi_inventory CHANGE created_at created_at DATETIME NOT NULL COMMENT \'(DC2Type:datetime_immutable)\', CHANGE updated_at updated_at DATETIME DEFAULT NULL COMMENT \'(DC2Type:datetime_immutable)\'');
$this->addSql('ALTER TABLE koi_item CHANGE created_at created_at DATETIME NOT NULL COMMENT \'(DC2Type:datetime_immutable)\', CHANGE updated_at updated_at DATETIME DEFAULT NULL COMMENT \'(DC2Type:datetime_immutable)\'');
$this->addSql('ALTER TABLE koi_loan CHANGE lent_at lent_at DATETIME NOT NULL COMMENT \'(DC2Type:datetime_immutable)\', CHANGE returned_at returned_at DATETIME DEFAULT NULL COMMENT \'(DC2Type:datetime_immutable)\'');
$this->addSql('ALTER TABLE koi_log CHANGE logged_at logged_at DATETIME NOT NULL COMMENT \'(DC2Type:datetime_immutable)\'');
$this->addSql('ALTER TABLE koi_photo CHANGE taken_at taken_at DATETIME DEFAULT NULL COMMENT \'(DC2Type:datetime_immutable)\', CHANGE created_at created_at DATETIME NOT NULL COMMENT \'(DC2Type:datetime_immutable)\', CHANGE updated_at updated_at DATETIME DEFAULT NULL COMMENT \'(DC2Type:datetime_immutable)\'');
$this->addSql('ALTER TABLE koi_tag CHANGE created_at created_at DATETIME NOT NULL COMMENT \'(DC2Type:datetime_immutable)\', CHANGE updated_at updated_at DATETIME DEFAULT NULL COMMENT \'(DC2Type:datetime_immutable)\'');
$this->addSql('ALTER TABLE koi_tag_category CHANGE created_at created_at DATETIME NOT NULL COMMENT \'(DC2Type:datetime_immutable)\', CHANGE updated_at updated_at DATETIME DEFAULT NULL COMMENT \'(DC2Type:datetime_immutable)\'');
$this->addSql('ALTER TABLE koi_template CHANGE created_at created_at DATETIME NOT NULL COMMENT \'(DC2Type:datetime_immutable)\', CHANGE updated_at updated_at DATETIME DEFAULT NULL COMMENT \'(DC2Type:datetime_immutable)\'');
$this->addSql('ALTER TABLE koi_user CHANGE last_date_of_activity last_date_of_activity DATE DEFAULT NULL COMMENT \'(DC2Type:date_immutable)\', CHANGE created_at created_at DATETIME NOT NULL COMMENT \'(DC2Type:datetime_immutable)\', CHANGE updated_at updated_at DATETIME DEFAULT NULL COMMENT \'(DC2Type:datetime_immutable)\', CHANGE automatic_dark_mode_start_at automatic_dark_mode_start_at TIME DEFAULT NULL COMMENT \'(DC2Type:time_immutable)\', CHANGE automatic_dark_mode_end_at automatic_dark_mode_end_at TIME DEFAULT NULL COMMENT \'(DC2Type:time_immutable)\'');
$this->addSql('ALTER TABLE koi_wish CHANGE created_at created_at DATETIME NOT NULL COMMENT \'(DC2Type:datetime_immutable)\', CHANGE updated_at updated_at DATETIME DEFAULT NULL COMMENT \'(DC2Type:datetime_immutable)\'');
$this->addSql('ALTER TABLE koi_wishlist CHANGE created_at created_at DATETIME NOT NULL COMMENT \'(DC2Type:datetime_immutable)\', CHANGE updated_at updated_at DATETIME DEFAULT NULL COMMENT \'(DC2Type:datetime_immutable)\'');
}

public function down(Schema $schema): void
{
$this->skipIf(true, 'Always move forward.');
}
}
127 changes: 127 additions & 0 deletions migrations/Postgresql/Version20220725195801.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
<?php

declare(strict_types=1);

namespace App\Migrations\Postgresql;

use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;

final class Version20220725195801 extends AbstractMigration
{
public function getDescription(): string
{
return '[Postgresql] Change all datetimes to immutable datetimes';
}

public function up(Schema $schema): void
{
$this->skipIf('postgresql' !== $this->connection->getDatabasePlatform()->getName(), 'Migration can only be executed safely on \'postgresql\'.');

$this->addSql('ALTER TABLE koi_album ALTER created_at TYPE TIMESTAMP(0) WITHOUT TIME ZONE');
$this->addSql('ALTER TABLE koi_album ALTER created_at DROP DEFAULT');
$this->addSql('ALTER TABLE koi_album ALTER updated_at TYPE TIMESTAMP(0) WITHOUT TIME ZONE');
$this->addSql('ALTER TABLE koi_album ALTER updated_at DROP DEFAULT');
$this->addSql('COMMENT ON COLUMN koi_album.created_at IS \'(DC2Type:datetime_immutable)\'');
$this->addSql('COMMENT ON COLUMN koi_album.updated_at IS \'(DC2Type:datetime_immutable)\'');
$this->addSql('ALTER TABLE koi_choice_list ALTER created_at TYPE TIMESTAMP(0) WITHOUT TIME ZONE');
$this->addSql('ALTER TABLE koi_choice_list ALTER created_at DROP DEFAULT');
$this->addSql('ALTER TABLE koi_choice_list ALTER updated_at TYPE TIMESTAMP(0) WITHOUT TIME ZONE');
$this->addSql('ALTER TABLE koi_choice_list ALTER updated_at DROP DEFAULT');
$this->addSql('COMMENT ON COLUMN koi_choice_list.created_at IS \'(DC2Type:datetime_immutable)\'');
$this->addSql('COMMENT ON COLUMN koi_choice_list.updated_at IS \'(DC2Type:datetime_immutable)\'');
$this->addSql('ALTER TABLE koi_collection ALTER created_at TYPE TIMESTAMP(0) WITHOUT TIME ZONE');
$this->addSql('ALTER TABLE koi_collection ALTER created_at DROP DEFAULT');
$this->addSql('ALTER TABLE koi_collection ALTER updated_at TYPE TIMESTAMP(0) WITHOUT TIME ZONE');
$this->addSql('ALTER TABLE koi_collection ALTER updated_at DROP DEFAULT');
$this->addSql('COMMENT ON COLUMN koi_collection.created_at IS \'(DC2Type:datetime_immutable)\'');
$this->addSql('COMMENT ON COLUMN koi_collection.updated_at IS \'(DC2Type:datetime_immutable)\'');
$this->addSql('ALTER TABLE koi_datum ALTER created_at TYPE TIMESTAMP(0) WITHOUT TIME ZONE');
$this->addSql('ALTER TABLE koi_datum ALTER created_at DROP DEFAULT');
$this->addSql('ALTER TABLE koi_datum ALTER updated_at TYPE TIMESTAMP(0) WITHOUT TIME ZONE');
$this->addSql('ALTER TABLE koi_datum ALTER updated_at DROP DEFAULT');
$this->addSql('COMMENT ON COLUMN koi_datum.created_at IS \'(DC2Type:datetime_immutable)\'');
$this->addSql('COMMENT ON COLUMN koi_datum.updated_at IS \'(DC2Type:datetime_immutable)\'');
$this->addSql('ALTER TABLE koi_inventory ALTER created_at TYPE TIMESTAMP(0) WITHOUT TIME ZONE');
$this->addSql('ALTER TABLE koi_inventory ALTER created_at DROP DEFAULT');
$this->addSql('ALTER TABLE koi_inventory ALTER updated_at TYPE TIMESTAMP(0) WITHOUT TIME ZONE');
$this->addSql('ALTER TABLE koi_inventory ALTER updated_at DROP DEFAULT');
$this->addSql('COMMENT ON COLUMN koi_inventory.created_at IS \'(DC2Type:datetime_immutable)\'');
$this->addSql('COMMENT ON COLUMN koi_inventory.updated_at IS \'(DC2Type:datetime_immutable)\'');
$this->addSql('ALTER TABLE koi_item ALTER created_at TYPE TIMESTAMP(0) WITHOUT TIME ZONE');
$this->addSql('ALTER TABLE koi_item ALTER created_at DROP DEFAULT');
$this->addSql('ALTER TABLE koi_item ALTER updated_at TYPE TIMESTAMP(0) WITHOUT TIME ZONE');
$this->addSql('ALTER TABLE koi_item ALTER updated_at DROP DEFAULT');
$this->addSql('COMMENT ON COLUMN koi_item.created_at IS \'(DC2Type:datetime_immutable)\'');
$this->addSql('COMMENT ON COLUMN koi_item.updated_at IS \'(DC2Type:datetime_immutable)\'');
$this->addSql('ALTER TABLE koi_loan ALTER lent_at TYPE TIMESTAMP(0) WITHOUT TIME ZONE');
$this->addSql('ALTER TABLE koi_loan ALTER lent_at DROP DEFAULT');
$this->addSql('ALTER TABLE koi_loan ALTER returned_at TYPE TIMESTAMP(0) WITHOUT TIME ZONE');
$this->addSql('ALTER TABLE koi_loan ALTER returned_at DROP DEFAULT');
$this->addSql('COMMENT ON COLUMN koi_loan.lent_at IS \'(DC2Type:datetime_immutable)\'');
$this->addSql('COMMENT ON COLUMN koi_loan.returned_at IS \'(DC2Type:datetime_immutable)\'');
$this->addSql('ALTER TABLE koi_log DROP payload');
$this->addSql('ALTER TABLE koi_log ALTER logged_at TYPE TIMESTAMP(0) WITHOUT TIME ZONE');
$this->addSql('ALTER TABLE koi_log ALTER logged_at DROP DEFAULT');
$this->addSql('COMMENT ON COLUMN koi_log.logged_at IS \'(DC2Type:datetime_immutable)\'');
$this->addSql('ALTER TABLE koi_photo ALTER taken_at TYPE TIMESTAMP(0) WITHOUT TIME ZONE');
$this->addSql('ALTER TABLE koi_photo ALTER taken_at DROP DEFAULT');
$this->addSql('ALTER TABLE koi_photo ALTER created_at TYPE TIMESTAMP(0) WITHOUT TIME ZONE');
$this->addSql('ALTER TABLE koi_photo ALTER created_at DROP DEFAULT');
$this->addSql('ALTER TABLE koi_photo ALTER updated_at TYPE TIMESTAMP(0) WITHOUT TIME ZONE');
$this->addSql('ALTER TABLE koi_photo ALTER updated_at DROP DEFAULT');
$this->addSql('COMMENT ON COLUMN koi_photo.taken_at IS \'(DC2Type:datetime_immutable)\'');
$this->addSql('COMMENT ON COLUMN koi_photo.created_at IS \'(DC2Type:datetime_immutable)\'');
$this->addSql('COMMENT ON COLUMN koi_photo.updated_at IS \'(DC2Type:datetime_immutable)\'');
$this->addSql('ALTER TABLE koi_tag ALTER created_at TYPE TIMESTAMP(0) WITHOUT TIME ZONE');
$this->addSql('ALTER TABLE koi_tag ALTER created_at DROP DEFAULT');
$this->addSql('ALTER TABLE koi_tag ALTER updated_at TYPE TIMESTAMP(0) WITHOUT TIME ZONE');
$this->addSql('ALTER TABLE koi_tag ALTER updated_at DROP DEFAULT');
$this->addSql('COMMENT ON COLUMN koi_tag.created_at IS \'(DC2Type:datetime_immutable)\'');
$this->addSql('COMMENT ON COLUMN koi_tag.updated_at IS \'(DC2Type:datetime_immutable)\'');
$this->addSql('ALTER TABLE koi_tag_category ALTER created_at TYPE TIMESTAMP(0) WITHOUT TIME ZONE');
$this->addSql('ALTER TABLE koi_tag_category ALTER created_at DROP DEFAULT');
$this->addSql('ALTER TABLE koi_tag_category ALTER updated_at TYPE TIMESTAMP(0) WITHOUT TIME ZONE');
$this->addSql('ALTER TABLE koi_tag_category ALTER updated_at DROP DEFAULT');
$this->addSql('COMMENT ON COLUMN koi_tag_category.created_at IS \'(DC2Type:datetime_immutable)\'');
$this->addSql('COMMENT ON COLUMN koi_tag_category.updated_at IS \'(DC2Type:datetime_immutable)\'');
$this->addSql('ALTER TABLE koi_template ALTER created_at TYPE TIMESTAMP(0) WITHOUT TIME ZONE');
$this->addSql('ALTER TABLE koi_template ALTER created_at DROP DEFAULT');
$this->addSql('ALTER TABLE koi_template ALTER updated_at TYPE TIMESTAMP(0) WITHOUT TIME ZONE');
$this->addSql('ALTER TABLE koi_template ALTER updated_at DROP DEFAULT');
$this->addSql('COMMENT ON COLUMN koi_template.created_at IS \'(DC2Type:datetime_immutable)\'');
$this->addSql('COMMENT ON COLUMN koi_template.updated_at IS \'(DC2Type:datetime_immutable)\'');
$this->addSql('ALTER TABLE koi_user ALTER created_at TYPE TIMESTAMP(0) WITHOUT TIME ZONE');
$this->addSql('ALTER TABLE koi_user ALTER created_at DROP DEFAULT');
$this->addSql('ALTER TABLE koi_user ALTER updated_at TYPE TIMESTAMP(0) WITHOUT TIME ZONE');
$this->addSql('ALTER TABLE koi_user ALTER updated_at DROP DEFAULT');
$this->addSql('COMMENT ON COLUMN koi_user.created_at IS \'(DC2Type:datetime_immutable)\'');
$this->addSql('COMMENT ON COLUMN koi_user.updated_at IS \'(DC2Type:datetime_immutable)\'');
$this->addSql('ALTER TABLE koi_wish ALTER created_at TYPE TIMESTAMP(0) WITHOUT TIME ZONE');
$this->addSql('ALTER TABLE koi_wish ALTER created_at DROP DEFAULT');
$this->addSql('ALTER TABLE koi_wish ALTER updated_at TYPE TIMESTAMP(0) WITHOUT TIME ZONE');
$this->addSql('ALTER TABLE koi_wish ALTER updated_at DROP DEFAULT');
$this->addSql('COMMENT ON COLUMN koi_wish.created_at IS \'(DC2Type:datetime_immutable)\'');
$this->addSql('COMMENT ON COLUMN koi_wish.updated_at IS \'(DC2Type:datetime_immutable)\'');
$this->addSql('ALTER TABLE koi_wishlist ALTER created_at TYPE TIMESTAMP(0) WITHOUT TIME ZONE');
$this->addSql('ALTER TABLE koi_wishlist ALTER created_at DROP DEFAULT');
$this->addSql('ALTER TABLE koi_wishlist ALTER updated_at TYPE TIMESTAMP(0) WITHOUT TIME ZONE');
$this->addSql('ALTER TABLE koi_wishlist ALTER updated_at DROP DEFAULT');
$this->addSql('COMMENT ON COLUMN koi_wishlist.created_at IS \'(DC2Type:datetime_immutable)\'');
$this->addSql('COMMENT ON COLUMN koi_wishlist.updated_at IS \'(DC2Type:datetime_immutable)\'');
$this->addSql('ALTER TABLE koi_user ALTER automatic_dark_mode_start_at TYPE TIME(0) WITHOUT TIME ZONE');
$this->addSql('ALTER TABLE koi_user ALTER automatic_dark_mode_start_at DROP DEFAULT');
$this->addSql('ALTER TABLE koi_user ALTER automatic_dark_mode_end_at TYPE TIME(0) WITHOUT TIME ZONE');
$this->addSql('ALTER TABLE koi_user ALTER automatic_dark_mode_end_at DROP DEFAULT');
$this->addSql('COMMENT ON COLUMN koi_user.automatic_dark_mode_start_at IS \'(DC2Type:time_immutable)\'');
$this->addSql('COMMENT ON COLUMN koi_user.automatic_dark_mode_end_at IS \'(DC2Type:time_immutable)\'');
$this->addSql('ALTER TABLE koi_user ALTER last_date_of_activity TYPE DATE');
$this->addSql('ALTER TABLE koi_user ALTER last_date_of_activity DROP DEFAULT');
$this->addSql('COMMENT ON COLUMN koi_user.last_date_of_activity IS \'(DC2Type:date_immutable)\'');
}

public function down(Schema $schema): void
{
$this->skipIf(true, 'Always move forward.');
}
}
24 changes: 24 additions & 0 deletions src/Command/RegenerateLogsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,30 @@ protected function execute(InputInterface $input, OutputInterface $output): int

$output->writeln($this->translator->trans('message.logs_generated', ['%count%' => $counter]));

$results = $this->managerRegistry->getManager()->createQueryBuilder()
->select('l.objectId')
->distinct()
->from(Log::class, 'l')
->where('l.type = ?1')
->setParameter(1, LogTypeEnum::TYPE_DELETE)
->getQuery()
->execute()
;

$ids = array_map(function ($result) {
return $result['objectId'];
}, $results);

$this->managerRegistry->getManager()->createQueryBuilder()
->update(Log::class, 'l')
->set('l.objectDeleted', '?1')
->where('l.objectId IN (?2)')
->setParameter(1, true)
->setParameter(2, $ids)
->getQuery()
->execute()
;

return Command::SUCCESS;
}
}
4 changes: 2 additions & 2 deletions src/Controller/Admin/AdminController.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public function index(
)]
public function exportSql(DatabaseDumper $databaseDumper): FileResponse
{
return new FileResponse($databaseDumper->dump(), (new \DateTime())->format('YmdHis').'-koillection-database.sql');
return new FileResponse($databaseDumper->dump(), (new \DateTimeImmutable())->format('YmdHis').'-koillection-database.sql');
}

#[Route(
Expand All @@ -91,7 +91,7 @@ public function exportImages(DatabaseDumper $databaseDumper, UserRepository $use
$options->setFlushOutput(true);
$options->setSendHttpHeaders(true);

$zipFilename = (new \DateTime())->format('YmdHis').'-koillection-images.zip';
$zipFilename = (new \DateTimeImmutable())->format('YmdHis').'-koillection-images.zip';
$zip = new ZipStream($zipFilename, $options);

foreach ($users as $user) {
Expand Down
Loading

0 comments on commit e66cba1

Please sign in to comment.