rocketeers / rocketeer

Send your projects up in the clouds
http://rocketeer.autopergamene.eu/
MIT License
2.66k stars 217 forks source link

Events are erased #732

Open etki opened 7 years ago

etki commented 7 years ago

Hi. I've spent some time debugging today just to find that events are just somehow erased.

here is my events.php:

<?php

use Rocketeer\Facades\Rocketeer;

Rocketeer::before('deploy', function($task) {
    throw new RuntimeException();
});

running deploy --on hotfix, entering Rocketeer\Abstracts\AbstractCommand::fireTasksQueue:

    protected function fireTasksQueue($tasks)
    {
        $this->laravel->instance('rocketeer.command', $this); // breakpoint here; $this->laravel->events->getListeners('rocketeer.deploy.before') == array [1]

        if (!$this->laravel['rocketeer.rocketeer']->isLocal()) { // current deploy is not local, so this block executes
            $this->laravel['rocketeer.credentials']->getServerCredentials();
            $this->laravel['rocketeer.credentials']->getRepositoryCredentials();
        }

        if ($this->straight) { // breakpoint here; $this->laravel->events->getListeners('rocketeer.deploy.before') == array [0]
       // it's gone!

And when i forcibly set current server as local through debugger, everything is just okay

etki commented 7 years ago

Found it

// Rocketeer\Services\Connections\ConnectionsHandler
    public function setConnection($connection, $server = 0)
    {
        if (!$this->isValidConnection($connection) || (($this->connection === $connection) && ($this->currentServer === $server))) {
            return;
        }

        // Set the connection
        $this->handle = null;
        $this->connection = $connection;
        $this->localStorage = $server;
        $this->currentServer = $server;

        // Update events
        $this->tasks->registerConfiguredEvents();
    }
// Rocketeer\ServicesTasksHandler
    public function registerConfiguredEvents()
    {
        // Clean previously registered events
        foreach ($this->registeredEvents as $event) {
            $this->events->forget('rocketeer.'.$event);
        }

I'm not familiar enough with internals to bring a fixing pull request