]> _ Git - fluidbook-toolbox.git/commitdiff
wip #6195 @1
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Wed, 16 Aug 2023 11:59:55 +0000 (13:59 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Wed, 16 Aug 2023 11:59:55 +0000 (13:59 +0200)
app/Fields/QuizDevelopmentVersion.php [new file with mode: 0644]
app/Models/Traits/FluidbookPlayerBranches.php
app/Models/Traits/QuizBranches.php [new file with mode: 0644]
app/Models/Traits/ToolboxPlayerBranches.php [new file with mode: 0644]

diff --git a/app/Fields/QuizDevelopmentVersion.php b/app/Fields/QuizDevelopmentVersion.php
new file mode 100644 (file)
index 0000000..a439635
--- /dev/null
@@ -0,0 +1,37 @@
+<?php
+
+namespace App\Fields;
+
+use Cubist\Backpack\Magic\Fields\SelectFromArray;
+
+class QuizDevelopmentVersion extends SelectFromArray
+{
+    protected static $__options = null;
+
+    /**
+     * @throws \JsonException
+     */
+    public function getOptions()
+    {
+        if (null === self::$__options) {
+            self::$__options = $this->_getOptions();
+        }
+        return self::$__options;
+    }
+
+    protected function _getOptions()
+    {
+        $versions = $this->getActiveBranches();
+        $res = ['stable' => 'master : git (stable)',
+            'dev' => 'master : local (dev)'];
+
+        foreach ($versions as $version) {
+            if ($version === 'master') {
+                continue;
+            }
+            $res[$version . '|git'] = $version . ' : git';
+            $res[$version . '|local'] = $version . ' : local';
+        }
+        return $res;
+    }
+}
index b060513c31dd6ff7698794b00332cd3a88a569f4..e659af7b933647800bc85697d2cdb76d6682b368 100644 (file)
@@ -8,117 +8,13 @@ use Cubist\Util\PHP;
 
 trait FluidbookPlayerBranches
 {
-    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);
+    use ToolboxPlayerBranches;
 
-        if (method_exists($this, 'line')) {
-            $this->line('<fg=blue>' . $git->getCommand() . '</>');
-            $this->line($output);
-        }
-        return $output;
-    }
+    protected static $reposName = 'fluidbook-html5';
 
-    protected static function getFluidbookPlayerBaseDirectory()
+    protected static function getPlayerBaseDirectory()
     {
         return Files::mkdir(resource_path('fluidbookpublication/player'));
     }
-
-    /**
-     * @return array
-     */
-    protected function getActiveBranches()
-    {
-        $cacheFile = self::getFluidbookPlayerBaseDirectory() . 'activebranches';
-        $res = json_decode(file_get_contents($cacheFile), true);
-        if (!$res) {
-            return self::updateAllBranches();
-        }
-        return $res;
-    }
-
-    protected static function reposDirectory()
-    {
-        return self::getFluidbookPlayerBaseDirectory() . 'repos/fluidbook-html5';
-    }
-
-    protected function fluidbookCreateBranch($branch)
-    {
-        $this->updateAllBranches();
-
-        $dir = self::reposDirectory();
-        $this->executeGitCommands($dir, ['checkout -b ' . $branch, 'push --set-upstream origin ' . $branch]);
-
-        $this->updateAllBranches();
-        $this->executeGitCommand($dir, 'checkout master');
-
-        $this->updateAllBranches();
-        return in_array($branch, $this->getActiveBranches());
-    }
-
-    protected function fluidbookRemoveBranch($branch)
-    {
-        $playerDir = self::getFluidbookPlayerBaseDirectory();
-        $branchesDir = $playerDir . 'branches/';
-        $localDir = $playerDir . 'local/';
-
-        $this->updateAllBranches();
-        $this->executeGitCommand(self::reposDirectory(), 'push --delete origin ' . $branch);
-
-        `rm -rf $localDir$branch`;
-        `rm -rf $branchesDir$branch`;
-
-        // TODO modifier la branche des fluidbooks qui utilisaient cette branche (self::resetPlayerVersion($branch);)
-
-        $this->updateAllBranches();
-        return !in_array($branch, $this->getActiveBranches());
-    }
-
-    /**
-     * @return []
-     */
-    protected function updateAllBranches()
-    {
-        PHP::neverStop();
-
-        $playerDir = self::getFluidbookPlayerBaseDirectory();
-        $branchesDir = Files::mkdir($playerDir . 'branches/');
-        $localDir = Files::mkdir($playerDir . 'local/');
-        $repos = self::reposDirectory();
-
-        $this->executeGitCommands($repos, ['stash save --keep-index', 'stash drop', 'pull --all', 'fetch --all --prune']);
-
-        $git = new Git($repos);
-        $branches = $git->listBranches();
-        file_put_contents($playerDir . '/activebranches', json_encode($branches));
-
-        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']);
-        }
-
-        return $branches;
-    }
 }
