Ejemplo n.º 1
0
function revert_dict($rev_id)
{
    if (!$rev_id) {
        throw new UnexpectedValueException();
    }
    check_permission(PERM_DICT);
    $res = sql_pe("SELECT lemma_id, rev_text FROM dict_revisions WHERE rev_id=? LIMIT 1", array($rev_id));
    $lemma_id = $res[0]['lemma_id'];
    $old_rev = sql_pe("SELECT rev_text FROM dict_revisions WHERE lemma_id=? and is_last=1 LIMIT 1", array($lemma_id));
    sql_begin();
    $new_set_id = create_revset("Отмена правки, возврат к версии d{$rev_id}");
    $new_rev_id = new_dict_rev($lemma_id, $res[0]['rev_text'], $new_set_id);
    // updated forms
    $pdr = parse_dict_rev($old_rev[0]['rev_text']);
    enqueue_updated_forms(calculate_updated_forms($pdr, parse_dict_rev($res[0]['rev_text'])), $new_rev_id);
    sql_commit();
}
Ejemplo n.º 2
0
function dict_save($array)
{
    check_permission(PERM_DICT);
    //it may be a totally new lemma
    if ($array['lemma_id'] == -1) {
        return dict_add_lemma($array);
    }
    // lemma might have been deleted, it is not editable then
    $r = sql_fetch_array(sql_query("SELECT deleted FROM dict_lemmata WHERE lemma_id = " . $array['lemma_id'] . " LIMIT 1"));
    if ($r['deleted']) {
        throw new Exception("This lemma is not editable");
    }
    $lemma_text = trim($array['lemma_text']);
    if (!$lemma_text) {
        throw new UnexpectedValueException();
    }
    $ltext = $array['form_text'];
    $lgram = $array['form_gram'];
    $gram_order = dict_get_grammemes_by_order();
    $lemma_gram_new = prepare_gram_array($array['lemma_gram'], $gram_order);
    $r = sql_fetch_array(sql_query("SELECT rev_text FROM dict_revisions WHERE lemma_id=" . $array['lemma_id'] . " AND is_last=1 LIMIT 1"));
    $old_rev_parsed = parse_dict_rev($old_xml = $r['rev_text']);
    $old_lemma_text = $old_rev_parsed['lemma']['text'];
    $new_paradigm = array();
    foreach ($ltext as $i => $text) {
        $text = trim($text);
        if ($text == '') {
            //the form is to be deleted, so we do nothing
        } elseif (strpos($text, ' ') !== false) {
            throw new UnexpectedValueException();
        } else {
            //TODO: perhaps some data validity check?
            array_push($new_paradigm, array($text, prepare_gram_array($lgram[$i], $gram_order)));
        }
    }
    sql_begin();
    //array -> xml
    $new_xml = make_dict_xml($lemma_text, $lemma_gram_new, $new_paradigm);
    if ($lemma_text != $old_lemma_text || $new_xml != $old_xml) {
        //something's really changed
        if ($lemma_text != $old_lemma_text) {
            sql_pe("UPDATE dict_lemmata SET lemma_text=? WHERE lemma_id=?", array($lemma_text, $array['lemma_id']));
        }
        $rev_id = new_dict_rev($array['lemma_id'], $new_xml, 0, $array['comment']);
        enqueue_updated_forms(calculate_updated_forms($old_rev_parsed, parse_dict_rev($new_xml)), $rev_id);
        sql_commit();
    }
    return $array['lemma_id'];
}