Beispiel #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();
}
Beispiel #2
0
/**
 * build source package with more simple form of install. 
 * @param array $options
 */
function cos_build_simple($options = null)
{
    $dir = getcwd();
    $name = basename($dir);
    if (file_exists("./build/{$name}")) {
        common::execCommand("sudo rm -rf ./build/{$name}*");
    }
    common::execCommand("mkdir ./build/{$name}");
    $htdocs = "cp -rf htdocs/* ./build/{$name}";
    common::execCommand($htdocs);
    $domain = conf::getMainIni('domain');
    if (!$domain) {
        $domain = 'default';
    }
    $files_rm = "sudo rm -rf ./build/{$name}/files/{$domain}/*";
    common::execCommand($files_rm);
    $config = "mkdir ./build/{$name}/config";
    common::execCommand($config);
    $tmp_dir = "mkdir ./build/{$name}/tmp";
    common::execCommand($tmp_dir);
    $profiles = "cp -rf profiles ./build/{$name}";
    common::execCommand($profiles);
    $sql_scripts = "cp -rf scripts ./build/{$name}";
    common::execCommand($sql_scripts);
    $cli = "cp -rf coscli.sh ./build/{$name}";
    common::execCommand($cli);
    $composer = "cp -rf composer.json ./build/{$name}";
    common::execCommand($composer);
    // reset database password
    $ary = conf::getIniFileArray("./config/config.ini");
    $profile = new profile();
    $ary = $profile->iniArrayPrepare($ary);
    // clean ini settings for secrets
    $ini_settings = conf::arrayToIniFile($ary);
    // add ini dist file
    file_put_contents("./build/{$name}/config/config.ini-dist", $ini_settings);
    $index = "cp -rf htdocs/index.php ./build/{$name}/index.php";
    common::execCommand($index);
    $phar_cli = "cp -rf phar-cli.php ./build/{$name}/";
    common::execCommand($phar_cli);
    $phar_web = "cp -rf phar-web.php ./build/{$name}/";
    common::execCommand($phar_web);
    $module_dir = conf::pathModules();
    $modules = "cp -rf {$module_dir} ./build/{$name}";
    common::execCommand($modules);
    $vendor = "cp -rf vendor ./build/{$name}";
    common::execCommand($vendor);
    $rm_git = "rm `find ./build/{$name} -name '.git'` -rf";
    common::execCommand($rm_git);
    $rm_ignore = "rm `find ./build/{$name} -name '.gitignore'` -rf";
    common::execCommand($rm_ignore);
    $rm_doc = "rm -rf ./build/vendor/doc";
    common::execCommand($rm_doc);
    $output = array();
    exec('git tag -l', $output);
    $version = array_pop($output);
    $command = "cd  ./build && tar -Pczf {$name}-{$version}.tar.gz {$name} ";
    common::execCommand($command);
}
Beispiel #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();
}
Beispiel #4
0
/**
 * wrapper function for creating a profile
 */
function create_profile($options)
{
    $pro = new profile();
    $pro->createProfile($options['profile']);
}
Beispiel #5
0
function cos_phar_web_create()
{
    // move sources to build dir.
    // e.g. build/coscms
    cos_build_simple();
    // some base values
    $dir = getcwd();
    $base = basename($dir);
    // dir we build phar from
    $build_from_dir = "{$dir}/build/{$base}";
    // when creating a web phar we add
    // config.ini
    // this is done so that on first exectution of the
    // phar archive we will create this file and a .sqlite database.
    $build_phar_dir = "build/phar";
    if (!file_exists($build_phar_dir)) {
        common::execCommand("mkdir {$build_phar_dir}");
    }
    // hidden .config file
    // cos_exec("cp -f config/config.ini $build_from_dir/tmp/.config.ini");
    // reset database password
    $ary = conf::getIniFileArray("./config/config.ini");
    $profile = new profile();
    // rm secrets
    $ary = $profile->iniArrayPrepare($ary);
    // add sqlite database to build phar dir
    if (conf::getMainIni('phar_sqlite')) {
        db_to_sqlite();
        // mv sqlite database into hidden file
        common::execCommand("cp -R sqlite/database.sql {$build_from_dir}/tmp/.database.sql");
        common::execCommand("chmod 777 {$build_from_dir}/tmp/.database.sql");
        common::execCommand("mkdir {$build_from_dir}/sqlite");
        unset($ary['db_init']);
        $ary['url'] = 'sqlite:.database.sql';
    }
    // no caching of assets. Place css and js in file
    $ary['cached_assets'] = 0;
    $ary['cashed_assets_reload'] = 0;
    $ary['cached_assets_minify'] = 0;
    $ary['cached_assets_compress'] = 0;
    $ary['cached_assets_inline'] = 1;
    if (conf::getMainIni('phar_files')) {
        common::execCommand("cp -rf htdocs/files {$build_from_dir}");
        common::execCommand("sudo chown -R 777 {$build_from_dir}/files");
    }
    $ini_settings = conf::arrayToIniFile($ary);
    file_put_contents("{$build_from_dir}/tmp/.config.ini", $ini_settings);
    chdir($build_phar_dir);
    $output = "{$base}-web.phar";
    $phar = new Phar($output);
    $phar->buildFromDirectory($build_from_dir);
    $stub = $phar->createDefaultStub('phar-web.php', 'phar-web.php');
    $phar->setStub($stub);
    $phar->stopBuffering();
    echo "Web phar executable file created from current source ({$output})\n";
    echo "Serve it e.g. with the built-in server. Like this:\n";
    echo "cd {$build_phar_dir}\n";
    echo "php -S localhost:8080 {$base}-web.phar\n";
    exit(0);
}
/**
 * wrapper function for settings template
 * change template in db to load specified template.
 * @param   array   options
 */
function set_template($options)
{
    $template = $options['template'];
    $pro = new profile();
    return $pro->setProfileTemplate($template);
}
Beispiel #7
0
/**
 * function for tagging all modules and templates
 * @param   array   options from cli env
 */
function cos_git_tag_all($options)
{
    $profile = new profile();
    $version = common::readSingleline('Enter tag version to use ');
    $modules = $profile->getModules();
    foreach ($modules as $key => $val) {
        $tags = git::getTagsModule($val['module_name'], 'module');
        if (in_array($version, $tags)) {
            common::echoStatus('NOTICE', 'y', "Tag already exists local for module '{$val['module_name']}'.");
        }
        $val['new_version'] = $version;
        cos_git_tag($val, 'module');
    }
    $templates = $profile->getTemplates();
    foreach ($templates as $key => $val) {
        $tags = git::getTagsModule($val['module_name'], 'template');
        if (in_array($version, $tags)) {
            common::echoStatus('NOTICE', 'y', "Tag already exists local for template '{$val['module_name']}'");
        }
        $val['new_version'] = $version;
        cos_git_tag($val, 'template');
    }
}
Beispiel #8
0
function cos_git_compare_master()
{
    $profile = new profile();
    //$version = common::readSingleline('Enter tag version to use ');
    $modules = $profile->getModules();
    foreach ($modules as $key => $val) {
        $tags = git::getTagsModule($val['module_name'], 'module');
        $latest = array_values(array_slice($tags, -1))[0];
        common::execCommand("cd ./modules/{$val['module_name']} && git diff {$latest} --raw");
    }
    $templates = $profile->getTemplates();
    foreach ($templates as $key => $val) {
        $tags = git::getTagsModule($val['module_name'], 'template');
        $latest = array_values(array_slice($tags, -1))[0];
        common::execCommand("cd ./htdocs/templates/{$val['module_name']} && git diff {$latest} --raw");
    }
}