コード例 #1
0
function cos_upgrade_to($version)
{
    common::echoMessage("Will now pull source, and checkout latest tag", 'y');
    $command = "git fetch --tags && git checkout master && git pull && git checkout {$version}";
    $ret = common::execCommand($command);
    if ($ret) {
        common::abort('Aborting upgrade');
    }
    common::echoMessage("Will upgrade vendor with composer according to version", 'y');
    $command = "composer update";
    $ret = common::systemCommand($command);
    if ($ret) {
        common::abort('Composer update failed.');
    }
    common::echoMessage("Will upgrade all modules and templates the versions in the profile", 'y');
    // Upgrade all modules and templates
    $profile = conf::getModuleIni('system_profile');
    if (!$profile) {
        $profile = 'default';
    }
    upgrade_from_profile(array('clone_only' => 1, 'profile' => $profile));
    // reload any changes
    common::echoMessage("Reloading all configuration files", 'y');
    $p = new profile();
    $p->reloadProfile($profile);
    common::echoMessage("Load modules changes into database", 'y');
    cos_config_reload();
}
コード例 #2
0
/**
 * 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']);
    }
}
コード例 #3
0
/**
 * function for installing coscms from a profile
 */
function cos_install($options = false)
{
    // we need a profile specified
    if (!isset($options['profile'])) {
        common::abort('You need to specifiy a profile');
    }
    // create files - logs/ - files/
    cos_create_files();
    // drop database
    drop_db_default($ary = array('silence' => 1));
    // create database
    create_db();
    // load default base sql.
    load_db_default();
    // Set up profile to install
    $pro = new profile();
    $pro->setProfileInfo($options['profile']);
    // install all the profile modules
    foreach ($pro->profileModules as $key => $val) {
        // check if master is specified. Else use profile version
        if (conf::getMainIni('git_use_master')) {
            $tag = 'master';
        } else {
            $tag = $val['module_version'];
        }
        $options['repo'] = $val['public_clone_url'];
        $options['version'] = $tag;
        //$val['module_version'];
        $options['module'] = $val['module_name'];
        // check out and install
        cos_git_install($options, 'module');
    }
    // install templates
    foreach ($pro->profileTemplates as $key => $val) {
        if (conf::getMainIni('git_use_master')) {
            $tag = 'master';
        } else {
            $tag = $val['module_version'];
        }
        $options['repo'] = $val['public_clone_url'];
        $options['version'] = $tag;
        //$val['module_version'];
        $options['template'] = $val['module_name'];
        // check out and install
        cos_git_install($options, 'template');
    }
    // load all profile ini files
    $pro->loadProfileFiles($options['profile']);
    // set template
    $pro->setProfileTemplate();
}
コード例 #4
0
function google_translate_path($options)
{
    if (!isset($options['path'])) {
        common::abort('You need to specify path to translate');
    }
    if (!isset($options['target'])) {
        common::abort('You need to specify target language to translate into');
    }
    $e = new google();
    $key = conf::getMainIni('google_translate_key');
    $e->key = $key;
    $e->setSingleDir($options['path']);
    $e->updateLang();
}
コード例 #5
0
ファイル: files.php プロジェクト: diversen/simple-php-classes
/**
 * Function for changing group settings on some files, which the server needs to 
 * have read and write access to. 
 * 
 * Change these files, so anon users does not have any access to them. 
 *
 * We read the user under which the web server is running. This is done by fetching
 * the `htdocs/whoami.php` script from the server. 
 *
 * @return void
 */
function cos_chmod_files()
{
    // Get group
    $group = conf::getServerUser();
    if (!$group) {
        common::abort('Could not fetch server user. Check if server_name is set in config/config.ini, and check if this server is running');
    }
    common::needRoot();
    $files_path = cos_files_group();
    $command = "chgrp -R {$group} {$files_path}";
    common::execCommand($command);
    $command = "chmod -R 770 {$files_path}";
    common::execCommand($command);
}
コード例 #6
0
function multi_shared_exec_command($options = null)
{
    $path = conf::pathBase() . "/config/multi/*";
    if (!isset($options['command'])) {
        common::abort('Specify a command');
        return 1;
    }
    $command = $options['command'];
    $dirs = file::getDirsGlob($path, array('basename' => 1));
    foreach ($dirs as $domain) {
        $exec_command = "./coscli.sh --domain={$domain} {$command}";
        common::echoMessage("Executing command: {$exec_command}");
        passthru($exec_command, $return_var);
    }
}
コード例 #7
0
/**
 * function for purgeing a template
 *
 * @param   array  options
 */
