Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CronExprParser Exception #5

Closed
BnitoBzh opened this issue May 30, 2013 · 3 comments
Closed

CronExprParser Exception #5

BnitoBzh opened this issue May 30, 2013 · 3 comments

Comments

@BnitoBzh
Copy link

My application throw an exception for one cron task :
( The application has thrown an exception!)
(======================================================================)
( invalid cron expression component: expecting numeric or valid string, "30" given)
( Heartsentwined\CronExprParser\Exception\InvalidArgumentException)
(======================================================================)
(/home/bas/vendor/heartsentwined/cron-expr-parser/src/Heartsentwined/CronExprParser/Parser.php:149)
(----------------------------------------------------------------------)
(#0 /home/bas/vendor/heartsentwined/cron-expr-parser/src/Heartsentwined/CronExprParser/Parser.php(52): Heartsentwined\CronExprParser\Parser::matchTimeComponent('30', 35))
(#1 /home/bas/vendor/heartsentwined/zf2-cron/src/Heartsentwined/Cron/Service/Cron.php(284): Heartsentwined\CronExprParser\Parser::matchTime(1369902900, '30 6 * * *'))
(#2 /home/bas/vendor/heartsentwined/zf2-cron/src/Heartsentwined/Cron/Service/Cron.php(160): Heartsentwined\Cron\Service\Cron->schedule())
(#3 /home/bas/vendor/heartsentwined/zf2-cron/src/Heartsentwined/Cron/Controller/CronController.php(35): Heartsentwined\Cron\Service\Cron->run())
(#4 /home/bas/vendor/zendframework/zendframework/library/Zend/Mvc/Controller/AbstractActionController.php(83): Heartsentwined\Cron\Controller\CronController->indexAction())
(#5 [internal function]: Zend\Mvc\Controller\AbstractActionController->onDispatch(Object(Zend\Mvc\MvcEvent)))
(#6 /home/bas/vendor/zendframework/zendframework/library/Zend/EventManager/EventManager.php(472): call_user_func(Array, Object(Zend\Mvc\MvcEvent)))
(#8 /home/bas/vendor/zendframework/zendframework/library/Zend/Mvc/Controller/AbstractController.php(117): Zend\EventManager\EventManager->trigger('dispatch', Object(Zend\Mvc\MvcEvent), Object(Closure)))
(#7 /home/bas/vendor/zendframework/zendframework/library/Zend/EventManager/EventManager.php(207): Zend\EventManager\EventManager->triggerListeners('dispatch', Object(Zend\Mvc\MvcEvent), Object(Closure)))
(#9 /home/bas/vendor/zendframework/zendframework/library/Zend/Mvc/DispatchListener.php(114): Zend\Mvc\Controller\AbstractController->dispatch(Object(Zend\Console\Request), Object(Zend\Console\Response)))
(#10 [internal function]: Zend\Mvc\DispatchListener->onDispatch(Object(Zend\Mvc\MvcEvent)))
(#11 /home/bas/vendor/zendframework/zendframework/library/Zend/EventManager/EventManager.php(472): call_user_func(Array, Object(Zend\Mvc\MvcEvent)))
(#12 /home/bas/vendor/zendframework/zendframework/library/Zend/EventManager/EventManager.php(207): Zend\EventManager\EventManager->triggerListeners('dispatch', Object(Zend\Mvc\MvcEvent), Object(Closure)))
(#13 /home/bas/vendor/zendframework/zendframework/library/Zend/Mvc/Application.php(294): Zend\EventManager\EventManager->trigger('dispatch', Object(Zend\Mvc\MvcEvent), Object(Closure)))
(#14 /home/bas/public/index.php(13): Zend\Mvc\Application->run())
(#15 {main})
(======================================================================)
( Previous Exception(s):)
()
(======================================================================)

I register my cron task like this :
Cron::register(
'import-all',
'30 6 * * *',
array($this, 'runImport'),
array('all')
);

For example, this register request worked fine :
Cron::register(
'import-queue',
'*/30 * * * *',
array($this, 'runImport'),
array('queue')
);

And my composer is configured like this :

    "heartsentwined/yaml": "1.*",
    "heartsentwined/zf2-cron": "2.*",
    "zendframework/zendframework": "2.*",
    "heartsentwined/arg-validator": "1.*",
    "heartsentwined/background-exec": "1.*",
    "heartsentwined/zf2-doctrine": "1.*",
    "heartsentwined/cron-expr-parser": "1.*",

Could you help me please ?

@BnitoBzh
Copy link
Author

Up ?

@rafaelhdr
Copy link

I had the same problem. I have fixed it by editing de function "exprToNumeric" in "vendor/heartsentwined/cron-expr-parser/src/Heartsentwined/CronExprParser/Parser.php" (line 169)

    public static function exprToNumeric($value)
    {
        ArgValidator::assert($value, array('string', 'numeric'));

        static $data = array(
            'jan'   => 1,
            'feb'   => 2,
            'mar'   => 3,
            'apr'   => 4,
            'may'   => 5,
            'jun'   => 6,
            'jul'   => 7,
            'aug'   => 8,
            'sep'   => 9,
            'oct'   => 10,
            'nov'   => 11,
            'dec'   => 12,

            'sun'   => 0,
            'mon'   => 1,
            'tue'   => 2,
            'wed'   => 3,
            'thu'   => 4,
            'fri'   => 5,
            'sat'   => 6,
        );

        /* Original conditional
        if (is_numeric($value)) {
            if (in_array((int) $value, $data, true)) {
                return $value;
            } else {
                return false;
            }
        }
        */

        if (is_numeric($value)) {
            return (int) $value;
        }

        if (is_string($value)) {
            $value = strtolower(substr($value, 0, 3));
            if (isset($data[$value])) {
                return $data[$value];
            }
        }

        return false;
    }

The problem is that the function was validating only values between 0 and 12 (and for minutes expressions, you have the value 30)

But i don't know if other problems will happen with this change.

@yalesov
Copy link
Owner

yalesov commented Jul 6, 2016

Fixed upstream at yalesov/php-cron-expr-parser#1

@yalesov yalesov closed this as completed Jul 6, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants