--- /dev/null
+<?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));
+ }
+
+}