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

Refresh $backups variable if initially empty #3

Closed ataylorme closed 6 years ago

ataylorme commented 6 years ago

Refresh the $backups variable after creating a backup due to no previous backups existing. Addresses #2.

ataylorme commented 6 years ago

@stevector I merged master to get the changes from #4 into this branch

ataylorme commented 6 years ago

So you think $site['env_raw']->getBackups()->getFinishedBackups($element) is cached? Maybe the environment itself is cached by Terminus.

stevector commented 6 years ago

That's just a guess. I suppose another possibility is that $this->createBackup($site); is not blocking and that the new backup is not yet there for $site['env_raw']->getBackups()->getFinishedBackups($element);

Did the change work on your machine?

ataylorme commented 6 years ago

@stevector yes, I just tested again and it worked. Neither the source or destination multidev had any backups before the clone

terminus site:clone wp-microsite.auto-update wp-quicksilver-demo.clone-test --no-code --yes
 [notice] Creating a backup of the code, database and media files on the wp-quicksilver-demo.clone-test environment...
 [notice] Finished backing up the code, database and media files on the wp-quicksilver-demo.clone-test environment.

 [notice] Creating a files backup on the wp-microsite.auto-update environment...
 [notice] Finished backing up the files on the wp-microsite.auto-update environment.

 [notice] Importing media files on wp-quicksilver-demo.clone-test...
 [notice] Imported the media files to wp-quicksilver-demo.clone-test.
screen shot 2018-05-18 at 11 11 25 am screen shot 2018-05-18 at 11 11 28 am
ataylorme commented 6 years ago

@stevector when you initially ran into this did you pass --no-backup? The backup argument defaults to true so a backup is made before attempting to clone. So unless no-backup was used and the source had no backups I don't see how the backup fetch would fail and catch the conditional in question to begin with.

ataylorme commented 6 years ago

@stevector I was able to recreate with --no-backup.

terminus site:clone wp-microsite.clone-test wp-quicksilver-demo.clone-test --no-code --no-backup

 Are you sure you want to clone from the wp-microsite.clone-test environment (source) to the wp-quicksilver-demo.clone-test (destination)? This will completely destroy the destination.
 (yes/no) [no]:
 > yes

 [notice] Cloning the following elements: database, files
 [notice] No database backups in the wp-microsite.clone-test environment found.

 [notice] Creating a backup of the code, database and media files on the wp-microsite.clone-test environment...
 [notice] Finished backing up the code, database and media files on the wp-microsite.clone-test environment.

PHP Fatal error:  Uncaught Error: Call to a member function serialize() on null in /Users/andrewtaylor/.terminus/plugins/terminus-site-clone-plugin/src/Commands/SiteCloneCommand.php:271
Stack trace:
#0 /Users/andrewtaylor/.terminus/plugins/terminus-site-clone-plugin/src/Commands/SiteCloneCommand.php(134): Pantheon\TerminusSiteClone\Commands\SiteCloneCommand->getLatestBackup(Array, 'database')
#1 [internal function]: Pantheon\TerminusSiteClone\Commands\SiteCloneCommand->clonePantheonSite('wp-microsite.cl...', 'wp-quicksilver-...', Array)
#2 /Users/andrewtaylor/pantheon-cli/vendor/consolidation/annotated-command/src/CommandProcessor.php(235): call_user_func_array(Array, Array)
#3 /Users/andrewtaylor/pantheon-cli/vendor/consolidation/annotated-command/src/CommandProcessor.php(181): Consolidation\AnnotatedCommand\CommandProcessor->runCommandCallback(Array, Object(Consolidation\AnnotatedCommand\CommandData))
#4 /Users/andrewtaylor/pantheon-cli/vendor/consolidation/annotated-command/src/CommandProcessor.php(150): Consolidation\Annot in /Users/andrewtaylor/.terminus/plugins/terminus-site-clone-plugin/src/Commands/SiteCloneCommand.php on line 271

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

