[aur-dev] [PATCH 1/2] RPC: Provide out-of-date timestamp
Convert the "OutOfDate" field to provide a timestamp instead of a boolean flag in JSON results. We don't really care about backward compatibility here, as most AUR helpers would break anyway when trying to parse RPC responses after the data type overhaul that should come with one of the following patches. Signed-off-by: Lukas Fleischer <archlinux@cryptocrack.de> --- web/lib/aurjson.class.php | 5 ++--- 1 files changed, 2 insertions(+), 3 deletions(-) diff --git a/web/lib/aurjson.class.php b/web/lib/aurjson.class.php index b596359..b4648c9 100644 --- a/web/lib/aurjson.class.php +++ b/web/lib/aurjson.class.php @@ -18,9 +18,8 @@ class AurJSON { 'search', 'info', 'multiinfo', 'msearch' ); private static $fields = array( - 'Packages.ID', 'Name', 'Version', 'CategoryID', - 'Description', 'URL', 'License', - 'NumVotes', '(OutOfDateTS IS NOT NULL) AS OutOfDate', + 'Packages.ID', 'Name', 'Version', 'CategoryID', 'Description', 'URL', + 'License', 'NumVotes', 'OutOfDateTS AS OutOfDate', 'SubmittedTS AS FirstSubmitted', 'ModifiedTS AS LastModified' ); -- 1.7.6.3
Coerce following fields into integers to ensure json_encode() serializes them as integers: * ID * CategoryID * NumVotes * OutOfDate * FirstSubmitted * LastModified This means that there will be a minor API break. There's no better way to do this properly, though. Fixes FS#25693. Signed-off-by: Lukas Fleischer <archlinux@cryptocrack.de> --- web/lib/aurjson.class.php | 12 ++++++++++++ 1 files changed, 12 insertions(+), 0 deletions(-) diff --git a/web/lib/aurjson.class.php b/web/lib/aurjson.class.php index b4648c9..3a8e830 100644 --- a/web/lib/aurjson.class.php +++ b/web/lib/aurjson.class.php @@ -22,6 +22,10 @@ class AurJSON { 'License', 'NumVotes', 'OutOfDateTS AS OutOfDate', 'SubmittedTS AS FirstSubmitted', 'ModifiedTS AS LastModified' ); + private static $numeric_fields = array( + 'ID', 'CategoryID', 'NumVotes', 'OutOfDate', 'FirstSubmitted', + 'LastModified' + ); /** * Handles post data, and routes the request. @@ -126,6 +130,14 @@ class AurJSON { $name = $row['Name']; $row['URLPath'] = URL_DIR . substr($name, 0, 2) . "/" . $name . "/" . $name . ".tar.gz"; + /* Unfortunately, mysql_fetch_assoc() returns all fields as + * strings. We need to coerce numeric values into integers to + * provide proper data types in the JSON response. + */ + foreach (self::$numeric_fields as $field) { + $row[$field] = intval($row[$field]); + } + if ($type == 'info') { $search_data = $row; break; -- 1.7.6.3
participants (1)
-
Lukas Fleischer