diff --git a/.env.dist b/.env.dist index 256b9ba..0cc0114 100644 --- a/.env.dist +++ b/.env.dist @@ -37,7 +37,7 @@ DATABASE_URL="mysql://${MYSQL_USER}:${MYSQL_PASSWORD}@database:3306/${MYSQL_DATA ###> symfony/mercure-bundle ### # See https://symfony.com/doc/current/mercure.html#configuration # The URL of the Mercure hub, used by the app to publish updates (can be a local URL) -MERCURE_URL=https://newsroom-php/.well-known/mercure +MERCURE_URL=https://unfold-php/.well-known/mercure # The public URL of the Mercure hub, used by the browser to connect MERCURE_PUBLIC_URL="https://${SERVER_NAME}/.well-known/mercure" # The secret used to sign the JWTs diff --git a/migrations/Version20250729102713.php b/migrations/Version20250729102713.php deleted file mode 100644 index 398c1a3..0000000 --- a/migrations/Version20250729102713.php +++ /dev/null @@ -1,71 +0,0 @@ -addSql(<<<'SQL' - CREATE TABLE app_user (id INT AUTO_INCREMENT NOT NULL, npub VARCHAR(255) NOT NULL, roles JSON DEFAULT NULL, UNIQUE INDEX UNIQ_88BDF3E95FB8BABB (npub), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 - SQL); - $this->addSql(<<<'SQL' - CREATE TABLE article (id INT AUTO_INCREMENT NOT NULL, raw JSON DEFAULT NULL, event_id VARCHAR(225) DEFAULT NULL, slug LONGTEXT DEFAULT NULL, content LONGTEXT DEFAULT NULL, kind INT DEFAULT NULL, title LONGTEXT DEFAULT NULL, summary LONGTEXT DEFAULT NULL, pubkey VARCHAR(255) NOT NULL, created_at DATETIME DEFAULT NULL, sig VARCHAR(255) NOT NULL, image LONGTEXT DEFAULT NULL, published_at DATETIME DEFAULT NULL, topics JSON DEFAULT NULL, event_status INT DEFAULT NULL, current_places JSON DEFAULT NULL, rating_negative INT DEFAULT NULL, rating_positive INT DEFAULT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 - SQL); - $this->addSql(<<<'SQL' - CREATE TABLE event (id VARCHAR(225) NOT NULL, event_id VARCHAR(225) DEFAULT NULL, kind INT NOT NULL, pubkey VARCHAR(255) NOT NULL, content LONGTEXT NOT NULL, created_at BIGINT NOT NULL, tags JSON NOT NULL, sig VARCHAR(255) NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 - SQL); - $this->addSql(<<<'SQL' - CREATE TABLE nzine (id INT AUTO_INCREMENT NOT NULL, npub VARCHAR(255) NOT NULL, main_categories JSON NOT NULL, lists JSON DEFAULT NULL, editor VARCHAR(255) DEFAULT NULL, slug LONGTEXT DEFAULT NULL, state VARCHAR(255) NOT NULL, nzine_bot_id INT DEFAULT NULL, UNIQUE INDEX UNIQ_65025D9871FD5427 (nzine_bot_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 - SQL); - $this->addSql(<<<'SQL' - CREATE TABLE nzine_bot (id INT AUTO_INCREMENT NOT NULL, encrypted_nsec VARCHAR(255) NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 - SQL); - $this->addSql(<<<'SQL' - CREATE TABLE sessions (sess_id VARBINARY(128) NOT NULL, sess_data LONGBLOB NOT NULL, sess_lifetime INT UNSIGNED NOT NULL, sess_time INT UNSIGNED NOT NULL, INDEX sess_lifetime_idx (sess_lifetime), PRIMARY KEY(sess_id)) DEFAULT CHARACTER SET utf8mb4 ENGINE = InnoDB - SQL); - $this->addSql(<<<'SQL' - ALTER TABLE nzine ADD CONSTRAINT FK_65025D9871FD5427 FOREIGN KEY (nzine_bot_id) REFERENCES nzine_bot (id) - SQL); - } - - public function down(Schema $schema): void - { - // this down() migration is auto-generated, please modify it to your needs - $this->addSql(<<<'SQL' - ALTER TABLE nzine DROP FOREIGN KEY FK_65025D9871FD5427 - SQL); - $this->addSql(<<<'SQL' - DROP TABLE app_user - SQL); - $this->addSql(<<<'SQL' - DROP TABLE article - SQL); - $this->addSql(<<<'SQL' - DROP TABLE event - SQL); - $this->addSql(<<<'SQL' - DROP TABLE nzine - SQL); - $this->addSql(<<<'SQL' - DROP TABLE nzine_bot - SQL); - $this->addSql(<<<'SQL' - DROP TABLE sessions - SQL); - } -} diff --git a/migrations/Version20250729122617.php b/migrations/Version20250729122617.php new file mode 100644 index 0000000..c6ce605 --- /dev/null +++ b/migrations/Version20250729122617.php @@ -0,0 +1,37 @@ +addSql('CREATE TABLE app_user (id INT NOT NULL, npub VARCHAR(255) NOT NULL, roles JSON DEFAULT NULL, UNIQUE INDEX UNIQ_88BDF3E95FB8BABB (npub), PRIMARY KEY (id)) DEFAULT CHARACTER SET utf8mb4'); + $this->addSql('CREATE TABLE article (id INT NOT NULL, raw JSON DEFAULT NULL, event_id VARCHAR(225) DEFAULT NULL, slug LONGTEXT DEFAULT NULL, content LONGTEXT DEFAULT NULL, kind INT DEFAULT NULL, title LONGTEXT DEFAULT NULL, summary LONGTEXT DEFAULT NULL, pubkey VARCHAR(255) NOT NULL, created_at DATETIME DEFAULT NULL, sig VARCHAR(255) NOT NULL, image LONGTEXT DEFAULT NULL, published_at DATETIME DEFAULT NULL, topics JSON DEFAULT NULL, event_status INT DEFAULT NULL, current_places JSON DEFAULT NULL, rating_negative INT DEFAULT NULL, rating_positive INT DEFAULT NULL, PRIMARY KEY (id)) DEFAULT CHARACTER SET utf8mb4'); + $this->addSql('CREATE TABLE event (id VARCHAR(225) NOT NULL, event_id VARCHAR(225) DEFAULT NULL, kind INT NOT NULL, pubkey VARCHAR(255) NOT NULL, content LONGTEXT NOT NULL, created_at BIGINT NOT NULL, tags JSON NOT NULL, sig VARCHAR(255) NOT NULL, PRIMARY KEY (id)) DEFAULT CHARACTER SET utf8mb4'); + $this->addSql('CREATE TABLE sessions (sess_id VARBINARY(128) NOT NULL, sess_data LONGBLOB NOT NULL, sess_lifetime INT UNSIGNED NOT NULL, sess_time INT UNSIGNED NOT NULL, INDEX sess_lifetime_idx (sess_lifetime), PRIMARY KEY (sess_id)) DEFAULT CHARACTER SET utf8mb4 ENGINE = InnoDB'); + } + + public function down(Schema $schema): void + { + // this down() migration is auto-generated, please modify it to your needs + $this->addSql('DROP TABLE app_user'); + $this->addSql('DROP TABLE article'); + $this->addSql('DROP TABLE event'); + $this->addSql('DROP TABLE sessions'); + } +} diff --git a/migrations/Version20250729122903.php b/migrations/Version20250729122903.php new file mode 100644 index 0000000..b31eb1e --- /dev/null +++ b/migrations/Version20250729122903.php @@ -0,0 +1,33 @@ +addSql('ALTER TABLE app_user CHANGE id id INT AUTO_INCREMENT NOT NULL'); + $this->addSql('ALTER TABLE article CHANGE id id INT AUTO_INCREMENT NOT NULL'); + } + + public function down(Schema $schema): void + { + // this down() migration is auto-generated, please modify it to your needs + $this->addSql('ALTER TABLE app_user CHANGE id id INT NOT NULL'); + $this->addSql('ALTER TABLE article CHANGE id id INT NOT NULL'); + } +} diff --git a/src/Controller/DefaultController.php b/src/Controller/DefaultController.php index e431ffd..0ea1042 100644 --- a/src/Controller/DefaultController.php +++ b/src/Controller/DefaultController.php @@ -31,6 +31,14 @@ class DefaultController extends AbstractController $mag = $this->redisCache->get('magazine-newsroom-magazine-by-newsroom', function (){ return null; }); + + // Handle case when magazine is not found + if ($mag === null) { + return $this->render('home.html.twig', [ + 'indices' => [] + ]); + } + $tags = $mag->getTags(); $cats = array_filter($tags, function($tag) { diff --git a/src/Entity/Article.php b/src/Entity/Article.php index f7e9a20..1b522b8 100644 --- a/src/Entity/Article.php +++ b/src/Entity/Article.php @@ -18,8 +18,8 @@ use Doctrine\ORM\Mapping as ORM; class Article { #[ORM\Id] - #[ORM\GeneratedValue] - #[ORM\Column(length: 225)] + #[ORM\GeneratedValue(strategy: 'IDENTITY')] + #[ORM\Column] private ?int $id = null; #[ORM\Column(type: Types::JSON, nullable: true)] diff --git a/src/Entity/User.php b/src/Entity/User.php index 5b4c6ce..a3423af 100644 --- a/src/Entity/User.php +++ b/src/Entity/User.php @@ -16,7 +16,7 @@ use Symfony\Component\Security\Core\User\UserInterface; class User implements UserInterface, EquatableInterface { #[ORM\Id] - #[ORM\GeneratedValue] + #[ORM\GeneratedValue(strategy: 'IDENTITY')] #[ORM\Column] private ?int $id = null; diff --git a/src/Service/EncryptionService.php b/src/Service/EncryptionService.php deleted file mode 100644 index cf788af..0000000 --- a/src/Service/EncryptionService.php +++ /dev/null @@ -1,36 +0,0 @@ -encryptionKey = $bag->get('encryption_key'); - } - - public function encrypt(string $data): string - { - return openssl_encrypt($data, 'aes-256-cbc', $this->encryptionKey, 0, $this->getIv()); - } - - public function decrypt(string $encryptedData): string - { - return openssl_decrypt($encryptedData, 'aes-256-cbc', $this->encryptionKey, 0, $this->getIv()); - } - - private function getIv(): string - { - return substr(hash('sha256', $this->encryptionKey), 0, 16); // AES-256 requires a 16-byte IV - } -} diff --git a/src/Service/NostrClient.php b/src/Service/NostrClient.php index 1b4d6b5..9f74553 100644 --- a/src/Service/NostrClient.php +++ b/src/Service/NostrClient.php @@ -424,7 +424,7 @@ class NostrClient // Create request using the helper method $request = $this->createNostrRequest( - kinds: [KindsEnum::COMMENTS->value, KindsEnum::TEXT_NOTE->value], + kinds: [KindsEnum::COMMENTS->value], filters: ['tag' => ['#A', [$coordinate]]], relaySet: $relaySet ); diff --git a/src/Twig/Components/Header.php b/src/Twig/Components/Header.php index 18402b8..7d9f132 100644 --- a/src/Twig/Components/Header.php +++ b/src/Twig/Components/Header.php @@ -22,6 +22,12 @@ class Header return null; }); + // Handle case when magazine is not found + if ($mag === null) { + $this->cats = []; + return; + } + $tags = $mag->getTags(); $this->cats = array_filter($tags, function($tag) {