Error: Call to a member function serialize() on null in /Users/andrewtaylor/.terminus/plugins/terminus-site-clone-plugin/src/Commands/SiteCloneCommand.php on line 271

Call Stack:
    0.0003     365464   1. {main}() /Users/andrewtaylor/pantheon-cli/bin/terminus:0
    0.0902    6516560   2. Pantheon\Terminus\Terminus->run() /Users/andrewtaylor/pantheon-cli/bin/terminus:44
    0.0902    6516584   3. Robo\Runner->run() /Users/andrewtaylor/pantheon-cli/src/Terminus.php:103
    0.4354   10233816   4. Symfony\Component\Console\Application->run() /Users/andrewtaylor/pantheon-cli/vendor/consolidation/robo/src/Runner.php:175
    0.4451   10238136   5. Symfony\Component\Console\Application->doRun() /Users/andrewtaylor/pantheon-cli/vendor/symfony/console/Application.php:148
    0.4453   10238136   6. Symfony\Component\Console\Application->doRunCommand() /Users/andrewtaylor/pantheon-cli/vendor/symfony/console/Application.php:248

In this scenario the source environment has no backups and the user must opt-out of backups with --no-backup. I think it's okay to throw an error and ask the user to re-run without --no-backup or to create a backup manually themselves first and re-run. Thoughts?

stevector commented 6 years ago

@ataylorme,

I am getting the error with --backup. Here's what I just ran.

terminus env:create bitb-persch.dev c3 && terminus site:clone bitb-persch.c3   d8-papc.300 --database --backup
ataylorme commented 6 years ago

@stevector I am confused by your --database --backup arguments. By default all options are true and should be opted out with negation. For example --no-backup.

stevector commented 6 years ago

That just happened to be the same combinations of flags used by yesterday's Custom Upstream user who saw the error originally.

If --database, --files, --code, and --backup aren't meant to be set (only there --no-* pairs) then it seems odd to have them as options at all.

But I'm getting the error even with leaving those flags off:

terminus env:create bitb-persch.dev c7 && terminus site:clone bitb-persch.c7   d8-papc.300  --yes
 [warning] Plugin Discovery: Ignoring directory /Users/stevepersch/.terminus/plugins/.idea because: The file "/Users/stevepersch/.terminus/plugins/.idea/composer.json" does not exist.
 [notice] Created Multidev environment "c7"
 [warning] Plugin Discovery: Ignoring directory /Users/stevepersch/.terminus/plugins/.idea because: The file "/Users/stevepersch/.terminus/plugins/.idea/composer.json" does not exist.
 [notice] Creating a backup of the code, database and media files on the d8-papc.300 environment...
 [notice] Finished backing up the code, database and media files on the d8-papc.300 environment.

 [notice] Importing code on d8-papc.300 with git...
 [notice] Cloning code for d8-papc.300 to /Users/stevepersch/.terminus/plugins/terminus-site-clone-plugin/terminus-site-clone-temp/bitb-persch/...
 [notice] Running git clone ssh://codeserver.dev.69a5ce13-a201-4035-98d5-cc4e7ac04536@codeserver.dev.69a5ce13-a201-4035-98d5-cc4e7ac04536.drush.in:2222/~/repository.git /Users/stevepersch/.terminus/plugins/terminus-site-clone-plugin/terminus-site-clone-temp/bitb-persch/
Cloning into '/Users/stevepersch/.terminus/plugins/terminus-site-clone-plugin/terminus-site-clone-temp/bitb-persch'...
remote: Counting objects: 89433, done.
remote: Compressing objects: 100% (39174/39174), done.
remote: Total 89433 (delta 49225), reused 84797 (delta 44690)
Receiving objects: 100% (89433/89433), 52.10 MiB | 975.00 KiB/s, done.
Resolving deltas: 100% (49225/49225), done.
Checking out files: 100% (17722/17722), done.
 [notice] Running git -C /Users/stevepersch/.terminus/plugins/terminus-site-clone-plugin/terminus-site-clone-temp/bitb-persch/ checkout c7
