Example #1
0
 protected function jobStarted($jobScript)
 {
     $file = FileSystem::getRelativePath(getcwd(), $jobScript);
     echo "Running {$file}:";
     // Call parent
     return call_user_func_array(array('parent', __FUNCTION__), func_get_args());
 }
Example #2
0
 /**
  * Run specific job script
  *
  * @param string
  */
 public function run($jobScript)
 {
     $this->jobStarted($jobScript);
     // -----
     $phpBin = 'php';
     $proc = proc_open($phpBin . ' ' . escapeshellarg($jobScript), array(array('pipe', 'r'), array('pipe', 'w'), array('pipe', 'w')), $pipes, dirname($jobScript), NULL, array('bypass_shell' => TRUE));
     list($stdin, $stdout, $stderr) = $pipes;
     fclose($stdin);
     do {
         $status = proc_get_status($proc);
     } while ($status['running']);
     // -----
     $result = $status['exitcode'] == 0;
     if ($result) {
         $this->jobFinished($jobScript, $stdout, $stderr);
     } else {
         $this->jobFailed($jobScript, $stdout, $stderr);
     }
     fclose($stdout);
     fclose($stderr);
     proc_close($proc);
     /// @todo error handling
     if ($result) {
         unlink($jobScript);
     } else {
         $dir = $this->storage->directory . '/failed';
         FileSystem::createDirIfNotExists($dir);
         rename($jobScript, $dir . '/' . basename($jobScript));
     }
     return $result;
 }
Example #3
0
 /**
  * Generates proforma invoice for order and returns it's file path
  * 
  * @param Order $order
  * 
  * @return string absolute filepath 
  */
 public function generate(Order $order)
 {
     $outputFile = $this->getFilePath($order);
     vBuilder\Utils\FileSystem::createFilePath($outputFile);
     $orderInvoice = new vStore\Invoicing\ShopOrderInvoice($order);
     $this->renderer->renderToFile($orderInvoice, $outputFile);
     return $outputFile;
 }
Example #4
0
 public function __construct()
 {
     $this->parameters = $this->getDefaultParameters();
     if ($this->parameters['appDir']) {
         $this->parameters['wwwDir'] = Utils\FileSystem::normalizePath($this->parameters['appDir'] . '/../www');
         $this->parameters['confDir'] = $this->parameters['appDir'] . '/config';
         $this->parameters['vendorDir'] = Utils\FileSystem::normalizePath($this->parameters['appDir'] . '/../vendor');
         $this->parameters['libsDir'] = $this->parameters['vendorDir'];
         $this->parameters['filesDir'] = Utils\FileSystem::normalizePath($this->parameters['appDir'] . '/../files');
         $this->parameters['logDir'] = Utils\FileSystem::normalizePath($this->parameters['appDir'] . '/../log');
         $this->parameters['tempDir'] = Utils\FileSystem::normalizePath($this->parameters['appDir'] . '/../temp');
     }
 }
Example #5
0
 public function loadConfiguration()
 {
     $container = $this->getContainerBuilder();
     $config = $this->getConfig();
     $useProfiler = isset($config['profiler']) ? $config['profiler'] : $container->parameters['debugMode'];
     unset($config['profiler']);
     if (isset($config['flags'])) {
         $flags = 0;
         foreach ((array) $config['flags'] as $flag) {
             $flags |= constant($flag);
         }
         $config['flags'] = $flags;
     }
     $tableManagerConfig = array_intersect_key($config, array_flip(array('tables', 'requiredTables')));
     $connection = $container->addDefinition($this->prefix('connection'))->setClass('DibiConnection', array(array_diff_key($config, $tableManagerConfig)));
     if ($useProfiler) {
         $panel = $container->addDefinition($this->prefix('panel'))->setClass('DibiNettePanel')->addSetup('Nette\\Diagnostics\\Debugger::getBar()->addPanel(?)', array('@self'))->addSetup('Nette\\Diagnostics\\Debugger::getBlueScreen()->addPanel(?)', array('DibiNettePanel::renderException'));
         $connection->addSetup('$service->onEvent[] = ?', array(array($panel, 'logEvent')));
     }
     // TableManager service
     $tmDef = $container->addDefinition($this->prefix('tableManager'))->setClass('vBuilder\\Database\\TableManager')->addSetup('$service->setScriptDirPath(?)', array(FileSystem::normalizePath($this->getContainerBuilder()->expand('%appDir%/../db'))));
     // Add all required tables and their definition
     if (isset($tableManagerConfig['requiredTables'])) {
         $requiredTables = (array) $tableManagerConfig['requiredTables'];
         foreach ($requiredTables as $table) {
             $tableConfig = array('structure' => NULL, 'data' => NULL);
             // Defined table
             if (isset($tableManagerConfig['tables'][$table])) {
                 // table_name: { structure: script1.sql, data: script2.sql }
                 if (is_array($tableManagerConfig['tables'][$table])) {
                     $tableConfig = array_intersect_key($tableManagerConfig['tables'][$table], array_flip(array('structure', 'data')));
                     if (isset($db->config['tables'][$table]['structure'])) {
                         $tableConfig['structure'] = $db->config['tables'][$table]['structure'];
                     }
                     // table_name: script.sql
                 } else {
                     $tableConfig['structure'] = $tableManagerConfig['tables'][$table];
                 }
             }
             // Normalize paths
             if ($tableConfig['structure']) {
                 $tableConfig['structure'] = FileSystem::normalizePath($tableConfig['structure']);
             }
             if ($tableConfig['data']) {
                 $tableConfig['data'] = FileSystem::normalizePath($tableConfig['data']);
             }
             $tmDef->addSetup('$service->setTableScripts(?, ?, ?)', array($table, $tableConfig['structure'], $tableConfig['data']));
         }
     }
 }
Example #6
0
    $dumpPaths = array('structure' => $tm->getDdlScript($table), 'data' => $tm->getDataScript($table));
    // Create parent directories
    foreach ($dumpPaths as $path) {
        if ($path) {
            FileSystem::createFilePath($path);
        }
    }
    $relPath = FileSystem::getRelativePath($workPath, $dumpPaths['structure']);
    echo "\n{$table} in {$relPath}: ";
    switch (dumpStructure($db, $table, $dumpPaths['structure'])) {
        case 0:
            echo "ok";
            break;
        case 1:
            echo "created";
            break;
        case 2:
            echo "updated";
            break;
    }
    if ($args->get('data')) {
        if ($dumpPaths['data'] === FALSE) {
            echo "\n   -> data dump skipped by config\n";
        } else {
            $relPath = FileSystem::getRelativePath($workPath, $dumpPaths['data']);
            echo "\n   -> data dumped in: {$relPath}\n";
            dumpData($db, $table, $dumpPaths['data']);
        }
    }
}
echo "\n\nDone :-)\n\n";
Example #7
0
 /**
  * Creates new job with code and metadata
  *
  * @param string name
  * @param array metadata
  * @param string php code
  * @return string|FALSE absolute path to job file or FALSE on failure
  */
 public function createJob($name, array $metadata, $phpCode)
 {
     FileSystem::createDirIfNotExists($this->dir);
     $path = $this->dir . '/' . self::FILENAME_PREFIX . $name . '.' . md5($phpCode) . self::FILENAME_SUFFIX;
     $result = $this->getFileStorage()->write($path, $metadata, "<?php\n" . $phpCode);
     return $result === FALSE ? FALSE : $path;
 }