function purge_template($options)
{
    //uninstall_module($options);
    if (strlen($options['template']) == 0) {
        common::echoMessage("No such template: {$options['template']}");
        common::abort();
    }
    $template_path = conf::pathBase() . '/htdocs/templates/' . $options['template'];
    if (!file_exists($template_path)) {
        common::echoMessage("Template already purged: No such template path: {$template_path}");
        common::abort();
    }
    $command = "rm -rf {$template_path}";
    common::execCommand($command);
}
コード例 #8
0
/**
 * will update all translation files in specified language
 * @param array $options
 */
function translate_path($options)
{
    if (!isset($options['path'])) {
        common::abort('Add a path');
    }
    $path = conf::pathBase() . "/{$options['path']}";
    if (!file_exists($path) or !is_dir($path)) {
        common::abort('Specify a dir as path');
    }
    $e = new extractor();
    if (!empty($options['language'])) {
        $e->defaultLanguage = $options['language'];
    }
    $e->setSingleDir($options['path']);
    $e->updateLang();
    common::echoStatus('OK', 'g', 'Extraction done');
}
コード例 #9
0
ファイル: multi.php プロジェクト: gpawlik/suited-php-classes
/**
 * executes a shell command on all coscms systems install in parent dir (../) from
 * current dir
 * @param string $command
 * @return int $ret
 */
function multi_exec_shell_command($options = array())
{
    $path = conf::pathBase() . "/../";
    if (!isset($options['command'])) {
        common::abort('Specify a command');
        return 1;
    }
    $command = $options['command'];
    $dirs = file::getDirsGlob($path, array('basename' => 1));
    foreach ($dirs as $domain) {
        if (!file_exists("../{$domain}/config/config.ini")) {
            continue;
        }
        $exec_command = "cd ../{$domain} && {$command}";
        multi_passthru($exec_command);
    }
}
コード例 #10
0
ファイル: sqlite.php プロジェクト: gpawlik/suited-php-classes
function db_to_sqlite($options = array())
{
    $check = "which sequel";
    if (common::execCommand($check)) {
        common::echoMessage('You need sequel. Install it like this, e.g.:');
        common::echoMessage('sudo aptitude install ruby-sequel libsqlite3-ruby libmysql-ruby');
        common::abort();
    } else {
        common::echoStatus('OK', 'g', 'Sequel is installed');
    }
    $ok = false;
    $info = admin::getDbInfo();
    if (!$info) {
        return db_no_url();
    }
    if ($info['scheme'] == 'mysql') {
        $ok = true;
    }
    if ($info['scheme'] == 'mysqli') {
        $ok = true;
    }
    if (!$ok) {
        common::echoStatus('ERROR', 'r', 'Driver needs to be mysql or mysqli');
    }
    $fs = new Filesystem();
    $fs->remove('sqlite/database.sql');
    $username = conf::getMainIni('username');
    $password = conf::getMainIni('password');
    $command = "sequel ";
    $command .= "{$info['scheme']}://{$username}:{$password}@{$info['host']}/{$info['dbname']} ";
    $command .= "-C ";
    $command .= "sqlite://sqlite/database.sql";
    $ret = common::systemCommand($command);
    $base = conf::pathBase();
    if (!$ret) {
        $fs->chmod('sqlite/database.sql', 0777, 00, true);
        common::echoMessage('Sqlite database created. Edit config.ini and add:');
        common::echoMessage("sqlite:/{$base}/sqlite/database.sql");
    }
}
コード例 #11
0
/**
 * function for loading a database file into db specified in config.ini
 *
 * @param   array   options. You can specifiy a file to load in options.
 *                  e.g. <code>$options = array('File' => 'backup/sql/latest.sql')</code>
 * @return  int     the executed commands shell status 0 on success.
 */
