⌈⌋ ⎇ branch:  freshcode


Artifact [3fda48ba6b]

Artifact 3fda48ba6bf6551dc0f2f000316084eb310d24f3:

  • File cron.daily/tags.php — part of check-in [b4a8119636] at 2014-12-07 21:11:54 on branch trunk — Added transactions as suggested by Lothar. (user: mario size: 1245)

<?php
/**
 * api: cli
 * title: Update `tags` table
 * description: Splits out tags from according column in project `release`.
 * version: 0.4
 * category: postprocessing
 * type: cron
 * x-cron: 10 *\/2 * * *
 *
 * Manually update tags table.
 *   - Splits up comma separated release.tags field
 *   - Maximum of 10 tags each
 *   - Populates separate tags table with name=>tag list.
 *
 * While this could be done in the release::update/::store handler,
 * it's not really urgent to have per-project tags mirrored there.
 * (Externalizing this avoids immediate database load, though not locks;
 * but the transactions cut down on that.)
 *
 * Runs every 2 hours.
 *
 */

chdir(dirname(__DIR__)); 
include("config.php");

/**
 * Scan each project,
 * split up `tags` as CSV and just fille up according tags table.
 *
 */
db("BEGIN IMMEDIATE TRANSACTION");
foreach (db("SELECT name, tags, MAX(t_changed) FROM release_versions GROUP BY name")->fetchAll() as $entry) {

    $name = $entry["name"];
    $tags = array_slice(array_filter(p_csv($entry["tags"])), 0, 10);

    db("DELETE FROM tags WHERE name=?", $name);
    foreach ($tags as $t) {
        db("INSERT INTO tags (name, tag) VALUES (?, ?)", $name, $t);
    }

}
db("END TRANSACTION");