fputs(STDOUT, "!= AMOS GIT DIFF: {$version->dir} [{$amosstring->id},{$frankenstylename}]\n"); $gitstring->clean_text(); $fixcomponent->add_string($gitstring); continue; } } foreach ($gitcomponent->get_iterator() as $gitstring) { $amosstring = $amoscomponent->get_string($gitstring->id); if (is_null($amosstring)) { fputs(STDOUT, ">> GIT ONLY: {$version->dir} [{$gitstring->id},{$frankenstylename}]\n"); $gitstring->clean_text(); $fixcomponent->add_string($gitstring); continue; } } if ($fixcomponent->has_string()) { $stage->add($fixcomponent); } $fixcomponent->clear(); $amoscomponent->clear(); $gitcomponent->clear(); } } if ($options['execute']) { $stage->commit('Fixing the drift between Git and AMOS repository', array('source' => 'fixdrift', 'userinfo' => 'AMOS-bot <*****@*****.**>')); } else { list($x, $y, $z) = mlang_stage::analyze($stage); if ($x > 0) { fputs(STDOUT, "There are {$x} string changes prepared for sync execution\n"); } }
/** * Stores the stash into the stash pool * * Dumps the serialized stash contents into a file in moodledata and creates new record * in database table amos_stashes. Sets $this->hash and $this->id. In a special case of * autosave stashes where their id is known in advance, this methods updates the stashed * information. */ public function push() { global $DB; if (is_null($this->hash)) { $this->set_hash(); } $this->save_into_file(); list($strings, $languages, $components) = mlang_stage::analyze($this->stage); if (is_null($this->id)) { $record = new stdclass(); $record->ownerid = $this->ownerid; $record->hash = $this->hash; $record->languages = $languages; $record->components = $components; $record->strings = $strings; $record->timecreated = $this->timecreated; $record->timemodified = null; $record->name = $this->name; $record->message = $this->message; $this->id = $DB->insert_record('amos_stashes', $record); } else { $record = new stdclass(); $record->id = $this->id; $record->languages = $languages; $record->components = $components; $record->strings = $strings; $record->timemodified = time(); $DB->update_record('amos_stashes', $record); } }
/** * Factory method using an instance if {@link mlang_stash} as a data source * * @param mlang_stash $stash * @param stdClass $owner owner user data * @return local_amos_stash new instance */ public static function instance_from_mlang_stash(mlang_stash $stash, stdClass $owner) { if ($stash->ownerid != $owner->id) { throw new coding_exception('Stash owner mismatch'); } $new = new local_amos_stash(); $new->id = $stash->id; $new->name = $stash->name; $new->timecreated = $stash->timecreated; $stage = new mlang_stage(); $stash->apply($stage); list($new->strings, $new->languages, $new->components) = mlang_stage::analyze($stage); $stage->clear(); unset($stage); $new->components = explode('/', trim($new->components, '/')); $new->languages = explode('/', trim($new->languages, '/')); $new->owner = $owner; if ($stash->hash === 'xxxxautosaveuser' . $new->owner->id) { $new->isautosave = true; } else { $new->isautosave = false; } return $new; }
if ($maintainerof !== 'all') { if (!in_array($contribution->lang, $maintainerof)) { print_error('contributionaccessdenied', 'local_amos'); } } $author = $DB->get_record('user', array('id' => $contribution->authorid)); } else { $author = $USER; } // get the contributed components and rebase them to see what would happen $stash = mlang_stash::instance_from_id($contribution->stashid); $stage = new mlang_stage(); $stash->apply($stage); list($origstrings, $origlanguages, $origcomponents) = mlang_stage::analyze($stage); $stage->rebase(); list($rebasedstrings, $rebasedlanguages, $rebasedcomponents) = mlang_stage::analyze($stage); if ($stage->has_component()) { } else { // nothing left after rebase } $contribinfo = new local_amos_contribution($contribution, $author); $contribinfo->language = implode(', ', array_filter(array_map('trim', explode('/', $origlanguages)))); $contribinfo->components = implode(', ', array_filter(array_map('trim', explode('/', $origcomponents)))); $contribinfo->strings = $origstrings; $contribinfo->stringsreb = $rebasedstrings; echo $output->render($contribinfo); echo html_writer::start_tag('div', array('class' => 'contribactions')); if ($maintainerof) { if ($contribution->status == local_amos_contribution::STATE_NEW) { echo $output->single_button(new moodle_url($PAGE->url, array('review' => $id)), get_string('contribstartreview', 'local_amos'), 'post', array('class' => 'singlebutton review')); }