Exemplo n.º 1
0
function parseArguments()
{
    global $argv;
    $verbose = false;
    $fileName = FILE_NAME;
    for ($i = 1; $i < count($argv); $i++) {
        $arg = $argv[$i];
        if ($arg == "-v") {
            $verbose = true;
        } else {
            if ($arg == '-f') {
                $i++;
                $fileName = $argv[$i];
            } else {
                if ($arg == '-t') {
                    runTestSuite();
                    exit;
                } else {
                    OS::errorAndExit("Unknown flag: {$arg}");
                }
            }
        }
    }
    return array($verbose, $fileName);
}
function GetWotdFromSubject($subject)
{
    $parts = preg_split("/\\s+/", trim($subject));
    if (count($parts) != 2) {
        OS::errorAndExit("Ignoring message '{$subject}' due to invalid subject", 0);
    }
    if ($parts[0] != Config::get('WotD.password')) {
        OS::errorAndExit("Ignoring message '{$subject}' due to invalid password in the subject", 0);
    }
    return $parts[1];
}
Exemplo n.º 3
0
$LICENSE = util_getRootPath() . '/tools/dumpDatabaseLicense.txt';
$parts = db_splitDsn();
$COMMON_COMMAND = sprintf("mysqldump -h %s -u %s --password='******' %s ", $parts['host'], $parts['user'], $parts['password'], $parts['database']);
$schemaOnly = array('RecentLink', 'Cookie', 'UserWordBookmark', 'DefinitionSimple', 'history_Comment', 'history_Definition');
$currentYear = date("Y");
// Full/Public dump: the public dump omits the user table, which contains emails and md5-ed passwords.
$doFullDump = false;
for ($i = 1; $i < count($argv); $i++) {
    $arg = $argv[$i];
    if ($arg == "--full") {
        $doFullDump = true;
    } else {
        if ($arg == '--public') {
            $doFullDump = false;
        } else {
            OS::errorAndExit("Unknown flag: {$arg}");
        }
    }
}
log_scriptLog('Running dumpDatabase.php with argument ' . ($doFullDump ? 'full' : 'public'));
$dbName = $parts['database'];
$tablesToIgnore = '';
foreach ($schemaOnly as $table) {
    $tablesToIgnore .= "--ignore-table={$dbName}.{$table} ";
}
if ($doFullDump) {
    $remoteFile = '/download/mirrorAccess/dex-database.sql.gz';
} else {
    $remoteFile = '/download/dex-database.sql.gz';
    $tablesToIgnore .= "--ignore-table={$dbName}.User --ignore-table={$dbName}.Definition --ignore-table={$dbName}.Source --ignore-table={$dbName}.diverta_Book --ignore-table={$dbName}.divertaIndex ";
}
Exemplo n.º 4
0
$merge = false;
$split = false;
foreach ($argv as $i => $arg) {
    if ($arg == "--merge") {
        $merge = true;
    } else {
        if ($arg == '--split') {
            $split = true;
        } else {
            if ($i) {
                OS::errorAndExit("Unknown flag: {$arg}");
            }
        }
    }
}
if ($merge === $split) {
    OS::errorAndExit("Please specify exactly one of --merge or --split");
}
if ($merge) {
    OS::executeAndAssert("convert -size {$GEOMETRY} xc:white {$SPRITE}");
    foreach ($IMAGES as $i) {
        if ($i['bg']) {
            OS::executeAndAssert(sprintf("convert {$SPRITE} -fill '%s' -draw 'rectangle %s,%s %s,%s' {$SPRITE}", $i['bg'], $i['x'], $i['y'], $i['x'] + $i['width'] - 1, $i['y'] + $i['height'] - 1));
        }
        OS::executeAndAssert("convert {$SPRITE} {$i['file']} -geometry +{$i['x']}+{$i['y']} -compose over -composite {$SPRITE}");
    }
    OS::executeAndAssert("optipng {$SPRITE}");
    print "Composed and optimized sprite in {$SPRITE}\n";
} else {
    print "Splitting is not implemented yet.\n";
}
Exemplo n.º 5
0
<?php

require_once '../../phplib/util.php';
$FIELDS = array('Comment' => array('Contents', 'HtmlContents'), 'Definition' => array('Lexicon', 'InternalRep', 'HtmlRep'), 'GuideEntry' => array('Correct', 'CorrectHtml', 'Wrong', 'WrongHtml', 'Comments', 'CommentsHtml'), 'RecentLink' => array('Text'), 'Source' => array('ShortName', 'Name', 'Author', 'Publisher', 'Year'), 'Typo' => array('Problem'), 'User' => array('Name'), 'inflections' => array('infl_descr'), 'lexems' => array('lexem_forma', 'lexem_neaccentuat', 'lexem_utf8_general', 'lexem_invers', 'lexem_descr', 'lexem_parse_info', 'lexem_comment'), 'model_types' => array('mt_descr'), 'models' => array('model_descr', 'model_exponent'), 'transforms' => array('transf_from', 'transf_to', 'transf_descr'), 'wordlist' => array('wl_form', 'wl_neaccentuat', 'wl_utf8_general'));
$MAPPINGS = array(array('ş', 'ș'), array('Ş', 'Ș'), array('ţ', 'ț'), array('Ţ', 'Ț'));
foreach ($FIELDS as $table => $fields) {
    foreach ($fields as $field) {
        foreach ($MAPPINGS as $mapping) {
            $query = "update {$table} set {$field} = replace({$field}, '{$mapping[0]}', '{$mapping[1]}')";
            print "{$query}\n";
            if (mysql_query($query)) {
                print "    " . mysql_affected_rows() . " rows affected.\n";
            } else {
                OS::errorAndExit(mysql_error());
            }
        }
    }
}
Exemplo n.º 6
0
<?php

require_once __DIR__ . '/../phplib/util.php';
ini_set('max_execution_time', '3600');
ini_set('memory_limit', '256M');
assert_options(ASSERT_BAIL, 1);
log_scriptLog('Running rebuildFullTextIndex.php.');
if (!Lock::acquire(LOCK_FULL_TEXT_INDEX)) {
    OS::errorAndExit('Lock already exists!');
    exit;
}
log_scriptLog("Clearing table FullTextIndex.");
db_execute('truncate table FullTextIndex');
$stopWordForms = array_flip(db_getArray('select distinct i.formNoAccent ' . 'from Lexem l, LexemModel lm, InflectedForm i ' . 'where l.id = lm.lexemId ' . 'and lm.id = i.lexemModelId ' . 'and l.stopWord'));
$ifMap = array();
$dbResult = db_execute('select id, internalRep from Definition where status = 0');
$numDefs = $dbResult->rowCount();
$defsSeen = 0;
$indexSize = 0;
$fileName = tempnam(Config::get('global.tempDir'), 'index_');
$handle = fopen($fileName, 'w');
log_scriptLog("Writing index to file {$fileName}.");
DebugInfo::disable();
foreach ($dbResult as $dbRow) {
    $words = extractWords($dbRow[1]);
    foreach ($words as $position => $word) {
        if (!isset($stopWordForms[$word])) {
            if (!array_key_exists($word, $ifMap)) {
                cacheWordForm($word);
            }
            if (array_key_exists($word, $ifMap)) {
Exemplo n.º 7
0
function parseArguments()
{
    global $argv;
    $verbose = false;
    $fileName = '/tmp/dn.online';
    for ($i = 1; $i < count($argv); $i++) {
        $arg = $argv[$i];
        if ($arg == "-v") {
            $verbose = true;
        } else {
            if ($arg == '-f') {
                $i++;
                $fileName = $argv[$i];
            } else {
                OS::errorAndExit("Unknown flag: {$arg}");
            }
        }
    }
    return array($verbose, $fileName);
}
            }
        }
    }
    if (++$defsSeen % 10000 == 0) {
        $runTime = DebugInfo::getRunningTimeInMillis() / 1000;
        $speed = round($defsSeen / $runTime);
        log_scriptLog("{$defsSeen} of {$numDefs} definitions indexed ({$speed} defs/sec). " . "Word map has " . count($ifMap) . " entries. " . "Memory used: " . round(memory_get_usage() / 1048576, 1) . " MB.");
    }
}
fclose($handle);
log_scriptLog("{$defsSeen} of {$numDefs} definitions indexed.");
log_scriptLog("Index size: {$indexSize} entries.");
OS::executeAndAssert("chmod 666 {$fileName}");
log_scriptLog("Importing file {$fileName} into table FullTextIndex");
if (!db_execute("load data local infile '{$fileName}' into table FullTextIndex")) {
    OS::errorAndExit("MySQL error");
}
util_deleteFile($fileName);
if (!Lock::release(LOCK_FULL_TEXT_INDEX)) {
    log_scriptLog('WARNING: could not release lock!');
}
log_scriptLog('rebuildFullTextIndex.php completed successfully ' . '(against all odds)');
/***************************************************************************/
function extractWords($text)
{
    $alphabet = 'abcdefghijklmnopqrstuvwxyzăâîșț';
    $text = mb_strtolower($text);
    $text = AdminStringUtil::removeAccents($text);
    $result = array();
    $currentWord = '';
    $chars = AdminStringUtil::unicodeExplode($text);