protected function jobStarted($jobScript) { $file = FileSystem::getRelativePath(getcwd(), $jobScript); echo "Running [0;36m{$file}:[0m"; // Call parent return call_user_func_array(array('parent', __FUNCTION__), func_get_args()); }
/** * 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; }
/** * 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; }
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'); } }
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'])); } } }
$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[1;36m{$table}[0m in [0;36m{$relPath}[0m: "; 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: [0;36m{$relPath}[0m\n"; dumpData($db, $table, $dumpPaths['data']); } } } echo "\n\nDone :-)\n\n";
/** * 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; }