Skip to content

Releases: cdaecke/md_unreadnews

Last release

05 Aug 13:07

Choose a tag to compare

Last release.

This extension was replaced by ext:md_notifications. For TYPO3 v12 and newer, please use the versatile extension ext:md_notifications instead!

Migrate existing md_unreadnews records to new md_notifications records:

  • Add temporary the following command in your own site extension (packages/your_site_extension/Classes/Command/UnreadNewsImportCommand.php)
  • Adapt the namespace on the class
  • Clear TYPO3 cache
  • Execute the command: ./typo3 unreadnews:import

After you have executed the command, you can remove the class again.

<?php

declare(strict_types=1);

namespace Vendor\Namespace\Command;

use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

// Run `./typo3 unreadnews:import` for executing this command

#[AsCommand(
    name: 'unreadnews:import',
    description: 'Imports unread news entries into tx_mdnotifications with JSON data.',
)]
class UnreadNewsImportCommand extends Command
{
    protected function configure(): void
    {
        $this->setName('unreadnews:import')
            ->setDescription('Imports unread news entries into tx_mdnotifications with JSON data.');
    }

    public function execute(InputInterface $input, OutputInterface $output): int
    {
        $output->writeln('<info>Starting unread news import...</info>');

        $connection = GeneralUtility::makeInstance(ConnectionPool::class)
            ->getConnectionForTable('tx_mdunreadnews_domain_model_unreadnews');

        $newsConnection = GeneralUtility::makeInstance(ConnectionPool::class)
            ->getConnectionForTable('tx_news_domain_model_news');

        $notificationConnection = GeneralUtility::makeInstance(ConnectionPool::class)
            ->getConnectionForTable('tx_mdnotifications_domain_model_notification');

        // 1. Get unread entries
        $unreadItems = $connection->select(
            ['pid', 'news', 'feuser', 'news_datetime', 'tstamp', 'crdate', 'deleted', 'hidden', 'starttime', 'endtime', 'news_datetime'],
            'tx_mdunreadnews_domain_model_unreadnews'
        )->fetchAllAssociative();

        $insertCount = 0;

        foreach ($unreadItems as $item) {

            // Optional: Check for duplicates
            $exists = $notificationConnection->select(
                ['uid'],
                'tx_mdnotifications_domain_model_notification',
                [
                    'record_key' => 'tx_news_domain_model_news',
                    'record_id' => $item['news'],
                    'feuser' => $item['feuser']
                ]
            )->fetchOne();

            if ($exists) {
                continue;
            }

            // 2. Get news
            $news = $newsConnection->select(
                [
                    'uid',
                    'pid',
                    'title',
                    'teaser',
                    'bodytext',
                    'datetime',
                    'type',
                    'internalurl',
                    'externalurl'
                ],
                'tx_news_domain_model_news',
                ['uid' => (int)$item['news']]
            )->fetchAssociative();

            if (!$news) {
                continue;
            }

            // 3. Generate JSON
            $json = json_encode($news, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);

            // 4. Insert in notifications
            $notificationConnection->insert(
                'tx_mdnotifications_domain_model_notification',
                [
                    'pid' => $item['pid'],
                    'tstamp' => $item['tstamp'],
                    'crdate' => $item['crdate'],
                    'deleted' => $item['deleted'],
                    'hidden' => $item['hidden'],
                    'starttime' => $item['starttime'],
                    'endtime' => $item['endtime'],
                    'record_key' => 'tx_news_domain_model_news',
                    'record_id' => (int)$item['news'],
                    'record_date' => (int)$item['news_datetime'],
                    'feuser' => (int)$item['feuser'],
                    'data' => $json
                ]
            );

            $insertCount++;
        }

        $output->writeln('<info>Finished. Inserted ' . $insertCount . ' notifications.</info>');

        return Command::SUCCESS;
    }
}

Maintenance release

15 Dec 12:51

Choose a tag to compare

  • [TASK] Update dependency to ext:news (allow ext:news v12)

All changes
5.0.1...5.0.2

TYPO3 v12 compatibility

15 Jul 09:29

Choose a tag to compare

  • [TASK] TYPO3 v12 compatibility

All changes
4.0.1...5.0.0

Maintenance release

11 Nov 09:48

Choose a tag to compare

  • [TASK] Update dependency to new version of ext:news.

All changes
4.0.0...4.0.1

TYPO3 11 compatibility

29 Dec 22:05

Choose a tag to compare

  • [FEATURE] TYPO3 11 compatibility
  • [TASK] Dependency to ext:numbered_pagination was added.

BREAKING

  • List.html-Template was changed.
  • New paginator was introduced, so partial needs to be change, if you use your own.

Important

Clear cache in install tool, in oder to get everything working!

All changes
3.0.1...4.0.0