示例#1
0
/**
 * This is a hacky way how to populate a forum at lang.moodle.org with commits into the core
 *
 * @param mlang_stage $stage
 * @param string $commitmsg
 * @param string $committer
 * @param string $committeremail
 * @param string $commithash
 * @param string $fullcommitmsg
 * @return void
 */
function amos_core_commit_notify(mlang_stage $stage, $commitmsg, $committer, $committeremail, $commithash, $fullcommitmsg)
{
    global $CFG;
    $DB;
    require_once $CFG->dirroot . '/mod/forum/lib.php';
    if ($CFG->wwwroot !== 'http://lang.moodle.org') {
        // this is intended for lang.moodle.org portal only
        return;
    }
    if (!$stage->has_component()) {
        // nothing to commit
        return;
    }
    // these are hard-coded values of a forum to inject commit messages into
    $courseid = 2;
    // course 'Translating Moodle'
    $cmid = 7;
    // forum 'Notification of string changes'
    $userid = 2;
    // user 'AMOS bot'
    $cm = get_coursemodule_from_id('forum', $cmid);
    $discussion = new stdclass();
    $discussion->course = $courseid;
    $discussion->forum = $cm->instance;
    $discussion->name = substr(s('[AMOS commit] ' . $commitmsg), 0, 255);
    $discussion->message = 'Author: ' . $committer . "\n";
    $discussion->message .= $fullcommitmsg . "\n\n";
    $discussion->message .= 'http://git.moodle.org/gw?p=moodle.git;a=commit;h=' . $commithash . "\n";
    $discussion->message .= 'http://github.com/moodle/moodle/commit/' . $commithash . "\n\n";
    $standardplugins = local_amos_standard_plugins();
    foreach ($stage->get_iterator() as $component) {
        foreach ($component->get_iterator() as $string) {
            if ($string->deleted) {
                $sign = '-  ';
            } else {
                $sign = '+  ';
            }
            if (isset($standardplugins[$component->version->dir][$component->name])) {
                $name = $standardplugins[$component->version->dir][$component->name];
            } else {
                $name = $component->name;
            }
            $discussion->message .= $sign . $component->version->dir . ' en [' . $string->id . ',' . $name . "]\n";
        }
    }
    $discussion->message = s($discussion->message);
    $discussion->messageformat = FORMAT_MOODLE;
    $discussion->messagetrust = 0;
    $discussion->attachments = null;
    $discussion->mailnow = 1;
    $message = null;
    forum_add_discussion($discussion, null, $message, $userid);
}
}
$version = mlang_version::by_branch($options['version']);
if (is_null($version)) {
    echo 'Invalid version' . PHP_EOL;
    exit(3);
}
$component = mlang_component::from_phpfile($filepath, $options['lang'], $version, $options['timemodified'], $options['name'], (int) $options['format']);
fputs(STDOUT, "{$component->name} {$component->version->label} {$component->lang}" . PHP_EOL);
$stage = new mlang_stage();
$stage->add($component);
$stage->rebase(null, true, $options['timemodified']);
if (!$stage->has_component()) {
    echo 'No strings found (after rebase)' . PHP_EOL;
    exit(4);
}
foreach ($stage->get_iterator() as $component) {
    foreach ($component->get_iterator() as $string) {
        if ($string->deleted) {
            $sign = '-';
        } else {
            $sign = '+';
        }
        echo $sign . ' ' . $string->id . PHP_EOL;
    }
}
echo PHP_EOL;
$continue = cli_input('Continue? [y/n]', 'n', array('y', 'n'));
if ($continue !== 'y') {
    echo 'Import aborted' . PHP_EOL;
    exit(5);
}
示例#3
0
 /**
  * Returns the number of strings and the list of languages and components in the stage
  *
  * Languages and components lists are returned as strings, slash is used as a delimiter
  * and there is heading and trailing slash, too.
  *
  * @return array of (int)strings, (string)languages, (string)components
  */
 public static function analyze(mlang_stage $stage)
 {
     $strings = 0;
     $languages = array();
     $components = array();
     foreach ($stage->get_iterator() as $component) {
         if ($s = $component->get_number_of_strings()) {
             $strings += $s;
             if (!isset($components[$component->name])) {
                 $components[$component->name] = true;
             }
             if (!isset($languages[$component->lang])) {
                 $languages[$component->lang] = true;
             }
         }
     }
     $languages = '/' . implode('/', array_keys($languages)) . '/';
     $components = '/' . implode('/', array_keys($components)) . '/';
     return array($strings, $languages, $components);
 }