Example #1
0
function qa_create_event_for_tags($tagstring, $questionid, $updatetype, $lastuserid, $timestamp = null)
{
    require_once QA_INCLUDE_DIR . 'util/string.php';
    require_once QA_INCLUDE_DIR . 'db/post-create.php';
    $tagwordids = qa_db_word_mapto_ids(array_unique(qa_tagstring_to_tags($tagstring)));
    foreach ($tagwordids as $wordid) {
        qa_db_event_create_for_entity(QA_ENTITY_TAG, $wordid, $questionid, $questionid, $updatetype, $lastuserid, $timestamp);
    }
}
function qa_db_word_mapto_ids_add($words)
{
    $wordtoid = qa_db_word_mapto_ids($words);
    $wordstoadd = array();
    foreach ($words as $word) {
        if (!isset($wordtoid[$word])) {
            $wordstoadd[] = $word;
        }
    }
    if (count($wordstoadd)) {
        qa_db_query_sub('LOCK TABLES ^words WRITE');
        // to prevent two requests adding the same word
        $wordtoid = qa_db_word_mapto_ids($words);
        // map it again in case table content changed before it was locked
        $rowstoadd = array();
        foreach ($words as $word) {
            if (!isset($wordtoid[$word])) {
                $rowstoadd[] = array($word);
            }
        }
        qa_db_query_sub('INSERT IGNORE INTO ^words (word) VALUES $', $rowstoadd);
        qa_db_query_sub('UNLOCK TABLES');
        $wordtoid = qa_db_word_mapto_ids($words);
        // do it one last time
    }
    return $wordtoid;
}