예제 #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
파일: 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);
 }
예제 #3
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.");
 }
예제 #4
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);
 }
예제 #5
0
 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
파일: 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());
 }
예제 #7
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);
     }
 }
예제 #8
0
 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 . ')');
     }
 }
예제 #9
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");
 }
예제 #10
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();
 }
예제 #11
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);
     }
 }
예제 #12
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));
 }
예제 #13
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);
         }
     }
 }
예제 #14
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();
     }
 }
예제 #15
0
 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);
             }
         }
     }
 }
예제 #16
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;
 }
예제 #17
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);
 }
예제 #18
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");
     }
 }
예제 #19
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.");
 }
예제 #20
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!");
     }
 }
예제 #21
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));
 }
예제 #22
0
 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 . ')');
         }
     }
 }
예제 #23
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."." );
 }
예제 #24
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
     			}
     		}*/
 }
예제 #25
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() . '.');
     }
 }
예제 #26
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
     }
 }
예제 #27
0
파일: Dump.php 프로젝트: CeusMedia/Hymn
 public function run()
 {
     if (!Hymn_Command_Database_Test::test($this->client)) {
         return Hymn_Client::out("Database can NOT be connected.");
     }
     $arguments = $this->client->arguments;
     $fileName = $arguments->getArgument(0);
     if (!preg_match("/[a-z0-9]/i", $fileName)) {
         //  arguments has not valid value
         $fileName = 'config/sql/';
     }
     //  set default path
     if (substr($fileName, -1) == "/") {
         //  given argument is a path
         $fileName = $fileName . "dump_" . date("Y-m-d_H:i:s") . ".sql";
     }
     //  generate stamped file name
     if (dirname($fileName)) {
         //  path is not existing
         exec("mkdir -p " . dirname($fileName));
     }
     //  create path
     $dbc = $this->client->getDatabase();
     $username = $this->client->getDatabaseConfiguration('username');
     $password = $this->client->getDatabaseConfiguration('password');
     $name = $this->client->getDatabaseConfiguration('name');
     $prefix = $this->client->getDatabaseConfiguration('prefix');
     if ($this->prefix = $arguments->hasOption('prefix')) {
         $this->prefixPlaceholder = $arguments->getOption('prefix');
     }
     $tables = array();
     if ($prefix) {
         foreach ($dbc->query("SHOW TABLES LIKE '" . $prefix . "%'") as $table) {
             $tables[] = $table[0];
         }
     }
     $tables = join(' ', $tables);
     $command = "mysqldump -u%s -p%s %s %s > %s";
     $command = sprintf($command, $username, $password, $name, $tables, $fileName);
     exec($command);
     /*  --  REPLACE PREFIX  --  */
     $regExp = "@(EXISTS|FROM|INTO|TABLE|TABLES|for table)( `)(" . $prefix . ")(.+)(`)@U";
     //  build regular expression
     $callback = array($this, '_callbackReplacePrefix');
     //  create replace callback
     $contents = explode("\n", file_get_contents($fileName));
     //  read raw dump file
     foreach ($contents as $nr => $content) {
         //  iterate lines
         $contents[$nr] = preg_replace_callback($regExp, $callback, $content);
     }
     //  replace prefix by placeholder
     file_put_contents($fileName, implode("\n", $contents));
     //  save final dump file
     return Hymn_Client::out("Database dumped to " . $fileName);
 }
예제 #28
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__ );
 }
예제 #29
0
파일: Update.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.");
     }
     //		$start		= microtime( TRUE );
     $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
     $moduleId = trim($this->client->arguments->getArgument());
     //  is there a specific module ID is given
     $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);
             }
         }
     }
     if ($moduleId) {
         if (!array_key_exists($moduleId, $listInstalled)) {
             return Hymn_Client::out("Module '" . $moduleId . "' is not installed and cannot be updated");
         }
         if (!array_key_exists($moduleId, $outdatedModules)) {
             return Hymn_Client::out("Module '" . $moduleId . "' is not outdated and cannot be updated");
         }
         $outdatedModules = array($moduleId => $outdatedModules[$moduleId]);
     }
     foreach ($outdatedModules as $update) {
         $module = $library->getModule($update->id);
         $installType = $this->client->getModuleInstallType($module->id, $this->installType);
         /*			$relation->addModule( $module, $installType );
         */
         $message = "Updating module '%s' (%s -> %s) ...";
         $message = sprintf($message, $module->id, $update->installed, $update->available);
         Hymn_Client::out($message);
         $installer = new Hymn_Module_Installer($this->client, $library, $this->quiet);
         $installer->update($module, $installType, $this->verbose, $this->dry);
     }
 }
예제 #30
0
파일: Files.php 프로젝트: CeusMedia/Hymn
 /**
  *	Removed installed files of module.
  *	@access		public
  *	@param 		object 		$module			Module object
  *	@param 		boolean 	$verbose		Flag: be verbose
  *	@param		boolean		$dry			Flag: dry run mode - simulation only
  *	@return		void
  *	@throws		RuntimeException			if target file is not readable
  *	@throws		RuntimeException			if target file is not writable
  */
 public function removeFiles($module, $verbose = FALSE, $dry = FALSE)
 {
     $fileMap = $this->prepareModuleFileMap($module);
     //  get list of installed module files
     foreach ($fileMap as $source => $target) {
         //  iterate file list
         if (!is_readable($target)) {
             //  if installed file is not readable
             throw new RuntimeException('Target file ' . $target . ' is not readable');
         }
         //  throw exception
         if (!is_writable($target)) {
             //  if installed file is not writable
             throw new RuntimeException('Target file ' . $target . ' is not removable');
         }
         //  throw exception
         if (!$dry) {
             //  not a dry run
             @unlink($target);
             //  remove installed file
         }
         if ($verbose && !$this->quiet) {
             //  be verbose
             Hymn_Client::out('  … removed file ' . $target);
         }
         //  print note about removed file
     }
 }