<commit_before><?php

namespace app\commands;

use yii\console\Controller;
use app\models\Feed;
use \Yii;

class FeedController extends Controller
{
    public function actionIndex()
    {
        $feeds = Feed::find()->all();

        foreach ($feeds as $feed) {
            $res = Yii::$app->feed->reader()->import($feed->url);
            foreach ($res as $item) {
                var_dump($item->getTitle());
            }
        }
    }
}
<commit_msg>#1 Save last modified date for feed<commit_after><?php

namespace app\commands;

use yii\console\Controller;
use app\models\Feed;
use \Yii;

class FeedController extends Controller
{
    public function actionIndex()
    {
        $feeds = Feed::find()->all();

        foreach ($feeds as $feed) {
            $last_feed_date = $last_modified =  new \DateTime($feed->last_modified);

            /** @var \Zend\Feed\Reader\Reader $reader */
            $reader = Yii::$app->feed->reader();
            $res = $reader->import($feed->url, null, $last_modified);

            foreach ($res as $item) {
                $diff = $item->getDateModified()->diff($last_modified);
                if ($diff->format('%R') == '-') {
                    echo $item->getTitle() . PHP_EOL;

                    $diff = $item->getDateModified()->diff($last_feed_date);
                    if ($diff->format('%R') == '-') {
                        $last_feed_date = $item->getDateModified();
                    }
                }
            }
            $feed->last_modified = $last_feed_date->format('Y-m-d H:i:s');
            $feed->save();
        }
    }
}

{'fraction_non_alphanumeric': 0.16251556662515568, 'fraction_numerical': 0.0006226650062266501, 'mean_word_length': 1.8645276292335116, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 26, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6314982', 'n_tokens_mistral': 483, 'n_tokens_neox': 468, 'n_words': 91}