Exemple #1
0
 /**
  * Cope any local js libraries to export folder.
  * 
  * @param  string  $libraries
  * @param  string  $path
  * 
  * @return string  scripts html to insert before closing body tag
  */
 private function handleLibraries($libraries, $path)
 {
     $scripts = "<script src=\"js/jquery.js\"></script>\n<script src=\"js/bootstrap.js\"></script>\n";
     @$this->fs->copy($this->app['base_dir'] . '/assets/js/vendor/jquery.js', $path . 'js/jquery.js', true);
     @$this->fs->copy($this->app['base_dir'] . '/assets/js/vendor/bootstrap/bootstrap.min.js', $path . 'js/bootstrap.js', true);
     $libraries = json_decode($libraries);
     if ($libraries) {
         foreach ($libraries as $library) {
             if (is_string($library)) {
                 $library = Library::where('name', $library)->first();
             }
             if (!str_contains($library->path, '//')) {
                 $absolute = $this->relativeToAbsolute($library->path);
                 try {
                     @$this->fs->copy($absolute, $path . 'js/' . basename($absolute), true);
                 } catch (\Exception $e) {
                     continue;
                 }
                 $scripts .= '<script src="js/' . basename($library->path) . "\"></script>\n";
             } else {
                 $scripts .= '<script src="' . $library->path . "\"></script>\n";
             }
         }
     }
     return $scripts;
 }
 /**
  * Copies a file. Uses Symfony's copy but actually honors the third parameter.
  *
  * @param string $origin
  * @param string $target
  * @param bool $override
  */
 public static function copy($origin, $target, $override = false)
 {
     $fs = new \Symfony\Component\Filesystem\Filesystem();
     if (!$override && $fs->exists($target)) {
         return;
     }
     $fs->copy($origin, $target, $override);
 }
 private function dumpLocal()
 {
     $filesystem = new \Symfony\Component\Filesystem\Filesystem();
     if (!$filesystem->exists($this->databasePath)) {
         $this->result['status'] = 0;
         $this->result['message'] = "Defined Redis dump does not exist!";
         return $this->result;
     }
     $filesystem->copy($this->databasePath, $this->backupPath . $this->backupFilename);
     return true;
 }
Exemple #4
0
 /**
  * Use given template for given project.
  * 
  * @param  ProjectModel $project    
  * @param  integer      $templateId 
  * 
  * @return ProjectModel
  */
 private function useTemplate(Project $project, $templateId)
 {
     $template = Template::with('pages')->find($templateId);
     $pages = array();
     foreach ($template->pages as $page) {
         $pages[] = new Page(array_except($page->toArray(), array('id', 'pageable_id', 'pageable_type', 'created_at', 'updated_at')));
     }
     $project->pages()->saveMany($pages);
     $this->attachLibraries($project);
     //copy thumbnail from template to project
     $path = $this->app['base_dir'] . '/' . $template->thumbnail;
     $this->fs->copy($path, $this->app['base_dir'] . '/assets/images/projects/project-' . $project->id . '.png', true);
     return $project;
 }
Exemple #5
0
 /**
  * @param string $code
  *
  * @When /^I wait for the "([^"]*)" job to finish$/
  */
 public function iWaitForTheJobToFinish($code)
 {
     $condition = '$("#status").length && /(COMPLETED|STOPPED|FAILED|TERMINÉ|ARRÊTÉ|EN ÉCHEC)$/.test($("#status").text().trim())';
     try {
         $this->wait($condition);
     } catch (BehaviorException $e) {
         $jobInstance = $this->getFixturesContext()->getJobInstance($code);
         $jobExecution = $jobInstance->getJobExecutions()->first();
         $log = $jobExecution->getLogFile();
         if (is_file($log)) {
             $dir = getenv('WORKSPACE');
             $id = getenv('BUILD_ID');
             if (false !== $dir && false !== $id) {
                 $target = sprintf('%s/../builds/%s/batch_log/%s', $dir, $id, pathinfo($log, PATHINFO_BASENAME));
                 $fs = new \Symfony\Component\Filesystem\Filesystem();
                 $fs->copy($log, $target);
                 $log = sprintf('http://ci.akeneo.com/screenshots/%s/%s/batch_log/%s', getenv('JOB_NAME'), $id, pathinfo($log, PATHINFO_BASENAME));
             }
             $message = sprintf('Job "%s" failed, log available at %s', $code, $log);
             $this->getMainContext()->addErrorMessage($message);
         } else {
             $this->getMainContext()->addErrorMessage(sprintf('Job "%s" failed, no log available', $code));
         }
         // Get and print the normalized jobexecution to ease debugging
         $this->getSession()->executeScript(sprintf('$.get("/%s/%s_execution/%d.json", function (resp) { window.executionLog = resp; });', $jobInstance->getType() === 'import' ? 'collect' : 'spread', $jobInstance->getType(), $jobExecution->getId()));
         $this->wait();
         $executionLog = $this->getSession()->evaluateScript("return window.executionLog;");
         $this->getMainContext()->addErrorMessage(sprintf('Job execution: %s', print_r($executionLog, true)));
         // Call the wait method again to trigger timeout failure
         $this->wait($condition);
     }
 }
