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

Undefined index: year in vendor/lavary/crunz/src/Event.php on line 370 #41

Closed
krlitus opened this issue Nov 30, 2016 · 4 comments
Closed
Labels

Comments

@krlitus
Copy link

krlitus commented Nov 30, 2016

This error occurs when using on method in 'Running Events at Certain Times'

    /**
     * Position of cron fields
     *
     * @var array
     */
    protected $fieldsPosition = [
        'minute' => 1,
        'hour'   => 2,
        'day'    => 3,
        'month'  => 4,
        'week'   => 5,
    ];

    /**
     * Schedule the event to run on a certain date
     *
     * @param  string  $date
     *
     * @return $this
     */
    public function on($date)
    {
        
        $date     = date_parse($date);
        $segments = array_only($date, array_flip($this->fieldsPosition));

        if ($date['year']) {
 
            $this->skip(function () use ($segments) {
                return (int) date('Y') != $segments['year'];
            });

        }
                
        foreach ($segments as $key => $value) {   
            if ($value != false) {                
                $this->spliceIntoPosition($this->fieldsPosition[$key], (int) $value);
            }
        }

        return $this;          
    }

Apparently missing the position for the year in the attribute 'fieldsPosition'.

@MoatazAbdAlmageed
Copy link

How can I fix this issue ?

@PabloKowalczyk
Copy link
Collaborator

@krlitus could you provide date that causes this issue?

@mindcreations
Copy link
Contributor

mindcreations commented Jun 12, 2018

Experienced this problem today while trying on() method. The problem is caused by $segments['year'] in this line:

return (int) date('Y') != $segments['year'];

$segments will never contain a 'year' key.

You can debug this only when you run the scheduler at the exact minute of the datetime passed to on().

To fix this I think is enough to replace $segments with $date. The fixed code will look like:

            $this->skip(function () use ($date) {
                return (int) date('Y') != $date['year'];
            });

I'll arrange a pull request...

mindcreations added a commit to mindcreations/crunz that referenced this issue Jun 12, 2018
mindcreations added a commit to mindcreations/crunz that referenced this issue Jun 14, 2018
@mindcreations mindcreations mentioned this issue Jun 14, 2018
Merged
@PabloKowalczyk
Copy link
Collaborator

Fixed in #118. Thanks guys.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants