<commit_before><?php
/**
 * @package Airtime
 * @subpackage StorageServer
 * @copyright 2010 Sourcefabric O.P.S.
 * @license http://www.gnu.org/licenses/gpl.txt
 */

set_include_path(__DIR__.'/../../../airtime_mvc/library' . PATH_SEPARATOR . get_include_path());
require_once __DIR__.'/../../../airtime_mvc/application/configs/conf.php';
require_once(dirname(__FILE__).'/../../include/AirtimeInstall.php');
require_once(dirname(__FILE__).'/../../include/AirtimeIni.php');

AirtimeInstall::CreateZendPhpLogFile();

const CONF_DIR_BINARIES = "/usr/lib/airtime";
const CONF_FILE_AIRTIME = "/etc/airtime/airtime.conf";

function BypassMigrations($version)
{
    $appDir = __DIR__."/../../airtime_mvc";
    $dir = __DIR__;
    $command = "php $appDir/library/doctrine/migrations/doctrine-migrations.phar ".
                "--configuration=$dir/../../DoctrineMigrations/migrations.xml ".
                "--db-configuration=$appDir/library/doctrine/migrations/migrations-db.php ".
                "--no-interaction --add migrations:version $version";
    system($command);
}

function MigrateTablesToVersion($version)
{
    $appDir = __DIR__."/../../airtime_mvc";
    $dir = __DIR__;
    $command = "php $appDir/library/doctrine/migrations/doctrine-migrations.phar ".
                "--configuration=$dir/../../DoctrineMigrations/migrations.xml ".
                "--db-configuration=$appDir/library/doctrine/migrations/migrations-db.php ".
                "--no-interaction migrations:migrate $version";
    system($command);
}

function InstallAirtimePhpServerCode($phpDir)
{
    global $CC_CONFIG;

    $AIRTIME_SRC = realpath(__DIR__.'/../../../airtime_mvc');

    echo "* Installing PHP code to ".$phpDir.PHP_EOL;
    exec("mkdir -p ".$phpDir);
    exec("cp -R ".$AIRTIME_SRC."/* ".$phpDir);
}

function CopyUtils()
{
    $utilsSrc = __DIR__."/../../../utils";

    echo "* Installing binaries to ".CONF_DIR_BINARIES.PHP_EOL;
    exec("mkdir -p ".CONF_DIR_BINARIES);
    exec("cp -R ".$utilsSrc." ".CONF_DIR_BINARIES);
}

/* Removes pypo, media-monitor, show-recorder and utils from system. These will
   be reinstalled by the main airtime-upgrade script. */
function UninstallBinaries()
{
    echo "* Removing Airtime binaries from ".CONF_DIR_BINARIES.PHP_EOL;
    exec('rm -rf "'.CONF_DIR_BINARIES.'"');
}


function removeOldAirtimeImport(){
    exec('rm -f "/usr/lib/airtime/utils/airtime-import"');
    exec('rm -f "/usr/lib/airtime/utils/airtime-import.php"');
}

function updateAirtimeImportSymLink(){
    $dir = "/usr/lib/airtime/utils/airtime-import/airtime-import";
    exec("ln -s $dir /usr/bin/airtime-import");
}

function execSqlQuery($sql){
    global $CC_DBC;

    $result = $CC_DBC->query($sql);
    if (PEAR::isError($result)) {
        echo "* Failed sql query: $sql".PHP_EOL;
        echo "* Message {$result->getMessage()}".PHP_EOL;
        exit(1);
    }
}

function connectToDatabase(){
    global $CC_DBC, $CC_CONFIG;

    $values = parse_ini_file('/etc/airtime/airtime.conf', true);

    // Database config
    $CC_CONFIG['dsn']['username'] = $values['database']['dbuser'];
    $CC_CONFIG['dsn']['password'] = $values['database']['dbpass'];
    $CC_CONFIG['dsn']['hostspec'] = $values['database']['host'];
    $CC_CONFIG['dsn']['phptype'] = 'pgsql';
    $CC_CONFIG['dsn']['database'] = $values['database']['dbname'];

    $CC_DBC = DB::connect($CC_CONFIG['dsn'], FALSE);<commit_msg>CC-2279: Upgrade script for converting stor directory to new format<commit_after><?php
/**
 * @package Airtime
 * @subpackage StorageServer
 * @copyright 2010 Sourcefabric O.P.S.
 * @license http://www.gnu.org/licenses/gpl.txt
 */

set_include_path(__DIR__.'/../../../airtime_mvc/library' . PATH_SEPARATOR . get_include_path());
require_once __DIR__.'/../../../airtime_mvc/application/configs/conf.php';
require_once(dirname(__FILE__).'/../../include/AirtimeInstall.php');
require_once(dirname(__FILE__).'/../../include/AirtimeIni.php');

AirtimeInstall::CreateZendPhpLogFile();

const CONF_DIR_BINARIES = "/usr/lib/airtime";
const CONF_FILE_AIRTIME = "/etc/airtime/airtime.conf";

function BypassMigrations($version)
{
    $appDir = __DIR__."/../../airtime_mvc";
    $dir = __DIR__;
    $command = "php $appDir/library/doctrine/migrations/doctrine-migrations.phar ".
                "--configuration=$dir/../../DoctrineMigrations/migrations.xml ".
                "--db-configuration=$appDir/library/doctrine/migrations/migrations-db.php ".
                "--no-interaction --add migrations:version $version";
    system($command);
}

function MigrateTablesToVersion($version)
{
    $appDir = __DIR__."/../../airtime_mvc";
    $dir = __DIR__;
    $command = "php $appDir/library/doctrine/migrations/doctrine-migrations.phar ".
                "--configuration=$dir/../../DoctrineMigrations/migrations.xml ".
                "--db-configuration=$appDir/library/doctrine/migrations/migrations-db.php ".
                "--no-interaction migrations:migrate $version";
    system($command);
}

function InstallAirtimePhpServerCode($phpDir)
{
    global $CC_CONFIG;

    $AIRTIME_SRC = realpath(__DIR__.'/../../../airtime_mvc');

    echo "* Installing PHP code to ".$phpDir.PHP_EOL;
    exec("mkdir -p ".$phpDir);
    exec("cp -R ".$AIRTIME_SRC."/* ".$phpDir);
}

function CopyUtils()
{
    $utilsSrc = __DIR__."/../../../utils";

    echo "* Installing binaries to ".CONF_DIR_BINARIES.PHP_EOL;
    exec("mkdir -p ".CONF_DIR_BINARIES);
    exec("cp -R ".$utilsSrc." ".CONF_DIR_BINARIES);
}

/* Removes pypo, media-monitor, show-recorder and utils from system. These will
   be reinstalled by the main airtime-upgrade script. */
function UninstallBinaries()
{
    echo "* Removing Airtime binaries from ".CONF_DIR_BINARIES.PHP_EOL;
    exec('rm -rf "'.CONF_DIR_BINARIES.'"');
}


function removeOldAirtimeImport(){
    exec('rm -f "/usr/lib/airtime/utils/airtime-import"');
    exec('rm -f "/usr/lib/airtime/utils/airtime-import.php"');
}

function updateAirtimeImportSymLink(){
    $dir = "/usr/lib/airtime/utils/airtime-import/airtime-import";
    exec("ln -s $dir /usr/bin/airtime-import");
}

function execSqlQuery($sql){
    global $CC_DBC;

    $result = $CC_DBC->query($sql);
    if (PEAR::isError($result)) {
        echo "* Failed sql query: $sql".PHP_EOL;
        echo "* Message {$result->getMessage()}".PHP_EOL;
    }
}

function connectToDatabase(){
    global $CC_DBC, $CC_CONFIG;

    $values = parse_ini_file('/etc/airtime/airtime.conf', true);

    // Database config
    $CC_CONFIG['dsn']['username'] = $values['database']['dbuser'];
    $CC_CONFIG['dsn']['password'] = $values['database']['dbpass'];
    $CC_CONFIG['dsn']['hostspec'] = $values['database']['host'];
    $CC_CONFIG['dsn']['phptype'] = 'pgsql';
    $CC_CONFIG['dsn']['database'] = $values['database']['dbname'];

    $CC_DBC = DB::connect($CC_CONFIG['dsn'], FALSE);
{'fraction_non_alphanumeric': 0.18721727710491756, 'fraction_numerical': 0.0018969794250693127, 'mean_word_length': 3.4973753280839897, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 4}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4549143', 'n_tokens_mistral': 2354, 'n_tokens_neox': 2322, 'n_words': 357}