Пример #1
0
 public function handle()
 {
     $this->http = new HTTP(new Slice());
     $request = $this->request();
     $q = $request->query()->get('q');
     if (!$q) {
         $this->response(['error' => '?q must be specified!'], 500);
     }
     $repo = new Repository();
     $repo->setDriver(new DatabaseDriver(Application::getInstance()->getConnection()));
     $path_info = explode('/', $q);
     $type = $path_info[0];
     if ('locks' === $type) {
         $this->response(['locked' => $repo->isLocked()]);
         return;
     }
     if (!$type || !in_array($type, ['chunk', 'snippet', 'content', 'tv', 'template', 'category'])) {
         $this->response(['error' => 'Type must be specified!'], 500);
     }
     $pk = count($path_info) > 1 ? $path_info[1] : null;
     if ('GET' === $request->method()) {
         if (!$pk) {
             $items = $repo->getAll($type);
             $this->response(array_map(function ($item) {
                 return $item->getData();
             }, $items));
         } else {
             $this->response($repo->getOnce($type, $pk)->getData());
         }
     } elseif ('POST' === $request->method()) {
     }
 }
Пример #2
0
 public function __construct($stage)
 {
     /** @var Application $app */
     $app = Application::getInstance();
     $this->config = $app->config();
     $this->client = new Client();
     $this->stage = $stage;
 }
Пример #3
0
 /**
  * Load resources all types from remote stage
  *
  * @return mixed
  */
 public function loadRemote($stage)
 {
     $repository = new Repository();
     $repository->setDriver(new RemoteDriver($stage));
     foreach (ResourceType::asArray() as $type) {
         $resources = $repository->getAll($type);
         $writer = FilesystemFactory::getWriter($type);
         Application::getInstance()->getOutput()->writeln(sprintf('<question>count: %s; type:%s</question>', count($resources), $type));
         foreach ($resources as $resource) {
             $writer->write($resource);
         }
     }
 }
Пример #4
0
 public function _before(UnitTester $I)
 {
     $app = Application::getInstance();
     $app->init();
 }
Пример #5
0
 public function getConnection()
 {
     return Application::getInstance()->getConnection();
 }
Пример #6
0
 /**
  * 1. Checkout to new branch modvert/test based on origin/test
  * or movert/develop based on origin/develop
  * 2. Load remote resources
  * 3. Show message:
  *   1. Check changes `git diff --name-only -- storage`
  *   2. Commit if has changes
  *   3. Checkout to the main branch (test/develop/feature/QUES-*)
  *   4. Merge `git merge movert/test` or `git merge movert/develop`
  *
  * Если
  */
 public function loadRemote($stage)
 {
     /** @var $resource IResource **/
     $repository = new Repository();
     $driver = new RemoteDriver($stage);
     $repository->setDriver($driver);
     if ($repository->isLocked()) {
         // If remote stage is Locked
         return $this->output->writeln('<error>Remote stage is locked. Please try again!</error>');
     }
     $storage = new Storage($this->getConnection());
     $git = new Git();
     $git->setRepository(Application::getInstance()->getAppPath());
     $status = $git->status();
     $current_branch = $status['branch'];
     // do not checkout if has unstaged changes
     if (count($status['changes'])) {
         return $this->output->writeln('<error>Please commit changes before!</error>');
     }
     $temp_branch = 'modvert/develop';
     $parent_branch = 'origin/develop';
     try {
         $git->branch->delete($temp_branch, ['force' => true]);
     } catch (\Exception $ex) {
         /** the branch not found */
     }
     $git->checkout->create($temp_branch, $parent_branch);
     $storage->loadRemote($stage);
     $storage_changes = ArrayHelper::matchValue($git->status()['changes'], 'file', '/^storage/');
     if (count($storage_changes)) {
         $this->output->writeln('<info>You have unstaged remote changes! Commit them and merge with main branch!</info>');
     } else {
         $git->checkout($current_branch);
     }
 }
Пример #7
0
    $path = str_replace('/', DIRECTORY_SEPARATOR, $root . '../vendor/autoload.php');
    if (file_exists($path)) {
        include_once $path;
    } else {
        $path = str_replace('/', DIRECTORY_SEPARATOR, $root . '../../autoload.php');
        if (file_exists($path)) {
            include_once $path;
        } else {
            echo 'Something goes wrong with your archive' . PHP_EOL . 'Try downloading again' . PHP_EOL;
            exit(1);
        }
    }
}
define('TARGET_PATH', getcwd());
/** @var \Modvert\Application $app */
$app = \Modvert\Application::getInstance();
$app->setAppPath(TARGET_PATH);
$options = ['stage' => 'test'];
if ($argc > 2) {
    foreach ($argv as $arg) {
        if (preg_match('/\\-\\-(?P<key>\\w+)\\=(?P<value>[\\w\\_\\-\\d]+)/', $arg, $match)) {
            if (count($match) && array_key_exists('key', $match) && array_key_exists('value', $match)) {
                $options[$match['key']] = $match['value'];
            }
        }
    }
}
$output = new Symfony\Component\Console\Output\ConsoleOutput();
$app->setOutput($output);
try {
    if (count($argv) >= 2 && $argv[1] == 'init') {
Пример #8
0
<?php

use Modvert\Application;
// This is global bootstrap for autoloading
require __DIR__ . '/../vendor/autoload.php';
$config_file = getcwd() . DIRECTORY_SEPARATOR . 'modvert.yml';
if (!file_exists($config_file)) {
    throw new \Exception('Config file modvert.yml not found');
}
define('TARGET_PATH', getcwd());
$output = new Symfony\Component\Console\Output\ConsoleOutput();
$app = Application::getInstance();
$app->setOutput($output);
$app->init();
Пример #9
0
 public function tryToLoadRemote(UnitTester $I)
 {
     $app = \Modvert\Application::getInstance();
     $app->loadRemote('test');
 }