Skip to content

Commit

Permalink
Add my logger
Browse files Browse the repository at this point in the history
  • Loading branch information
zkabic committed Nov 8, 2023
1 parent 197ac25 commit 786047e
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,15 @@ public function __construct(SettingsManagerInterface $settingsManager, TenantCon

public function setUpdateAtDate(ArticleEvent $event): void
{
SwpLogger::log('Listener is in use :-) ....');
$article = $event->getArticle();
/**
* @var ?ArticleExtraTextField $dontUpdateDate
*/
$dontUpdateDate = $article->getExtraByKey('dont_change_updated_at') ?? null;
SwpLogger::log('Dont update date is type of: ' . gettype($dontUpdateDate));
if ($dontUpdateDate instanceof ArticleExtraTextField && strtolower($dontUpdateDate->getValue()) === 'on') {
SwpLogger::log('Dont update date: ' . $dontUpdateDate->getValue());
$article->cancelTimestampable();
}
}
Expand Down
3 changes: 3 additions & 0 deletions src/SWP/Bundle/CoreBundle/Service/ArticlePublisher.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
use SWP\Bundle\CoreBundle\Model\PublishDestinationInterface;
use SWP\Bundle\CoreBundle\Model\TenantInterface;
use SWP\Bundle\CoreBundle\Repository\ContentListItemRepository;
use SWP\Bundle\CoreBundle\Util\SwpLogger;
use SWP\Component\Bridge\Events;
use SWP\Component\ContentList\Model\ContentListInterface;
use SWP\Component\ContentList\Repository\ContentListRepositoryInterface;
Expand Down Expand Up @@ -136,7 +137,9 @@ public function publish(PackageInterface $package, CompositePublishActionInterfa
$article->setPublishedToAppleNews($destination->isPublishedToAppleNews());
$this->eventDispatcher->dispatch(new GenericEvent($article), Events::SWP_VALIDATION);
$this->eventDispatcher->dispatch(new ArticleEvent($article, $package, ArticleEvents::PRE_UPDATE, $article->getRoute()), ArticleEvents::PRE_UPDATE);
SwpLogger::log('PRE_UPDATE before flush: ' . ($article->isTimestampableCanceled() ? 'Y' : 'N'));
$this->articleRepository->flush();
SwpLogger::log('PRE_UPDATE after flush: ' . ($article->isTimestampableCanceled() ? 'Y' : 'N'));

if ($destination->isPublished()) {
$this->eventDispatcher->dispatch(new ArticleEvent($article, $package, ArticleEvents::PUBLISH), ArticleEvents::PUBLISH);
Expand Down
20 changes: 20 additions & 0 deletions src/SWP/Bundle/CoreBundle/Util/SwpLogger.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

namespace SWP\Bundle\CoreBundle\Util;

class SwpLogger
{

public static function log(string $message,bool $echo = false, string $fileName = 'swp.log')
{
$trace = debug_backtrace()[1];
$message = '[' . date('Y-m-d H:i:s') . '][' . $trace['class'] . '::' . $trace['function'] . '] ' . $message . PHP_EOL;

if (!empty($fileName)) {
file_put_contents('/tmp/' . $fileName, $message, FILE_APPEND);
}
if ($echo) {
echo $message;
}
}
}

0 comments on commit 786047e

Please sign in to comment.