Exemple #6
0
/*
 * This file is part of the Sonata package.
 *
 * (c) Thomas Rabaix <*****@*****.**>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */
$rootDir = __DIR__;
require_once __DIR__ . '/app/bootstrap.php.cache';
// reset data
$fs = new \Symfony\Component\Filesystem\Filesystem();
$output = new \Symfony\Component\Console\Output\ConsoleOutput();
// does the parent directory have a parameters.yml file
if (is_file(__DIR__ . '/../parameters.demo.yml')) {
    $fs->copy(__DIR__ . '/../parameters.demo.yml', __DIR__ . '/app/config/parameters.yml', true);
}
if (!is_file(__DIR__ . '/app/config/parameters.yml')) {
    $output->writeln('<error>no default apps/config/parameters.yml file</error>');
    exit(1);
}
/**
 * @param $commands
 * @param \Symfony\Component\Console\Output\ConsoleOutput $output
 *
 * @return boolean
 */
function execute_commands($commands, $output)
{
    foreach ($commands as $command) {
        $output->writeln(sprintf('<info>Executing : </info> %s', $command));
Exemple #7
0
<?php

/*
 * This file is part of Sulu.
 *
 * (c) MASSIVE ART WebServices GmbH
 *
 * This source file is subject to the MIT license that is bundled
 * with this source code in the file LICENSE.
 */
$filesystem = new \Symfony\Component\Filesystem\Filesystem();
$context = $container->getParameter('sulu.context');
$path = __DIR__ . DIRECTORY_SEPARATOR;
if (!$filesystem->exists($path . 'parameters.yml')) {
    $filesystem->copy($path . 'parameters.yml.dist', $path . 'parameters.yml');
}
$loader->import('parameters.yml');
$loader->import('context_' . $context . '.yml');
Exemple #8
0
function createContents($faker, $folders, $con)
{
    echo "start creating contents\n";
    $fileSystem = new \Symfony\Component\Filesystem\Filesystem();
    $contents = array();
    if (($handle = fopen(THELIA_ROOT . '/setup/import/contents.csv', "r")) !== FALSE) {
        $row = 0;
        while (($data = fgetcsv($handle, 1000, ";")) !== FALSE) {
            $row++;
            if ($row == 1) {
                continue;
            }
            $content = new \Thelia\Model\Content();
            $content->setVisible(1)->setPosition($row - 1)->setLocale('fr_FR')->setTitle(trim($data[0]))->setChapo($faker->text(20))->setDescription($faker->text(200))->setLocale('en_US')->setTitle(trim($data[1]))->setChapo($faker->text(20))->setDescription($faker->text(200));
            // folder
            $contentFolders = explode(';', $data[7]);
            $defaultFolder = null;
            foreach ($contentFolders as $contentFolder) {
                $contentFolder = trim($contentFolder);
                if (array_key_exists($contentFolder, $folders)) {
                    $content->addFolder($folders[$contentFolder]);
                    if (null === $defaultFolder) {
                        $defaultFolder = $folders[$contentFolder]->getId();
                    }
                }
            }
            $content->getContentFolders()->getFirst()->setDefaultFolder(true)->save($con);
            $content->save($con);
            $images = explode(';', $data[6]);
            foreach ($images as $image) {
                $image = trim($image);
                if (empty($image)) {
                    continue;
                }
                $contentImage = new \Thelia\Model\ContentImage();
                $contentImage->setContentId($content->getId())->setFile($image)->save($con);
                $fileSystem->copy(THELIA_ROOT . 'setup/import/images/' . $image, THELIA_ROOT . 'local/media/images/content/' . $image, true);
            }
            $contents[trim($data[1])] = $content;
        }
        fclose($handle);
    }
    echo "Contents created successfully\n";
    return $contents;
}
Exemple #9
0
    $connection = $checkConnection->getConnection();
    $connection->exec("SET NAMES UTF8");
    $database = new \Thelia\Install\Database($connection);
    if (isset($_POST['database'])) {
        $_SESSION['install']['database'] = $_POST['database'];
    }
    if (isset($_POST['database_create']) && $_POST['database_create'] != "") {
        $_SESSION['install']['database'] = $_POST['database_create'];
        $database->createDatabase($_SESSION['install']['database']);
    }
    $database->insertSql($_SESSION['install']['database']);
    if (!file_exists(THELIA_ROOT . "/local/config/database.yml")) {
        $fs = new \Symfony\Component\Filesystem\Filesystem();
        $sampleConfigFile = THELIA_ROOT . "/local/config/database.yml.sample";
        $configFile = THELIA_ROOT . "/local/config/database.yml";
        $fs->copy($sampleConfigFile, $configFile, true);
        $configContent = file_get_contents($configFile);
        $configContent = str_replace("%DRIVER%", "mysql", $configContent);
        $configContent = str_replace("%USERNAME%", $_SESSION['install']['username'], $configContent);
        $configContent = str_replace("%PASSWORD%", $_SESSION['install']['password'], $configContent);
        $configContent = str_replace("%DSN%", sprintf("mysql:host=%s;dbname=%s;port=%s", $_SESSION['install']['host'], $_SESSION['install']['database'], $_SESSION['install']['port']), $configContent);
        file_put_contents($configFile, $configContent);
        // FA - no, as no further install will be possible
        // $fs->remove($sampleConfigFile);
        $fs->remove($thelia->getContainer()->getParameter("kernel.cache_dir"));
    }
}
$_SESSION['install']['step'] = $step;
// Retrieve the website url
$url = $_SERVER['PHP_SELF'];
$website_url = preg_replace("#/install/[a-z](.*)#", '', $url);
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */
if (!is_file('composer.json')) {
    throw new \RuntimeException('Can\'t find a composer.json file. Make sure to start this script from the project root folder');
}
$rootDir = __DIR__ . '/..';
require_once __DIR__ . '/../app/bootstrap.php.cache';
use Symfony\Component\Console\Output\OutputInterface;
// reset data
$fs = new \Symfony\Component\Filesystem\Filesystem();
$output = new \Symfony\Component\Console\Output\ConsoleOutput();
// does the parent directory have a parameters.yml file
if (is_file(__DIR__ . '/../../parameters.demo.yml')) {
    $fs->copy(__DIR__ . '/../../parameters.demo.yml', __DIR__ . '/../app/config/parameters.yml', true);
}
if (!is_file(__DIR__ . '/../app/config/parameters.yml')) {
    $output->writeln('<error>no default apps/config/parameters.yml file</error>');
    exit(1);
}
/**
 * @param $commands
 * @param \Symfony\Component\Console\Output\ConsoleOutput $output
 *
 * @return boolean
 */
function execute_commands($commands, $output)
{
    foreach ($commands as $command) {
        list($command, $message, $allowFailure) = $command;
Exemple #11
0
 public function testIgnoreDotFiles()
 {
     $fs = new \Symfony\Component\Filesystem\Filesystem();
     $fs->copy(__DIR__ . '/fixtures/base.css', __DIR__ . '/temp/base.css');
     $fs->mkdir(__DIR__ . '/temp/.git');
     $fs->touch(__DIR__ . '/temp/.foo');
     $fs->touch(__DIR__ . '/temp/.bar');
     $filesystem = new Filesystem(new Local(__DIR__ . '/temp'));
     $finder = new Finder($filesystem);
     $expected = ['.bar', '.foo', '.git', 'base.css'];
     $this->assertSame($finder, $finder->ignoreDotFiles(false)->ignoreVCS(false));
     $this->assertIterator($expected, $finder->in('/')->getIterator());
     $expected = ['.bar', '.foo', '.git', 'base.css'];
     $finder = new Finder($filesystem);
     $finder->ignoreDotFiles(false)->ignoreDotFiles(false)->ignoreVCS(false);
     $this->assertIterator($expected, $finder->in('/')->getIterator());
     $expected = ['base.css'];
     $finder = new Finder($filesystem);
     $this->assertSame($finder, $finder->ignoreDotFiles(true)->ignoreVCS(false));
     $this->assertIterator($expected, $finder->in('/')->getIterator());
 }
 /**
  * Local datababe(s) backup
  */
 private function dumpLocal()
 {
     //do some research on local to find location of databases
     $couchDbConfigCommand = 'couch-config --db-dir';
     $couchDbConfig = new Process($couchDbConfigCommand);
     $couchDbConfig->run();
     //we couldn't find path, just return error
     if (!$couchDbConfig->isSuccessful()) {
         $this->result['status'] = 0;
         $this->result['message'] = $couchDbConfig->getErrorOutput();
         return $this->result;
     }
     //set database local directory
     $this->databaseDir = trim($couchDbConfig->getOutput());
     $this->databaseDir = rtrim($this->databaseDir, "/") . "/";
     $filesystem = new \Symfony\Component\Filesystem\Filesystem();
     //backup single database
     if ($this->database != '') {
         //check if database exists with extra check if extension wasnt set
         //in other case return error if everything fails
         if (!$filesystem->exists($this->databaseDir . $this->database)) {
             if (!$filesystem->exists($this->databaseDir . $this->database . ".couch")) {
                 $this->result['status'] = 0;
                 $this->result['message'] = "Defined Couchdb does not exist!";
                 return $this->result;
             } else {
                 $this->database = $this->database . ".couch";
             }
         }
         //copy our database to top backup path
         $filesystem->copy($this->databaseDir . $this->database, $this->backupPath . $this->backupFilename);
     } else {
         $filesystem->mkdir($this->backupPath . $this->backupFilename);
         $copyAllDatabasesCommand = 'cp -Ra ' . $this->databaseDir . '. ' . $this->backupPath . $this->backupFilename;
         $copyAllDatabases = new Process($copyAllDatabasesCommand);
         $copyAllDatabases->run();
         //if backup fails return error with some extra info
         if (!$copyAllDatabases->isSuccessful()) {
             $this->result['status'] = 0;
             $this->result['message'] = $copyAllDatabases->getErrorOutput();
             return false;
         }
     }
     return true;
 }