⌈⌋ ⎇ branch:  freshcode


Check-in [e0a1cddf81]

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Fix project-name normalization for raw incoming/pool imports.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: e0a1cddf81db27e0cb465f7afcfd60daa1c45fef
User & Date: mario 2014-10-28 21:14:44
Context
2014-10-28
21:15
raise to 150 character description for project name list check-in: b151f89ec3 user: mario tags: trunk
21:14
Fix project-name normalization for raw incoming/pool imports. check-in: e0a1cddf81 user: mario tags: trunk
21:13
Introduce structured metadata (HTML5 itemscope/itemtype) for Google display. check-in: 0a41182c57 user: mario tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Name change from cron.daily/import_spool.php to cron.daily/incoming_spool.php.

16
17
18
19
20
21
22
23
24









25
26

27
28
29




30
31







32
33
34
35
36
37
38
39
40
41
42
43
44
45
46

47
48
49
50
51
52
53
 * with a space (or not `^\w+:`) to be recognized.
 *
 */

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


// fresh insert attempts only every 3.5 hours









$last_release = db("SELECT t_published FROM release ORDER BY t_published DESC LIMIT 1")->t_published;
if (rand(0,2) and time() > $last_release + 3.35*3600) {



    // check files




    $files = glob("incoming/*");
    shuffle($files);







    foreach ($files as $fn) {

        // parse RFC-style text format
        $p = parse_release_fields(file_get_contents($fn));
        
        // skip if entry exists
        if (empty($p["name"]) or release::exists($p["name"], $p["version"])) {
            continue;
        }
        
        // store new project/release entry
        $rel = new release($p["name"]);
        $rel->update($p, [], [], TRUE);
        $rel->store();
        print_r($rel);


        // finish or continue
        if (rand(0,9)) {
           exit;
        }
        else {
           continue;








|
>
>
>
>
>
>
>
>
>
|
|
>
|

|
>
>
>
>

|
>
>
>
>
>
>
>












|


>







16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
 * with a space (or not `^\w+:`) to be recognized.
 *
 */

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


// import delays, 33% chance of skipping to next cron slot
if (rand(0,100) < 33) {
    return;
}
// minimum pause between imports
$pause = 3.35
       + (date("N") >= 6)
       - (count(glob("incoming/*")) >= 7);
print $pause;
// delay to last published project/version
$last_release = db("SELECT t_published FROM release WHERE NOT hidden AND NOT deleted ORDER BY t_published DESC LIMIT 1")->t_published;
if (time() < ($last_release + $pause * 3600)) {
   return;
}


// fresh insert attempts only every 3.5 hours
if (TRUE) {

    // read filenames, sort newest first
    $files = glob("incoming/*");
#    shuffle($files);
    $files = array_combine($files, array_map("filemtime", $files));
    asort($files);
    $files = array_keys($files);
#   print_r($files); exit;


    // loop over import files
    foreach ($files as $fn) {

        // parse RFC-style text format
        $p = parse_release_fields(file_get_contents($fn));
        
        // skip if entry exists
        if (empty($p["name"]) or release::exists($p["name"], $p["version"])) {
            continue;
        }
        
        // store new project/release entry
        $rel = new release($p["name"]);
        $rel->update($p, [], ["hidden"=>intval(!empty($p["hidden"]))], TRUE);
        $rel->store();
        print_r($rel);
        rename($fn, "oldimport/".basename($fn));

        // finish or continue
        if (rand(0,9)) {
           exit;
        }
        else {
           continue;

Changes to release.php.

164
165
166
167
168
169
170

171
172
173
174
175
176




177
178
179
180
181
182
183
    /**
     * Split up fields,
     * in particular the email out of `submitter`.
     *
     */
    function unpack(&$newdata) {


        if (!empty($newdata["submitter"]) and is_int(strpos($newdata["submitter"], "@"))
        and preg_match($rx = "/[^,;\s]+@[^,;\s]+/", $newdata["submitter"], $match))
        {
            $newdata["submitter_image"] = $match[0];
            $newdata["submitter"] = trim(preg_replace($rx, "", $newdata["submitter"]), ", ");
        }




    }


    /**
     * Retrieve latest published release version.
     *
     * @return array







>






>
>
>
>







164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
    /**
     * Split up fields,
     * in particular the email out of `submitter`.
     *
     */
    function unpack(&$newdata) {

        // extract new img@gravatar
        if (!empty($newdata["submitter"]) and is_int(strpos($newdata["submitter"], "@"))
        and preg_match($rx = "/[^,;\s]+@[^,;\s]+/", $newdata["submitter"], $match))
        {
            $newdata["submitter_image"] = $match[0];
            $newdata["submitter"] = trim(preg_replace($rx, "", $newdata["submitter"]), ", ");
        }
        // empty any previous _image data
        elseif (!empty($this["submitter"]) and strnatcasecmp($this["submitter"], $newdata["submitter"])) {
            $newdata["submitter_image"] = "";
        }
    }


    /**
     * Retrieve latest published release version.
     *
     * @return array
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
     * @return int
     */
    static function exists($name, $version) {
        $r = db("
            SELECT t_published
              FROM release
             WHERE name=? AND version=?",
            $name, rtrim(input::words($version))  // normalize version number
        );
        $t = $r ? $r->fetchColumn(0) : 0;
#        print "<b>exists=$t</b>\n";
        return intval($t);
    }









|







206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
     * @return int
     */
    static function exists($name, $version) {
        $r = db("
            SELECT t_published
              FROM release
             WHERE name=? AND version=?",
            proj_name($name), trim(input::words($version))  // normalize version number
        );
        $t = $r ? $r->fetchColumn(0) : 0;
#        print "<b>exists=$t</b>\n";
        return intval($t);
    }