Last active
June 21, 2022 07:49
-
-
Save hissy/eb9079eaac39ac9a43de4db823044e38 to your computer and use it in GitHub Desktop.
#ConcreteCMS A job to clear invalid workflow notifications
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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