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