diff options
author | redmatrix <redmatrix@redmatrix.me> | 2015-07-16 20:19:20 -0700 |
---|---|---|
committer | redmatrix <redmatrix@redmatrix.me> | 2015-07-16 20:19:20 -0700 |
commit | ec249d465b60407b2e7c64e7a99be8ccf4b95e64 (patch) | |
tree | 31e96e0a7dc6b1f95c3207638bb5f3491824a780 | |
parent | 964e461e092b15a66da891a0a4c155323e8391e1 (diff) | |
download | volse-hubzilla-ec249d465b60407b2e7c64e7a99be8ccf4b95e64.tar.gz volse-hubzilla-ec249d465b60407b2e7c64e7a99be8ccf4b95e64.tar.bz2 volse-hubzilla-ec249d465b60407b2e7c64e7a99be8ccf4b95e64.zip |
provide a way to export a single year of items (to potentially keep from exhausting resources either on export or import)
-rw-r--r-- | include/identity.php | 31 | ||||
-rw-r--r-- | mod/uexport.php | 10 | ||||
-rw-r--r-- | version.inc | 2 |
3 files changed, 40 insertions, 3 deletions
diff --git a/include/identity.php b/include/identity.php index 29d9ef022..3925c3537 100644 --- a/include/identity.php +++ b/include/identity.php @@ -583,7 +583,7 @@ function identity_basic_export($channel_id, $items = false) { /** @warning this may run into memory limits on smaller systems */ - $r = q("select * from item where (item_flags & %d)>0 and not (item_restrict & %d)>0 and uid = %d", + $r = q("select * from item where (item_flags & %d)>0 and not (item_restrict & %d)>0 and uid = %d order by created", intval(ITEM_WALL), intval(ITEM_DELETED), intval($channel_id) @@ -600,6 +600,35 @@ function identity_basic_export($channel_id, $items = false) { } + +function identity_export_year($channel_id,$year) { + + if(! $year) + return array(); + + $ret = array(); + $mindate = datetime_convert('UTC','UTC',$year . '-01-01 00:00:00'); + $maxdate = datetime_convert('UTC','UTC',$year+1 . '-01-01 00:00:00'); + $r = q("select * from item where (item_flags & %d) > 0 and (item_restrict & %d) = 0 and uid = %d and created >= '%s' and created < '%s' order by created ", + intval(ITEM_WALL), + intval(ITEM_DELETED), + intval($channel_id), + dbesc($mindate), + dbesc($maxdate) + ); + + if($r) { + $ret['item'] = array(); + xchan_query($r); + $r = fetch_post_tags($r,true); + foreach($r as $rr) + $ret['item'][] = encode_item($rr,true); + } + + return $ret; +} + + /** * @brief Loads a profile into the App structure. * diff --git a/mod/uexport.php b/mod/uexport.php index edcb2fa84..b0bb11afa 100644 --- a/mod/uexport.php +++ b/mod/uexport.php @@ -9,9 +9,17 @@ function uexport_init(&$a) { require_once('include/identity.php'); + if(argc() > 1 && intval(argv(1)) > 1900) { + $year = intval(argv(1)); + } + header('content-type: application/octet_stream'); - header('content-disposition: attachment; filename="' . $channel['channel_address'] . '.json"' ); + header('content-disposition: attachment; filename="' . $channel['channel_address'] . (($year) ? '-' . $year : '') . '.json"' ); + if($year) { + echo json_encode(identity_export_year(local_channel(),$year)); + killme(); + } if(argc() > 1 && argv(1) === 'basic') { echo json_encode(identity_basic_export(local_channel())); diff --git a/version.inc b/version.inc index a8c5cc468..b66e936cd 100644 --- a/version.inc +++ b/version.inc @@ -1 +1 @@ -2015-07-15.1094 +2015-07-16.1095 |