Skip to content

Commit

Permalink
Merge branch '5.x' into 6.x
Browse files Browse the repository at this point in the history
  • Loading branch information
angrybrad committed Feb 7, 2025
2 parents 7841091 + dd7b603 commit 475d76f
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 2 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
- Added support for viewing read-only settings on environments where `allowAdminChanges` is disabled. ([#1592](https://github.com/craftcms/feed-me/issues/1592))
- Improved the experience of mapping relational fields with individual field instances in Craft 5. ([#1585](https://github.com/craftcms/feed-me/issues/1585))
- Feed Me settings are now only available to admins and when `allowAdminChanges` is set to `true`. ([#1581](https://github.com/craftcms/feed-me/pull/1581))
- Added support for Craft [Time](https://craftcms.com/docs/5.x/reference/field-types/time.html) fields. ([#1593](https://github.com/craftcms/feed-me/pull/1593))
- Added support for Craft [Time](https://craftcms.com/docs/5.x/reference/field-types/time.html) fields. ([#1593](https://github.com/craftcms/feed-me/pull/1593))
- Added support for `formatted` and `raw` subfields in the Google Maps plugin. ([#1587](https://github.com/craftcms/feed-me/pull/1587))
- Fixed a bug where excessive logs would be generated in the Feed Me logs table in the database. ([#1594](https://github.com/craftcms/feed-me/pull/1594))
- Fixed a bug where empty values were not respected for inner-element fields when `setEmptyValues` is set to `true`. ([#1590](https://github.com/craftcms/feed-me/pull/1590))
- Fixed a bug where values with an empty string would not be treated as empty if `setEmtpyValues` is set to `true`. ([#1591](https://github.com/craftcms/feed-me/pull/1591))

Expand Down
13 changes: 13 additions & 0 deletions src/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use craft\feedme\web\twig\Extension;
use craft\feedme\web\twig\variables\FeedMeVariable;
use craft\helpers\UrlHelper;
use craft\services\Gc;
use craft\web\twig\variables\CraftVariable;
use craft\web\UrlManager;
use yii\base\Event;
Expand Down Expand Up @@ -91,6 +92,7 @@ public function init(): void
$this->_registerCpRoutes();
$this->_registerTwigExtensions();
$this->_registerVariables();
$this->_registerGc();
}

/**
Expand Down Expand Up @@ -183,4 +185,15 @@ private function _registerVariables(): void
$event->sender->set('feedme', FeedMeVariable::class);
});
}

private function _registerGc(): void
{
Event::on(
Gc::class,
Gc::EVENT_RUN,
function(Event $event) {
$this->getLogs()->prune();
}
);
}
}
19 changes: 18 additions & 1 deletion src/services/Logs.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ class Logs extends Component

public const LOG_CATEGORY = 'feed-me';
public const LOG_TABLE = '{{%feedme_logs}}';
public const LOG_TABLE_LIMIT = 300;

public const LOG_LEVEL_MAP = [
Logger::LEVEL_ERROR => 'error',
Expand Down Expand Up @@ -124,6 +125,22 @@ public function clear(): void
->execute();
}

public function prune(): void
{
$ids = (new Query())
->select(['id'])
->from(self::LOG_TABLE)
->orderBy(['log_time' => SORT_DESC])
->limit(self::LOG_TABLE_LIMIT)
->column();

if (count($ids)) {
Craft::$app->getDb()->createCommand()
->delete(self::LOG_TABLE, ['not', ['in', 'id', $ids]])
->execute();
}
}

/**
* @param null $type
* @return array
Expand All @@ -138,7 +155,7 @@ public function getLogEntries($type = null): array
->from(self::LOG_TABLE)

// Hard-coded until pagination is implemented
->limit(300);
->limit(self::LOG_TABLE_LIMIT);

if ($type) {
$query->andWhere(['level' => self::logLevelInt($type)]);
Expand Down
2 changes: 2 additions & 0 deletions src/services/Process.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ public function beforeProcessFeed(FeedModel $feed, array $feedData)
$gc = Craft::$app->getGc();
$gc->deleteAllTrashed = true;
$gc->run(true);
} else {
Plugin::getInstance()->getLogs()->prune();
}

$this->_data = $feedData;
Expand Down

0 comments on commit 475d76f

Please sign in to comment.