function cos_db_load_table($options)
{
    if (!isset($options['table'])) {
        common::abort('Specify a table to load with a backup');
    }
    $dump_dir = "backup/sql/{$options['table']}";
    if (!file_exists($dump_dir)) {
        common::abort('Yet no backups');
    }
    $search = conf::pathBase() . "/backup/sql/{$options['table']}";
    $latest = get_latest_db_dump($search);
    if ($latest == 0) {
        common::abort('Yet no database dumps');
    }
    $latest = "backup/sql/{$options['table']}/" . $latest . ".sql";
    $db = admin::getDbInfo();
    if (!$db) {
        return db_no_url();
    }
    $command = "mysql --default-character-set=utf8  -u" . conf::$vars['coscms_main']['username'] . " -p" . conf::$vars['coscms_main']['password'] . " {$db['dbname']} < {$latest}";
    return $ret = common::execCommand($command);
}
コード例 #12
0
ファイル: cli.php プロジェクト: diversen/cli-framework
 /**
  * Parse the options and return the result
  * @return array $result
  */
 public static function parse()
 {
     // Try to parse the commandline options
     // If it is a -h command, then the parser will exit here.
     try {
         $result = self::$parser->parse();
     } catch (Exception $e) {
         common::abort($e->getMessage());
     }
     return $result;
 }
コード例 #13
0
ファイル: git.php プロジェクト: gpawlik/suited-php-classes
/**
 * function for showing git tags (just for testing)
 * @param array $options
 */
function cos_git_echo_remote_tags($options)
{
    if (empty($options['repo'])) {
        common::abort('You need to specify a repo');
    }
    $tags = git::getTagsRemote($options['repo']);
    if (empty($tags)) {
        common::abort('No tags');
    }
    $latest = git::getTagsRemoteLatest($options['repo']);
    common::echoMessage("Latest is: {$latest}");
}
コード例 #14
0
ファイル: db.php プロジェクト: diversen/simple-php-classes
function clone_db($options = array())
{
    if (!isset($options['File'])) {
        common::abort('Specify new database name');
    }
    $db = admin::getDbInfo(conf::getMainIni('url'));
    $old = $db['dbname'];
    $new_name = $options['File'];
    admin::cloneDB($old, $new_name);
}
コード例 #15
0
ファイル: main.php プロジェクト: gpawlik/suited-php-classes
 /**
  * Do this after the commandline options has been parsed. 
  * Examine the --domain flag and the --verbose flag
  * @param type $result
  */
 public static function afterParse($result)
 {
     $verbose = $result->options['verbose'];
     conf::setMainIni('verbose', $verbose);
     // Check if other domain than default is being used
     $domain = $result->options['domain'];
     conf::setMainIni('domain', $domain);
     if ($domain != 'default' || empty($domain)) {
         $domain_ini = conf::pathBase() . "/config/multi/{$domain}/config.ini";
         if (!file_exists($domain_ini)) {
             common::abort("No such domain - no configuration found: '{$domain_ini}'");
         } else {
             // If domain is used - Load domain specific configuration
             conf::loadMainCli();
         }
     }
 }
コード例 #16
0
 /**
  * Method for setting info about profile
  * @param string $profile name of the profile
  */
 public function setProfileInfo($profile)
 {
     $profile_dir = conf::pathBase() . "/profiles/{$profile}";
     if (!file_exists($profile_dir)) {
         common::abort("No such path to profiles: {$profile_dir}");
     }
     include $profile_dir . "/profile.inc";
     $this->profileModules = $_PROFILE_MODULES;
     $this->profileTemplates = $_PROFILE_TEMPLATES;
     $this->profileTemplate = $_PROFILE_TEMPLATE;
 }
コード例 #17
0
ファイル: module.php プロジェクト: gpawlik/suited-php-classes
/**
 * function for purging a module (compleate removal)
 *
 * @param   array  options
 */
function purge_module($options)
{
    // check if module is set
    if (strlen($options['module']) == 0) {
        common::echoMessage("No such module: {$options['module']}");
        common::abort();
    }
    // check if module exists
    $module_path = conf::pathModules() . '/' . $options['module'];
    if (!file_exists($module_path)) {
        common::echoMessage("module already purged: No such module path: {$module_path}");
        common::abort();
    }
    // it exists. Uninstall
    uninstall_module($options);
    // remove
    $command = "rm -rf {$module_path}";
    common::execCommand($command);
}