0
내가 Symfony2에서 만든 콘솔 명령을 시도 :콘솔 스크립트가 작동 중임을 감지하는 가장 좋은 방법은 무엇입니까?
class UpdateCommentsCommand extends ContainerAwareCommand
{
protected function configure()
{
$this->setName('comments:update')
->setDescription('Update comments');
->addArgument('force', InputArgument::OPTIONAL, 'force', false)
}
protected function execute(InputInterface $input, OutputInterface $output)
{
if (!$input->getArgument('force') && if $flag_this_script_is_active) {
return;
}
$flag_this_script_is_active = True
$em = $this->getContainer()->get('doctrine')->getEntityManager();
// Bad comments
$update_commang = $em->createQuery("
UPDATE MyBundle:CommentsAll AS c
SET
c.is_automoderated = 1
WHERE
bla_bla_bla LIMIT 100
");
$result = $update_commang->getResult();
if ($result > 0) {
//Re-run this script with --force argument
} else {
$flag_this_script_is_active = false
}
}
}
모든 commnets가 변경됩니다 쭈으로 60 초마다 실행 전까지 진행이 스크립트 is_automoderated = 1
이전 스크립트가 이상이 아닌 경우 , 다음 스크립트는 그것을보고 실행되지 않습니다.
이제 플래그를 설정하는 방법을 알고 싶습니다. $flag_this_script_is_active
. 일부 파일을 만들고 스크립트가 끝난 후 삭제하고 싶습니다. 그러나 아마도 더 좋은 방법이있을 것입니다. symfony의 기능 중 일부입니까?
답변 해 주셔서 감사합니다. 크로스 플랫폼 솔루션을 사용하고 싶습니다. 그것이 프레임 워크에 고유 한 것이 바람직합니다. – Dmitry