Switched to a new branch 'c7'
Branch c7 set up to track remote branch c7 from origin.
 [notice] Running git -C /Users/stevepersch/.terminus/plugins/terminus-site-clone-plugin/terminus-site-clone-temp/bitb-persch/ fetch origin c7
From ssh://codeserver.dev.69a5ce13-a201-4035-98d5-cc4e7ac04536.drush.in:2222/~/repository
 * branch                c7         -> FETCH_HEAD
 [notice] Running git -C /Users/stevepersch/.terminus/plugins/terminus-site-clone-plugin/terminus-site-clone-temp/bitb-persch/ merge origin/c7
Already up-to-date.
 [notice] Force pushing to the d8-papc.300 on the 300 branch.
 [notice] Running git -C /Users/stevepersch/.terminus/plugins/terminus-site-clone-plugin/terminus-site-clone-temp/bitb-persch/ remote set-url origin ssh://codeserver.dev.1f4b0110-2b15-4076-ba6c-b45395eaf013@codeserver.dev.1f4b0110-2b15-4076-ba6c-b45395eaf013.drush.in:2222/~/repository.git
 [notice] Running git -C /Users/stevepersch/.terminus/plugins/terminus-site-clone-plugin/terminus-site-clone-temp/bitb-persch/ push origin c7:300 --force
Everything up-to-date
 [notice] Sucessfully imported code to d8-papc.300.

 [notice] Creating a database backup on the bitb-persch.c7 environment...
 [notice] Finished backing up the database on the bitb-persch.c7 environment.

 [notice] Importing the database on d8-papc.300...
 [notice] Imported the database to d8-papc.300.

 [notice] Creating a files backup on the bitb-persch.c7 environment...
 [notice] Finished backing up the files on the bitb-persch.c7 environment.

 [notice] No files backups in the bitb-persch.c7 environment found.

 [notice] Creating a backup of the code, database and media files on the bitb-persch.c7 environment...
 [notice] Finished backing up the code, database and media files on the bitb-persch.c7 environment.

Fatal error: Uncaught Error: Call to a member function serialize() on null in /Users/stevepersch/.terminus/plugins/terminus-site-clone-plugin/src/Commands/SiteCloneCommand.php:259
Stack trace:
#0 /Users/stevepersch/.terminus/plugins/terminus-site-clone-plugin/src/Commands/SiteCloneCommand.php(122): Pantheon\TerminusSiteClone\Commands\SiteCloneCommand->getLatestBackup(Array, 'files')
#1 [internal function]: Pantheon\TerminusSiteClone\Commands\SiteCloneCommand->clonePantheonSite('bitb-persch.c7', 'd8-papc.300', Array)
#2 /Users/stevepersch/terminus/vendor/consolidation/annotated-command/src/CommandProcessor.php(235): call_user_func_array(Array, Array)
#3 /Users/stevepersch/terminus/vendor/consolidation/annotated-command/src/CommandProcessor.php(181): Consolidation\AnnotatedCommand\CommandProcessor->runCommandCallback(Array, Object(Consolidation\AnnotatedCommand\CommandData))
#4 /Users/stevepersch/terminus/vendor/consolidation/annotated-command/src/CommandProcessor.php(150): Consolidation\AnnotatedCommand\CommandProcessor->v in /Users/stevepersch/.terminus/plugins/terminus-site-clone-plugin/src/Commands/SiteCloneCommand.php on line 259
ataylorme commented 6 years ago

If --database, --files, --code, and --backup aren't meant to be set (only there --no-* pairs) then it seems odd to have them as options at all.

Defaulting them to true is the only way to have them all run by default and provide a way to opt-out. The no- arguments are generated automatically by Terminus.