pantheon-systems / terminus-site-clone-plugin

A Terminus plugin that adds the `site:clone` command to facilitate cloning sites on Pantheon
MIT License
21 stars 11 forks source link

PHP error when running command with source site that did not previously have a files backup #2

Closed stevector closed 6 years ago

stevector commented 6 years ago

I was a on a call today with a custom upstreams user. We tried making a new site and cloning db/code/files from an old site. On the first attempt the code and db cloned successfully. Files cloning died with this error:

Fatal error: Call to a member function serialize() on null in /Users/anne/.terminus/plugins/terminus-site-clone-plugin/src/Commands/SiteCloneCommand.php on line 258

We ran the command again and it completed successfully.

Just reading through the relevant section of code, I think I see the problem. I've added inline comments here:

        $backups = $site['env_raw']->getBackups()->getFinishedBackups($element);
        // $backups might be empty.
        // But the variable is not updated inside this conditional.
        if ( empty($backups) ) {
            $this->log()->notice(
                "No {element} backups in the {site}.{env} environment found.\n",
                [
                    'site' => $site['name'],
                    'env' => $site['env'],
                    'element' => $element,
                ]
            );
            $this->createBackup($site);
        }
        // So $backups could still be empty here.
        $latest_backup = array_shift($backups);
        // and then $latest_backup is null.
        $return = $latest_backup->serialize();

@ataylorme, am I missing any context? I think the fix could be a small PR.

ataylorme commented 6 years ago

@stevector I think you are correct that we just need to add $backups = $site['env_raw']->getBackups()->getFinishedBackups($element); after $this->createBackup($site); in the if ( empty($backups) ) conditional.

ataylorme commented 6 years ago

@stevector can you review #3?