/** * wrapper function for loading a profile */ function load_profile($options) { $pro = new profile(); $profiles = file::getFileList('profiles', array('dir_only' => true)); if (!in_array($options['profile'], $profiles)) { common::abort('No such profile'); } if (isset($options['config_only'])) { $pro->loadConfigIni($options['profile']); } else { $pro->loadProfile($options['profile']); } }
/** * Get a SQL file list from module, and action * @param string $module * @param string $action (up or down) * @return array $ary array with file list */ public function getSqlFileList($module, $action) { $sql_dir = conf::pathModules() . "/{$module}/mysql/{$action}"; $file_list = file::getFileList($sql_dir); if (is_array($file_list)) { return $file_list; } else { return array(); } }
/** * function for getting latest timestamp for dumps * * default to backup/sql but you can specify a dir. * * @param string $dir * @return int $timestamp */ function get_latest_db_dump($dir = null, $num_files = null) { if (!$dir) { $dir = conf::pathBase() . "/backup/sql"; } $list = file::getFileList($dir); $time_stamp = 0; foreach ($list as $val) { $file = explode('.', $val); if (is_numeric($file[0])) { if ($file[0] > $time_stamp) { $time_stamp = $file[0]; } } } return $time_stamp; }
/** * Loads all base modules * Base modules are placed in vendor/diversen/simple-php-classes */ public static function loadBaseModules() { $command_path = __DIR__ . "/../shell"; $base_list = file::getFileList($command_path, array('search' => '.php')); foreach ($base_list as $val) { include_once $command_path . "/{$val}"; } }
/** * returns a array of all templates found in template_dir * @return array $templates */ public static function getAllTemplates() { return file::getFileList(conf::pathHtdocs() . "/templates", array('dir_only' => true)); }
/** * method for getting all templates located in conf::pathHtdocs()/template * used for settings current templates in profiles/profile/profile.inc file */ public function getTemplates() { $dir = conf::pathHtdocs() . "/templates"; $templates = file::getFileList($dir, array('dir_only' => true)); $ary = array(); foreach ($templates as $val) { $info = $this->getTemplateInfo($val); if (empty($info)) { continue; } $ary[] = $info; } return $ary; }
/** * CLI command: function for getting latest timestamp from /backup/full dir * * @return int backup with most recent timestamp */ function backup_get_latest_backup($type = null) { if ($type == 'files') { $dir = conf::pathBase() . "/backup/files"; } else { $dir = conf::pathBase() . "/backup/full"; } $list = file::getFileList($dir); $time_stamp = 0; foreach ($list as $key => $val) { $file = explode('.', $val); if (is_numeric($file[0])) { if ($file[0] > $time_stamp) { $time_stamp = $file[0]; } } } return $time_stamp; }
/** * function for doing a prompt install from shell mode * is a wrapper around other shell functions. */ function prompt_install() { common::echoMessage('Pick a version to install:', 'y'); $tags = git::getTagsInstallLatest() . PHP_EOL; $tags .= "master"; common::echoMessage($tags); $tag = common::readSingleline("Enter tag (version) to use:"); common::execCommand("git checkout {$tag}"); // Which profile to install $profiles = file::getFileList('profiles', array('dir_only' => true)); if (count($profiles) == 1) { $profile = array_pop($profiles); } else { common::echoMessage("List of profiles: "); foreach ($profiles as $val) { common::echoMessage("\t" . $val); } // select profile and load it $profile = common::readSingleline('Enter profile, and hit return: '); } common::echoMessage("Loading the profile '{$profile}'", 'y'); load_profile(array('profile' => $profile, 'config_only' => true)); common::echoMessage("Main configuration (placed in config/config.ini) for '{$profile}' is loaded", 'y'); // Keep base path. Ortherwise we will lose it when loading profile $base_path = conf::pathBase(); // Load the default config.ini settings as a skeleton conf::$vars['coscms_main'] = conf::getIniFileArray($base_path . '/config/config.ini', true); // Reset base path conf::setMainIni('base_path', $base_path); conf::defineCommon(); common::echoMessage("Enter MySQL credentials", 'y'); // Get configuration info $host = common::readSingleline('Enter your MySQL host: '); $database = common::readSingleline('Enter database name: '); $username = common::readSingleline('Enter database user: '******'Enter database users password: '******'Enter server host name: '); common::echoMessage("Writing database connection info to main configuration"); // Assemble configuration info conf::$vars['coscms_main']['url'] = "mysql:dbname={$database};host={$host};charset=utf8"; conf::$vars['coscms_main']['username'] = $username; conf::$vars['coscms_main']['password'] = $password; conf::$vars['coscms_main']['server_name'] = $server_name; // Write it to ini file $content = conf::arrayToIniFile(conf::$vars['coscms_main'], false); $path = conf::pathBase() . "/config/config.ini"; file_put_contents($path, $content); common::echoMessage("Your can also always change the config/config.ini file manually"); $options = array(); $options['profile'] = $profile; if ($tag == 'master') { $options['master'] = true; } common::echoMessage("Will now clone and install all modules", 'y'); cos_install($options); common::echoMessage("Create a super user", 'y'); useradd_add(); $login = "******"; common::echoMessage("If there was no errors you will be able to login at {$login}"); common::echoMessage("Remember to change file permissions. This will require super user"); common::echoMessage("E.g. like this:"); common::echoMessage("sudo ./coscli.sh file --chmod-files"); }