diff --git a/app/Models/Traits/QuizBranches.php b/app/Models/Traits/QuizBranches.php
new file mode 100644 (file)
index 0000000..f1047af
--- /dev/null
@@ -0,0 +1,17 @@
+<?php
+
+namespace App\Models\Traits;
+
+use Cubist\Util\Files\Files;
+
+trait QuizBranches
+{
+    use ToolboxPlayerBranches;
+
+    protected static $reposName = 'fluidbook-toolbox-quiz';
+
+    protected static function getPlayerBaseDirectory()
+    {
+        return Files::mkdir(resource_path('quiz/player'));
+    }
+}
diff --git a/app/Models/Traits/ToolboxPlayerBranches.php b/app/Models/Traits/ToolboxPlayerBranches.php
new file mode 100644 (file)
index 0000000..ba726ee
--- /dev/null
@@ -0,0 +1,120 @@
+<?php
+
+namespace App\Models\Traits;
+
+use Cubist\Util\CommandLine\Git;
+use Cubist\Util\Files\Files;
+use Cubist\Util\PHP;
+
+trait ToolboxPlayerBranches
+{
+    protected static function reposDirectory()
+    {
+        return self::getPlayerBaseDirectory() . 'repos/' . self::$reposName;
+    }
+
+    /**
+     * @return array
+     */
+    protected function getActiveBranches()
+    {
+        $cacheFile = self::getPlayerBaseDirectory() . 'activebranches';
+        $res = json_decode(file_get_contents($cacheFile), true);
+        if (!$res) {
+            return self::updateAllBranches();
+        }
+        return $res;
+    }
+
+
+    protected function fluidbookCreateBranch($branch)
+    {
+        $this->updateAllBranches();
+
+        $dir = self::reposDirectory();
+        $this->executeGitCommands($dir, ['checkout -b ' . $branch, 'push --set-upstream origin ' . $branch]);
+
+        $this->updateAllBranches();
+        $this->executeGitCommand($dir, 'checkout master');
+
+        $this->updateAllBranches();
+        return in_array($branch, $this->getActiveBranches());
+    }
+
+    protected function fluidbookRemoveBranch($branch)
+    {
+        $playerDir = self::getPlayerBaseDirectory();
+        $branchesDir = $playerDir . 'branches/';
+        $localDir = $playerDir . 'local/';
+
+        $this->updateAllBranches();
+        $this->executeGitCommand(self::reposDirectory(), 'push --delete origin ' . $branch);
+
+        `rm -rf $localDir$branch`;
+        `rm -rf $branchesDir$branch`;
+
+        // TODO modifier la branche des fluidbooks qui utilisaient cette branche (self::resetPlayerVersion($branch);)
+
+        $this->updateAllBranches();
+        return !in_array($branch, $this->getActiveBranches());
+    }
+
+    /**
+     * @return []
+     */
+    protected function updateAllBranches()
+    {
+        PHP::neverStop();
+
+        $playerDir = self::getPlayerBaseDirectory();
+        $branchesDir = Files::mkdir($playerDir . 'branches/');
+        $localDir = Files::mkdir($playerDir . 'local/');
+        $repos = self::reposDirectory();
+
+        $this->executeGitCommands($repos, ['stash save --keep-index', 'stash drop', 'pull --all', 'fetch --all --prune']);
+
+        $git = new Git($repos);
+        $branches = $git->listBranches();
+        file_put_contents($playerDir . '/activebranches', json_encode($branches));
+
+        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:' . self::$reposName . '.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']);
+        }
+
+        return $branches;
+    }
+
+    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);
+
+        if (method_exists($this, 'line')) {
+            $this->line('<fg=blue>' . $git->getCommand() . '</>');
+            $this->line($output);
+        }
+        return $output;
+    }
+}