]> _ Git - fluidbook-toolbox.git/commitdiff
wip #5399 @0.25
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Wed, 17 Aug 2022 16:08:44 +0000 (18:08 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Wed, 17 Aug 2022 16:08:44 +0000 (18:08 +0200)
app/Console/Commands/FluidbookPullSources.php [new file with mode: 0644]
app/Console/Kernel.php

diff --git a/app/Console/Commands/FluidbookPullSources.php b/app/Console/Commands/FluidbookPullSources.php
new file mode 100644 (file)
index 0000000..a87c244
--- /dev/null
@@ -0,0 +1,66 @@
+<?php
+
+namespace App\Console\Commands;
+
+use Cubist\Backpack\Console\Commands\CubistCommand;
+use Cubist\Util\CommandLine\Git;
+use Cubist\Util\Files\Files;
+use Cubist\Util\PHP;
+
+class FluidbookPullSources extends CubistCommand
+{
+    protected $signature = 'fluidbook:player:updatesources';
+    protected $description = 'Update fluidbook player sources from git repos';
+
+    protected function executeGitCommands($dir, $commands)
+    {
+        if (!is_array($commands)) {
+            $commands = [$commands];
+        }
+        $res = [];
+        foreach ($commands as $command) {
+            $res[] = $this->executeGitCommand($dir, $command);
+        }
+        return $res;
+    }
+
+    protected function executeGitCommand($dir, $command)
+    {
+        $git = new Git($dir);
+        $output = $git->executeCmd($command);
+
+        $this->line('<fg=blue>' . $git->getCommand() . '</>');
+        $this->line($output);
+        return $output;
+    }
+
+    public function handle()
+    {
+        PHP::neverStop(true);
+
+        $playerDir = Files::mkdir(resource_path('fluidbookpublication/player')) . '/';
+        $branchesDir = Files::mkdir($playerDir . 'branches/');
+        $localDir = Files::mkdir($playerDir . 'local/');
+        $baseBranchDir = Files::mkdir($branchesDir . 'fluidbook-html5');
+
+        $this->executeGitCommands($baseBranchDir, ['stash save --keep-index', 'stash drop', 'pull --all', 'fetch --all --prune']);
+
+        $git = new Git($baseBranchDir);
+        $branches = $git->listBranches();
+        foreach ($branches as $b) {
+            $gitsource = $branchesDir . $b;
+            $local = $localDir . $b;
+            if (!file_exists($branchesDir . $b)) {
+                $this->executeGitCommands($branchesDir, 'clone -b ' . $b . ' --single-branch git@git.cubedesigners.com:fluidbook-html5.git ' . $b);
+            }
+            if (!file_exists($local)) {
+                mkdir($local, 0777, true);
+                `cp -r $gitsource/* $local`;
+                `rm -rf $local/.git`;
+            }
+            $this->executeGitCommands($branchesDir . $b, ['reset --hard origin/' . $b, 'pull']);
+        }
+        file_put_contents($playerDir . '/activebranches', json_encode($branches));
+    }
+
+}
index 1420f210b772708a74de0921dab7ce636e262710..1e2d58fe82a3c16c6ee8d46dbc0211d15e1a70b4 100644 (file)
@@ -29,6 +29,7 @@ class Kernel extends \Cubist\Backpack\Console\Kernel
         $schedule->command('cubist:magic:precache')->everyFiveMinutes();
         $schedule->command('job:dispatch ProcessTotals')->everyTwoHours();
         $schedule->command('fluidbook:farm:ping')->everyMinute();
+        $schedule->command('fluidbook:player:updatesources')->everyMinute();
 
     }