Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@hissy
Last active June 21, 2022 07:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hissy/eb9079eaac39ac9a43de4db823044e38 to your computer and use it in GitHub Desktop.
Save hissy/eb9079eaac39ac9a43de4db823044e38 to your computer and use it in GitHub Desktop.
#ConcreteCMS A job to clear invalid workflow notifications
<?php
// application/jobs/clear_invalid_workflow_notifications.php
namespace Application\Job;
use Concrete\Core\Entity\Notification\WorkflowProgressNotification;
use Concrete\Core\Job\Job;
use Concrete\Core\Support\Facade\Application;
use Doctrine\ORM\EntityManagerInterface;
class ClearInvalidWorkflowNotifications extends Job
{
public function run()
{
$found = 0;
$removed = 0;
$app = Application::getFacadeApplication();
/** @var EntityManagerInterface $entityManager */
$entityManager = $app->make(EntityManagerInterface::class);
$repository = $entityManager->getRepository(WorkflowProgressNotification::class);
/** @var WorkflowProgressNotification $notification */
foreach ($repository->findAll() as $notification) {
$progress = $notification->getWorkflowProgressObject();
if (!is_object($progress)) {
$entityManager->refresh($notification);
$entityManager->remove($notification);
$entityManager->flush();
$removed++;
}
$found++;
}
return t('%d workflow progress notifications found. %s notifications are invalid and deleted.', $found, $removed);
}
public function getJobName()
{
return t('Clear Invalid Notifications');
}
public function getJobDescription()
{
return t('Fix "Call to a member function getWorkflowObject on null" error');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment