コード例 #1
0
ファイル: Default.php プロジェクト: CeusMedia/Hymn
 public function run()
 {
     Hymn_Client::out("Arguments:");
     print_r($this->client->arguments->getArguments());
     Hymn_Client::out("Options:");
     print_r($this->client->arguments->getOptions());
 }
コード例 #2
0
ファイル: Test.php プロジェクト: CeusMedia/Hymn
 public function run()
 {
     if (self::test($this->client)) {
         return Hymn_Client::out("Database can be connected.");
     }
     return Hymn_Client::out("Database is NOT connected.");
 }
コード例 #3
0
ファイル: Get.php プロジェクト: CeusMedia/Hymn
 public function run()
 {
     $filename = Hymn_Client::$fileName;
     if (!file_exists($filename)) {
         throw new RuntimeException('File "' . $filename . '" is missing');
     }
     $config = json_decode(file_get_contents($filename));
     if (is_null($config)) {
         throw new RuntimeException('Configuration file "' . $filename . '" is not valid JSON');
     }
     $key = $this->client->arguments->getArgument(0);
     if (!strlen(trim($key))) {
         throw new InvalidArgumentException('First argument "key" is missing');
     }
     $parts = explode(".", $key);
     $module = array_shift($parts);
     if (!$parts) {
         throw new InvalidArgumentException('Invalid key - must be of syntax "Module_Name.(section.)key"');
     }
     $configKey = join(".", $parts);
     if (!isset($config->modules->{$module}) || !isset($config->modules->{$module}->config)) {
         throw new InvalidArgumentException('No configuration for module "' . $module . '" set');
     }
     if (!isset($config->modules->{$module}->config->{$configKey})) {
         throw new InvalidArgumentException('No configuration value for key "' . $configKey . '" in module "' . $module . '" set');
     }
     $current = $config->modules->{$module}->config->{$configKey};
     Hymn_Client::out($current);
 }
コード例 #4
0
ファイル: Dump.php プロジェクト: CeusMedia/Hymn
 public function run()
 {
     $fileName = Hymn_Client::$fileName;
     //		Hymn_Client::out();
     if (!file_exists("config/modules")) {
         return Hymn_Client::out("No modules installed");
     }
     $index = new DirectoryIterator("config/modules");
     $list = array();
     foreach ($index as $entry) {
         if ($entry->isDir() || $entry->isDot()) {
             continue;
         }
         if (!preg_match("/\\.xml\$/", $entry->getFilename())) {
             continue;
         }
         $id = pathinfo($entry->getFilename(), PATHINFO_FILENAME);
         $module = Hymn_Module_Reader::load($entry->getPathname(), $id);
         //			Hymn_Client::out( $id );
         if ($module->config) {
             $list[$id] = array('config' => (object) array());
             foreach ($module->config as $pair) {
                 $list[$id]['config']->{$pair->key} = $pair->value;
             }
         }
     }
     $json = json_decode(file_get_contents($fileName));
     $json->modules = $list;
     file_put_contents($fileName, json_encode($json, JSON_PRETTY_PRINT));
     return Hymn_Client::out("Configuration dumped to " . $fileName);
 }
コード例 #5
0
ファイル: Updatable.php プロジェクト: CeusMedia/Hymn
 public function run()
 {
     $config = $this->client->getConfig();
     $library = new Hymn_Module_Library();
     foreach ($config->sources as $sourceId => $source) {
         $active = !isset($source->active) || $source->active;
         $library->addShelf($sourceId, $source->path, $active);
     }
     $relation = new Hymn_Module_Graph($this->client, $library);
     $modules = array();
     //  prepare list of modules to update
     $listInstalled = $library->listInstalledModules($config->application->uri);
     //  get list of installed modules
     if (!$listInstalled) {
         //  application has no installed modules
         return Hymn_Client::out("No installed modules found");
     }
     $outdatedModules = array();
     //
     foreach ($listInstalled as $installedModule) {
         $source = $installedModule->installSource;
         $availableModule = $library->getModule($installedModule->id, $source, FALSE);
         if ($availableModule) {
             if (version_compare($availableModule->version, $installedModule->version, '>')) {
                 $outdatedModules[$installedModule->id] = (object) array('id' => $installedModule->id, 'installed' => $installedModule->version, 'available' => $availableModule->version, 'source' => $installedModule->installSource);
             }
         }
     }
     foreach ($outdatedModules as $update) {
         $message = "- %s: %s -> %s";
         $message = sprintf($message, $update->id, $update->installed, $update->available);
         Hymn_Client::out($message);
     }
 }
コード例 #6
0
ファイル: Set.php プロジェクト: CeusMedia/Hymn
 public function run()
 {
     $filename = Hymn_Client::$fileName;
     if (!file_exists($filename)) {
         throw new RuntimeException('File "' . $filename . '" is missing');
     }
     $config = json_decode(file_get_contents($filename));
     if (is_null($config)) {
         throw new RuntimeException('Configuration file "' . $filename . '" is not valid JSON');
     }
     $key = $this->client->arguments->getArgument(0);
     if (!strlen(trim($key))) {
         throw new InvalidArgumentException('Missing first argument "key" is missing');
     }
     $key = $this->client->arguments->getArgument(0);
     $value = $this->client->arguments->getArgument(1);
     $parts = explode(".", $key);
     if (count($parts) === 3) {
         if (!isset($config->{$parts[0]})) {
             $config->{$parts[0]} = (object) array();
         }
         if (!isset($config->{$parts[0]}->{$parts[1]})) {
             $config->{$parts[0]}->{$parts[1]} = (object) array();
         }
         if (!isset($config->{$parts[0]}->{$parts[1]}->{$parts[2]})) {
             $config->{$parts[0]}->{$parts[1]}->{$parts[2]} = NULL;
         }
         $current = $config->{$parts[0]}->{$parts[1]}->{$parts[2]};
     } else {
         if (count($parts) === 2) {
             if (!isset($config->{$parts[0]})) {
                 $config->{$parts[0]} = (object) array();
             }
             if (!isset($config->{$parts[0]}->{$parts[1]})) {
                 $config->{$parts[0]}->{$parts[1]} = NULL;
             }
             $current = $config->{$parts[0]}->{$parts[1]};
         } else {
             throw new InvalidArgumentException('Invalid key - must be of syntax "path.(subpath.)key"');
         }
     }
     if (!strlen(trim($value))) {
         $value = trim(Hymn_Client::getInput("Value for '" . $key . "'", $current, array(), FALSE));
     }
     if (preg_match('/^".*"$/', $value)) {
         $value = substr($value, 1, -1);
     }
     //		if( $current === $value )
     //			throw new RuntimeException( 'No change made' );
     if (count($parts) === 3) {
         $config->{$parts[0]}->{$parts[1]}->{$parts[2]} = $value;
     } else {
         if (count($parts) === 2) {
             $config->{$parts[0]}->{$parts[1]} = $value;
         }
     }
     file_put_contents($filename, json_encode($config, JSON_PRETTY_PRINT));
     clearstatcache();
 }
コード例 #7
0
ファイル: Options.php プロジェクト: CeusMedia/Hymn
 public function run()
 {
     Hymn_Client::out();
     Hymn_Client::out("DevMode: Reflects parsed argument options");
     $this->client->arguments->registerOption('test', '/^(-t|--test)=(\\S+)$/', '\\2');
     $this->client->arguments->parse();
     print_r($this->client->arguments->getOptions());
 }
コード例 #8
0
ファイル: Required.php プロジェクト: CeusMedia/Hymn
 public function run()
 {
     $modules = (array) $this->client->getConfig()->modules;
     Hymn_Client::out(count($modules) . " modules required:");
     foreach ($modules as $module) {
         Hymn_Client::out("- " . $module->id);
     }
 }
コード例 #9
0
ファイル: Installed.php プロジェクト: CeusMedia/Hymn
 public function run()
 {
     $config = $this->client->getConfig();
     $library = new Hymn_Module_Library();
     $modules = $library->listInstalledModules($config->application->uri);
     ksort($modules);
     Hymn_Client::out(count($modules) . " modules installed:");
     foreach ($modules as $module) {
         Hymn_Client::out("- " . $module->id . ' (' . $module->version . ')');
     }
 }
コード例 #10
0
ファイル: Update.php プロジェクト: CeusMedia/Hymn
 public function run()
 {
     $urlHymn = "https://github.com/CeusMedia/Hymn/raw/master/hymn.phar";
     $pathFile = $this->getHymnFilePath();
     if (!$pathFile) {
         throw new Exception("Hymn not found");
     }
     Hymn_Client::out("Download: " . $urlHymn);
     $this->downloadFile($urlHymn, $pathFile);
     Hymn_Client::out("Saved to: " . $pathFile);
     passthru("hymn version");
 }
コード例 #11
0
ファイル: Get.php プロジェクト: CeusMedia/Hymn
 public function run()
 {
     $key = $this->client->arguments->getArgument(0);
     if (!strlen(trim($key))) {
         throw new InvalidArgumentException('Missing first argument "key" is missing');
     }
     $editor = new Hymn_Tool_BaseConfigEditor("config/config.ini");
     if (!$editor->hasProperty($key, FALSE)) {
         throw new InvalidArgumentException('Base config key "' . $key . '" is missing');
     }
     $current = $editor->getProperty($key);
     Hymn_Client::out($current);
     clearstatcache();
 }
コード例 #12
0
ファイル: Sources.php プロジェクト: CeusMedia/Hymn
 public function run()
 {
     $config = $this->client->getConfig();
     $library = new Hymn_Module_Library();
     $sources = (array) $config->sources;
     foreach ($sources as $sourceId => $source) {
         $active = !isset($source->active) || $source->active;
         $library->addShelf($sourceId, $source->path, $active);
     }
     Hymn_Client::out(count($sources) . " module sources:");
     foreach ($library->getShelves() as $shelf) {
         $status = $shelf->active ? '+' : '-';
         Hymn_Client::out("- [" . $status . "] " . $shelf->id . " -> " . $shelf->path);
     }
 }
コード例 #13
0
ファイル: Remove.php プロジェクト: CeusMedia/Hymn
 public function run()
 {
     $config = $this->client->getConfig();
     $key = $this->client->arguments->getArgument(0);
     if (!isset($config->sources)) {
         $config->sources = (object) array();
     }
     if (!isset($config->sources->{$key})) {
         Hymn_Client::out('Source with ID "' . $key . '" is not registered.');
         return;
     }
     unset($config->sources->{$key});
     $json = json_decode(file_get_contents(Hymn_Client::$fileName));
     $json->sources = $config->sources;
     file_put_contents(Hymn_Client::$fileName, json_encode($json, JSON_PRETTY_PRINT));
 }
コード例 #14
0
ファイル: Info.php プロジェクト: CeusMedia/Hymn
 public function run()
 {
     $config = $this->client->getConfig();
     $moduleId = $this->client->arguments->getArgument(0);
     //		$shelfId	= $this->client->arguments->getArgument( 1 );
     if ($moduleId) {
         $library = new Hymn_Module_Library();
         foreach ($config->sources as $sourceId => $source) {
             $active = !isset($source->active) || $source->active;
             $library->addShelf($sourceId, $source->path, $active);
         }
         $modulesAvailable = $library->getModules();
         $modulesInstalled = $library->listInstalledModules($config->application->uri);
         //  get list of installed modules
         foreach ($modulesAvailable as $availableModule) {
             if ($moduleId !== $availableModule->id) {
                 continue;
             }
             Hymn_Client::out('Module: ' . $availableModule->title);
             if ($availableModule->description) {
                 Hymn_Client::out($availableModule->description);
             }
             Hymn_Client::out('Category: ' . $availableModule->category);
             Hymn_Client::out('Source: ' . $availableModule->sourceId);
             Hymn_Client::out('Version: ' . $availableModule->version);
             if (array_key_exists($moduleId, $modulesInstalled)) {
                 $installedModule = $modulesInstalled[$moduleId];
                 Hymn_Client::out('Installed: ' . $installedModule->version);
                 if (version_compare($availableModule->version, $installedModule->version, '>')) {
                     $message = 'Update available: %s -> %s';
                     $message = sprintf($message, $installedModule->version, $availableModule->version);
                     Hymn_Client::out($message);
                 }
             }
             return;
         }
         Hymn_Client::out('Module ' . $moduleId . ' not available.');
     } else {
         Hymn_Client::out("Application Settings:");
         foreach ($config->application as $key => $value) {
             if (is_object($value)) {
                 $value = json_encode($value, JSON_PRETTY_PRINT);
             }
             Hymn_Client::out("- " . $key . " => " . $value);
         }
     }
 }
コード例 #15
0
ファイル: Abstract.php プロジェクト: CeusMedia/Hymn
 public function help()
 {
     $class = preg_replace("/^Hymn_Command_/", "", get_class($this));
     $command = strtolower(str_replace("_", "-", $class));
     $fileName = "phar://hymn.phar/locales/en/help/" . $command . ".txt";
     if (file_exists($fileName)) {
         Hymn_Client::out(file($fileName));
     } else {
         Hymn_Client::out();
         Hymn_Client::out("Outch! Help on this topic is not available yet. I am sorry :-/");
         Hymn_Client::out();
         Hymn_Client::out("But YOU can improve this situation :-)");
         Hymn_Client::out("- get more information on: https://ceusmedia.de/");
         Hymn_Client::out("- make a fork or patch on: https://github.com/CeusMedia/Hymn");
         Hymn_Client::out();
     }
 }
コード例 #16
0
ファイル: Set.php プロジェクト: CeusMedia/Hymn
 public function run()
 {
     $key = $this->client->arguments->getArgument(0);
     $value = $this->client->arguments->getArgument(1);
     if (!strlen(trim($key))) {
         throw new InvalidArgumentException('Missing first argument "key" is missing');
     }
     $editor = new Hymn_Tool_BaseConfigEditor("config/config.ini");
     if (!$editor->hasProperty($key, FALSE)) {
         throw new InvalidArgumentException('Base config key "' . $key . '" is missing');
     }
     $current = $editor->getProperty($key, FALSE);
     if (!strlen(trim($value))) {
         $value = trim(Hymn_Client::getInput("Value for '" . $key . "'", $current, array(), FALSE));
     }
     $editor->setProperty($key, $value);
     clearstatcache();
 }
コード例 #17
0
ファイル: Uninstall.php プロジェクト: CeusMedia/Hymn
 public function run()
 {
     $this->dry = $this->client->arguments->getOption('dry');
     $this->force = $this->client->arguments->getOption('force');
     $this->quiet = $this->client->arguments->getOption('quiet');
     $this->verbose = $this->client->arguments->getOption('verbose');
     if ($this->dry) {
         Hymn_Client::out("## DRY RUN: Simulated actions - no changes will take place.");
     }
     $config = $this->client->getConfig();
     $library = new Hymn_Module_Library();
     foreach ($config->sources as $sourceId => $source) {
         $active = !isset($source->active) || $source->active;
         $library->addShelf($sourceId, $source->path, $active);
     }
     $relation = new Hymn_Module_Graph($this->client, $library);
     $moduleId = trim($this->client->arguments->getArgument());
     $listInstalled = $library->listInstalledModules($config->application->uri);
     $isInstalled = array_key_exists($moduleId, $listInstalled);
     if (!$moduleId) {
         Hymn_Client::out("No module id given");
     } else {
         if (!$isInstalled) {
             Hymn_Client::out("Module '" . $moduleId . "' is not installed");
         } else {
             $module = $listInstalled[$moduleId];
             $neededBy = array();
             foreach ($listInstalled as $installedModuleId => $installedModule) {
                 if (in_array($moduleId, $installedModule->relations->needs)) {
                     $neededBy[] = $installedModuleId;
                 }
             }
             if ($neededBy && !$this->force) {
                 $list = implode(', ', $neededBy);
                 $msg = "Module '%s' is needed by %d other modules (%s)";
                 Hymn_Client::out(sprintf($msg, $module->id, count($neededBy), $list));
             } else {
                 $module->path = 'not_relevant/';
                 $installer = new Hymn_Module_Installer($this->client, $library, $this->quiet);
                 $installer->uninstall($module, $this->verbose, $this->dry);
             }
         }
     }
 }
コード例 #18
0
ファイル: Set.php プロジェクト: CeusMedia/Hymn
 public function run()
 {
     $filename = Hymn_Client::$fileName;
     #		if( !file_exists( $filename ) )
     #			throw new RuntimeException( 'File "'.$filename.'" is missing' );
     #		$config	= json_decode( file_get_contents( $filename ) );
     #		if( is_null( $config ) )
     #			throw new RuntimeException( 'Configuration file "'.$filename.'" is not valid JSON' );
     $key = $this->client->arguments->getArgument(0);
     if (!strlen(trim($key))) {
         throw new InvalidArgumentException('First argument "key" is missing');
     }
     $key = $this->client->arguments->getArgument(0);
     $value = $this->client->arguments->getArgument(1);
     $parts = explode(".", $key);
     $module = array_shift($parts);
     if (!$parts) {
         throw new InvalidArgumentException('Invalid key - must be of syntax "Module_Name.(section.)key"');
     }
     $configKey = join(".", $parts);
     if (!isset($config->modules->{$module})) {
         $config->modules->{$module} = (object) array();
     }
     if (!isset($config->modules->{$module}->config)) {
         $config->modules->{$module}->config = (object) array();
     }
     if (!isset($config->modules->{$module}->config->{$configKey})) {
         $config->modules->{$module}->config->{$configKey} = NULL;
     }
     $current = $config->modules->{$module}->config->{$configKey};
     if (!strlen(trim($value))) {
         $value = trim(Hymn_Client::getInput('Value for "' . $module . ':' . $configKey . '"', $current, array(), FALSE));
     }
     if (preg_match('/^".*"$/', $value)) {
         $value = substr($value, 1, -1);
     }
     //		if( $current === $value )
     //			throw new RuntimeException( 'No change made' );
     $config->modules->{$module}->config->{$configKey} = $value;
     file_put_contents($filename, json_encode($config, JSON_PRETTY_PRINT));
     clearstatcache();
 }
コード例 #19
0
ファイル: Help.php プロジェクト: CeusMedia/Hymn
 public function run()
 {
     $action = $this->client->arguments->getArgument(0);
     $className = "Hymn_Command_Default";
     if (strlen($action)) {
         $command = ucwords(preg_replace("/-+/", " ", $action));
         $className = "Hymn_Command_" . preg_replace("/ +/", "_", $command);
         if (!class_exists($className)) {
             throw new InvalidArgumentException('Command "' . $action . '" is not existing');
         }
         $class = new ReflectionClass($className);
         $object = $class->newInstanceArgs(array($this->client));
         call_user_func(array($object, 'help'));
         return;
     }
     $config = $this->client->getConfig();
     $lines = file("phar://hymn.phar/locales/en/help/default.txt");
     Hymn_Client::out($lines);
     return;
 }
コード例 #20
0
ファイル: Clear.php プロジェクト: CeusMedia/Hymn
 public function run()
 {
     if (!Hymn_Command_Database_Test::test($this->client)) {
         return Hymn_Client::out("Database can NOT be connected.");
     }
     $force = $this->client->arguments->getOption('force');
     $verbose = $this->client->arguments->getOption('verbose');
     $quiet = $this->client->arguments->getOption('quiet');
     $prefix = $this->client->getDatabaseConfiguration('prefix');
     $dbc = $this->client->getDatabase();
     $result = $dbc->query("SHOW TABLES" . ($prefix ? " LIKE '" . $prefix . "%'" : ""));
     $tables = $result->fetchAll();
     if (!$tables) {
         if (!$quiet) {
             Hymn_Client::out("Database is empty");
         }
         return;
     }
     if (!$force) {
         if ($quiet) {
             return Hymn_Client::out("Quiet mode needs force mode (-f|--force)");
         }
         Hymn_Client::out("Database tables:");
         foreach ($tables as $table) {
             Hymn_Client::out("- " . $table[0]);
         }
         $answer = Hymn_Client::getInput("Do you really want to drop these tables?", NULL, array("y", "n"));
         if ($answer !== "y") {
             return;
         }
     }
     foreach ($tables as $table) {
         if (!$quiet && $verbose) {
             Hymn_Client::out("- Drop table '" . $table[0] . "'");
         }
         $dbc->query("DROP TABLE " . $table[0]);
     }
     if (!$quiet) {
         Hymn_Client::out("Database cleared");
     }
 }
コード例 #21
0
ファイル: Get.php プロジェクト: CeusMedia/Hymn
 public function run()
 {
     $filename = Hymn_Client::$fileName;
     if (!file_exists($filename)) {
         throw new RuntimeException('File "' . $filename . '" is missing');
     }
     $config = json_decode(file_get_contents($filename));
     if (is_null($config)) {
         throw new RuntimeException('Configuration file "' . $filename . '" is not valid JSON');
     }
     $key = $this->client->arguments->getArgument(0);
     if (!strlen(trim($key))) {
         throw new InvalidArgumentException('Missing first argument "key" is missing');
     }
     $parts = explode(".", $key);
     if (count($parts) === 3) {
         if (!isset($config->{$parts[0]})) {
             $config->{$parts[0]} = (object) array();
         }
         if (!isset($config->{$parts[0]}->{$parts[1]})) {
             $config->{$parts[0]}->{$parts[1]} = (object) array();
         }
         if (!isset($config->{$parts[0]}->{$parts[1]}->{$parts[2]})) {
             $config->{$parts[0]}->{$parts[1]}->{$parts[2]} = NULL;
         }
         $current = $config->{$parts[0]}->{$parts[1]}->{$parts[2]};
     } else {
         if (count($parts) === 2) {
             if (!isset($config->{$parts[0]})) {
                 $config->{$parts[0]} = (object) array();
             }
             if (!isset($config->{$parts[0]}->{$parts[1]})) {
                 $config->{$parts[0]}->{$parts[1]} = NULL;
             }
             $current = $config->{$parts[0]}->{$parts[1]};
         } else {
             throw new InvalidArgumentException('Invalid key - must be of syntax "path.(subpath.)key"');
         }
     }
     Hymn_Client::out($current);
 }
コード例 #22
0
ファイル: Add.php プロジェクト: CeusMedia/Hymn
 public function run()
 {
     $config = $this->client->getConfig();
     if (!isset($config->sources)) {
         $config->sources = (object) array();
     }
     $data = (object) array('key' => 'Local_Modules', 'type' => 'folder', 'path' => NULL, 'title' => NULL);
     $questions = array((object) array('key' => 'type', 'label' => "- Source type", 'options' => array("folder")), (object) array('key' => 'path', 'label' => "- Source path"), (object) array('key' => 'key', 'label' => "- Source ID"), (object) array('key' => 'title', 'label' => "- Source description"));
     $connectable = FALSE;
     do {
         foreach ($questions as $question) {
             //  iterate questions
             $default = $data->{$question->key};
             //  shortcut default value
             $options = isset($question->options) ? $question->options : array();
             //  realize options
             $input = Hymn_Client::getInput($question->label, $default, $options, FALSE);
             //  ask for value
             $data->{$question->key} = $input;
             //  assign given value
         }
         if (isset($config->sources->{$data->key})) {
             Hymn_Client::out('Error: Source with ID "' . $data->key . '" is already registered.');
         } else {
             if ($data->type === "folder" && !file_exists($data->path)) {
                 Hymn_Client::out('Error: Path to module library source is not existing.');
             } else {
                 $connectable = TRUE;
             }
         }
         //  note connectability for loop break
     } while (!$connectable);
     //  repeat until connectable
     $data->title = $data->title ? $data->title : $data->key;
     $config->sources->{$data->key} = (object) array('active' => TRUE, 'title' => $data->title, 'type' => $data->type, 'path' => $data->path);
     $json = json_decode(file_get_contents(Hymn_Client::$fileName));
     $json->sources = $config->sources;
     file_put_contents(Hymn_Client::$fileName, json_encode($json, JSON_PRETTY_PRINT));
 }
コード例 #23
0
ファイル: Test.php プロジェクト: CeusMedia/Hymn
 public static function checkPhpClasses($path = "src", $recursive = TRUE, $verbose = FALSE, $level = 0)
 {
     $indent = str_repeat(". ", $level);
     if ($verbose) {
         Hymn_Client::out($indent . "Folder: " . $path);
     }
     $index = new DirectoryIterator($path);
     $valid = TRUE;
     foreach ($index as $entry) {
         if ($entry->isDot()) {
             continue;
         }
         if ($entry->isDir() && $recursive) {
             self::checkPhpClasses($entry->getPathname(), $recursive, $verbose, $level + 1);
         } else {
             if ($entry->isFile()) {
                 if (!preg_match("/\\.php/", $entry->getFilename())) {
                     continue;
                 }
                 if ($verbose) {
                     Hymn_Client::out($indent . ". File: " . $entry->getPathname());
                 }
                 $code = 0;
                 $results = array();
                 $command = "php -l " . $entry->getPathname() . " 2>&1";
                 @exec($command, $results, $code);
                 if ($code !== 0) {
                     $valid = FALSE;
                     $message = "Invalid PHP code has been found in " . $entry->getPathname() . ".";
                     $message = isset($results[0]) ? $results[0] . "." : $message;
                     Hymn_Client::out($message);
                 }
             }
         }
     }
     if (!$valid) {
         throw new RuntimeException("Invalid PHP code has been found. Please check syntax!");
     }
 }
コード例 #24
0
ファイル: Create.php プロジェクト: CeusMedia/Hymn
 public function run()
 {
     $data = array();
     Hymn_Client::out("Please enter application information:");
     $title = Hymn_Client::getInput("- Application title", "My Project", NULL, FALSE);
     $uri = Hymn_Client::getInput("- Folder Path", getcwd() . '/', NULL, FALSE);
     $protocol = Hymn_Client::getInput("- HTTP Protocol", "http://", NULL, FALSE);
     $host = Hymn_Client::getInput("- HTTP Host", "example.com", NULL, FALSE);
     $path = Hymn_Client::getInput("- HTTP Path", "/", NULL, FALSE);
     $data['application'] = (object) array('title' => $title, 'url' => $protocol . $host . "/" . ltrim($path, "/"), 'uri' => $uri);
     $data['library'] = (object) array();
     $data['sources'] = (object) array();
     $data['modules'] = (object) array();
     Hymn_Client::out("");
     Hymn_Client::out("Please enter database information:");
     $data['database'] = (object) array('driver' => Hymn_Client::getInput("- PDO Driver", "mysql", NULL, FALSE), 'host' => Hymn_Client::getInput("- Host", "localhost", NULL, FALSE), 'port' => Hymn_Client::getInput("- Port", "3306", NULL, FALSE), 'username' => Hymn_Client::getInput("- Username", "my_db_user", NULL, FALSE), 'password' => Hymn_Client::getInput("- Password", "my_db_password", NULL, FALSE), 'name' => Hymn_Client::getInput("- Name", "my_db_name", NULL, FALSE), 'prefix' => Hymn_Client::getInput("- Table Prefix", NULL, NULL, FALSE));
     Hymn_Client::out("");
     Hymn_Client::out("Please enter system information:");
     $data['system'] = (object) array('user' => Hymn_Client::getInput("- System User", get_current_user(), NULL, FALSE), 'group' => Hymn_Client::getInput("- System Group", "www-data", NULL, FALSE));
     file_put_contents(Hymn_Client::$fileName, json_encode($data, JSON_PRETTY_PRINT));
     Hymn_Client::out("Configuration file " . Hymn_Client::$fileName . " has been created.");
 }
コード例 #25
0
ファイル: Available.php プロジェクト: CeusMedia/Hymn
 public function run()
 {
     $config = $this->client->getConfig();
     $library = new Hymn_Module_Library();
     foreach ($config->sources as $sourceId => $source) {
         $active = !isset($source->active) || $source->active;
         $library->addShelf($sourceId, $source->path, $active);
     }
     $shelfId = $this->client->arguments->getArgument(0);
     if ($shelfId) {
         $modules = $library->getModules($shelfId);
         Hymn_Client::out(count($modules) . " modules available in module source '" . $shelfId . "':");
         foreach ($modules as $moduleId => $module) {
             Hymn_Client::out("- " . $module->id);
         }
     } else {
         $modules = $library->getModules();
         Hymn_Client::out(count($modules) . " modules available:");
         foreach ($modules as $moduleId => $module) {
             Hymn_Client::out("- " . $module->id . ' (' . $module->version . ')');
         }
     }
 }
コード例 #26
0
ファイル: Graph.php プロジェクト: CeusMedia/Hymn
 public function run()
 {
     if (!(file_exists("config") && is_writable("config"))) {
         return Hymn_Client::out("Configuration folder is either not existing or not writable");
     }
     $force = $this->client->arguments->getOption('force');
     $verbose = $this->client->arguments->getOption('verbose');
     $quiet = $this->client->arguments->getOption('quiet');
     if (!$quiet && $verbose) {
         Hymn_Client::out("Loading all needed modules into graph…");
     }
     $config = $this->client->getConfig();
     $library = new Hymn_Module_Library();
     foreach ($config->sources as $sourceId => $source) {
         $active = !isset($source->active) || $source->active;
         $library->addShelf($sourceId, $source->path);
     }
     $relation = new Hymn_Module_Graph($this->client, $library, $quiet);
     foreach ($config->modules as $moduleId => $module) {
         if (preg_match("/^@/", $moduleId)) {
             continue;
         }
         if (!isset($module->active) || $module->active) {
             $module = $library->getModule($moduleId);
             $installType = $this->client->getModuleInstallType($moduleId, $this->installType);
             $relation->addModule($module, $installType);
         }
     }
     $targetFileGraph = "config/modules.graph";
     $targetFileImage = "config/modules.graph.png";
     $graph = $relation->renderGraphFile($targetFileGraph, $verbose);
     //		if( !$quiet )
     //			Hymn_Client::out( "Saved graph file to ".$targetFileGraph."." );
     $image = $relation->renderGraphImage($graph, $targetFileImage, $verbose);
     //		if( !$quiet )
     //			Hymn_Client::out( "Saved graph image to ".$targetFileImage."." );
 }
コード例 #27
0
ファイル: Version.php プロジェクト: CeusMedia/Hymn
 public function run()
 {
     Hymn_Client::out(Hymn_Client::$version);
     //		Hymn_Client::out( "Working in: " . getCwd() );
     //		Hymn_Client::out( "Hymn Path: " . __DIR__ );
 }
コード例 #28
0
ファイル: Install.php プロジェクト: CeusMedia/Hymn
 public function run()
 {
     $this->dry = $this->client->arguments->getOption('dry');
     $this->force = $this->client->arguments->getOption('force');
     $this->quiet = $this->client->arguments->getOption('quiet');
     $this->verbose = $this->client->arguments->getOption('verbose');
     if ($this->dry) {
         Hymn_Client::out("## DRY RUN: Simulated actions - no changes will take place.");
     }
     $config = $this->client->getConfig();
     $library = new Hymn_Module_Library();
     foreach ($config->sources as $sourceId => $source) {
         $active = !isset($source->active) || $source->active;
         $library->addShelf($sourceId, $source->path, $active);
     }
     $relation = new Hymn_Module_Graph($this->client, $library);
     $moduleId = trim($this->client->arguments->getArgument());
     if ($moduleId) {
         $module = $library->getModule($moduleId);
         if ($module) {
             $installType = $this->client->getModuleInstallType($moduleId, $this->installType);
             $relation->addModule($module, $installType);
         }
     } else {
         foreach ($config->modules as $moduleId => $module) {
             if (preg_match("/^@/", $moduleId)) {
                 continue;
             }
             if (!isset($module->active) || $module->active) {
                 $module = $library->getModule($moduleId);
                 $installType = $this->client->getModuleInstallType($moduleId, $this->installType);
                 $relation->addModule($module, $installType);
             }
         }
     }
     $installer = new Hymn_Module_Installer($this->client, $library, $this->quiet);
     $modules = $relation->getOrder();
     foreach ($modules as $module) {
         $listInstalled = $library->listInstalledModules($config->application->uri);
         $isInstalled = array_key_exists($module->id, $listInstalled);
         $isCalledModule = $moduleId && $moduleId == $module->id;
         $isForced = $this->force && ($isCalledModule || !$moduleId);
         if ($isInstalled && !$isForced) {
             Hymn_Client::out("Module '" . $module->id . "' is already installed");
         } else {
             Hymn_Client::out("Installing module '" . $module->id . "' ...");
             $installType = $this->client->getModuleInstallType($module->id, $this->installType);
             $installer->install($module, $installType, $this->verbose, $this->dry);
         }
     }
     /*		//  todo: custom install mode: define SQL to import in hymn file
     		if( isset( $config->database->import ) ){
     			foreach( $config->database->import as $import ){
     				if( file_exists( $import ) )
     					$installer->executeSql( file_get_contents( $import ) );							//  broken on this point since extraction to Hymn_Module_SQL
     			}
     		}*/
 }
コード例 #29
0
ファイル: SQL.php プロジェクト: CeusMedia/Hymn
 /**
  *	Reads module SQL scripts and executes install and update scripts.
  *	@access		public
  *	@param 		object 		$installedModule	Object of locally installed module
  *	@param 		object 		$module				Object of library module to update to
  *	@param 		boolean 	$verbose			Flag: be verbose
  *	@param		boolean		$dry				Flag: dry run mode - simulation only
  *	@return		void
  */
 public function runModuleUpdateSql($installedModule, $module, $verbose, $dry = FALSE)
 {
     if (!isset($module->sql) || !count($module->sql)) {
         //  module has no SQL scripts
         return;
     }
     //  quit here
     $driver = $this->checkDriver();
     //  check database connection and get PDO driver
     $version = $installedModule->version;
     //  start by version of currently installed module
     $scripts = array();
     //  prepare empty list for collected scripts
     foreach ($module->sql as $sql) {
         //  iterate SQL scripts
         if ($sql->event == "update" && trim($sql->sql)) {
             //  is an update script
             if ($sql->type === $driver || $sql->type == "*") {
                 //  database driver is matching or general
                 if (version_compare($sql->version, $version, ">")) {
                     //  script version is prior to currently installed version
                     $scripts[$sql->version] = $sql;
                     //  append script for execution
                 }
             }
         }
     }
     uksort($scripts, 'version_compare');
     //  sort update scripts by version
     foreach ($scripts as $script) {
         //  iterate found ordered update scripts
         if ($verbose && !$this->quiet) {
             //  be verbose
             $msg = "    … apply database script on %s at version %s";
             //  ...
             Hymn_Client::out(sprintf($msg, $script->event, $script->version));
             //  ...
         }
         if (!$dry) {
             //  not a dry run
             $this->executeSql($script->sql);
         }
         //  execute collected SQL script
     }
 }
コード例 #30
0
ファイル: Graph.php プロジェクト: CeusMedia/Hymn
 public function renderGraphImage($graph = NULL, $targetFile = NULL, $verbose = FALSE)
 {
     Hymn_Client::out("Checking graphviz: ", FALSE);
     Hymn_Test::checkShellCommand("graphviz");
     Hymn_Client::out("OK");
     try {
         if (!$graph) {
             $graph = $this->renderGraphFile(NULL, $verbose);
         }
         $sourceFile = tempnam(sys_get_temp_dir(), 'Hymn');
         file_put_contents($sourceFile, $graph);
         //  save temporary
         if ($targetFile) {
             @exec('dot -Tpng -o' . $targetFile . ' ' . $sourceFile);
             if (!$this->quiet) {
                 Hymn_Client::out('Graph image saved to ' . $targetFile . '.');
             }
         } else {
             exec('dot -Tpng -O ' . $sourceFile);
             unlink($sourceFile);
             $graphImage = file_get_contents($sourceFile . '.png');
             @unlink($sourceFile);
             return $graphImage;
         }
     } catch (Exception $e) {
         Hymn_Client::out('Graph rendering failed: ' . $e->getMessage() . '.');
     }
 }