aboutsummaryrefslogtreecommitdiffstats
path: root/include/import.php
diff options
context:
space:
mode:
authorredmatrix <git@macgirvin.com>2016-05-04 17:35:27 -0700
committerredmatrix <git@macgirvin.com>2016-05-04 17:35:27 -0700
commit50fb525b280069e4a95f9ae133b15460e8b02318 (patch)
tree681af74d8de7b6b73c6965738e366657fdc2e5cd /include/import.php
parent7c57da3a28ceda8eb5622ffedd0a20bba742e96a (diff)
downloadvolse-hubzilla-50fb525b280069e4a95f9ae133b15460e8b02318.tar.gz
volse-hubzilla-50fb525b280069e4a95f9ae133b15460e8b02318.tar.bz2
volse-hubzilla-50fb525b280069e4a95f9ae133b15460e8b02318.zip
add categories to apps (wip)
Diffstat (limited to 'include/import.php')
-rw-r--r--include/import.php73
1 files changed, 64 insertions, 9 deletions
diff --git a/include/import.php b/include/import.php
index f6e62f9e0..321f275b1 100644
--- a/include/import.php
+++ b/include/import.php
@@ -297,8 +297,11 @@ function import_apps($channel,$apps) {
if($channel && $apps) {
foreach($apps as $app) {
+ $term = ((array_key_exists('term',$app) && is_array($app['term'])) ? $app['term'] : null);
+
unset($app['id']);
unset($app['app_channel']);
+ unset($app['term']);
$app['app_channel'] = $channel['channel_id'];
@@ -307,6 +310,8 @@ function import_apps($channel,$apps) {
$app['app_photo'] = $x[0];
}
+ $hash = $app['app_id'];
+
dbesc_array($app);
$r = dbq("INSERT INTO app (`"
. implode("`, `", array_keys($app))
@@ -314,6 +319,21 @@ function import_apps($channel,$apps) {
. implode("', '", array_values($app))
. "')"
);
+
+ if($term) {
+ $x = q("select * from app where app_id = '%s' and app_channel = %d limit 1",
+ dbesc($hash),
+ intval($channel['channel_id'])
+ );
+ if($x) {
+ foreach($term as $t) {
+ store_item_tag($channel['channel_id'],$x[0]['id'],TERM_OBJ_APP,$t['type'],escape_tags($t['term']),escape_tags($t['url']));
+ }
+ }
+ }
+
+
+
}
}
}
@@ -325,16 +345,41 @@ function sync_apps($channel,$apps) {
if($channel && $apps) {
foreach($apps as $app) {
- if(array_key_exists('app_deleted',$app) && $app['app_deleted'] && $app['app_id']) {
+ $exists = false;
+ $term = ((array_key_exists('term',$app)) ? $app['term'] : null);
+
+ $x = q("select * from app where app_id = '%s' and app_channel = %d limit 1",
+ dbesc($app['app_id']),
+ intval($channel['channel_id'])
+ );
+ if($x) {
+ $exists = $x[0];
+ }
+
+ if(array_key_exists('app_deleted',$app) && $app['app_deleted'] && $app['app_id']) {
q("delete from app where app_id = '%s' and app_channel = %d limit 1",
dbesc($app['app_id']),
intval($channel['channel_id'])
);
+ if($exists) {
+ q("delete from term where otype = %d and oid = %d",
+ intval(TERM_OBJ_APP),
+ intval($exists['id'])
+ );
+ }
continue;
}
unset($app['id']);
unset($app['app_channel']);
+ unset($app['term']);
+
+ if($exists) {
+ q("delete from term where otype = %d and oid = %d",
+ intval(TERM_OBJ_APP),
+ intval($exists['id'])
+ );
+ }
if(! $app['app_created'] || $app['app_created'] === NULL_DATE)
$app['app_created'] = datetime_convert();
@@ -348,16 +393,15 @@ function sync_apps($channel,$apps) {
$app['app_photo'] = $x[0];
}
- $exists = false;
+ if($exists && $term) {
+ foreach($term as $t) {
+ store_item_tag($channel['channel_id'],$exists['id'],TERM_OBJ_APP,$t['type'],escape_tags($t['term']),escape_tags($t['url']));
+ }
+ }
- $x = q("select * from app where app_id = '%s' and app_channel = %d limit 1",
- dbesc($app['app_id']),
- intval($channel['channel_id'])
- );
- if($x) {
- if($x[0]['app_edited'] >= $app['app_edited'])
+ if($exists) {
+ if($exists['app_edited'] >= $app['app_edited'])
continue;
- $exists = true;
}
$hash = $app['app_id'];
@@ -380,6 +424,17 @@ function sync_apps($channel,$apps) {
. implode("', '", array_values($app))
. "')"
);
+ if($term) {
+ $x = q("select * from app where app_id = '%s' and app_channel = %d limit 1",
+ dbesc($hash),
+ intval($channel['channel_id'])
+ );
+ if($x) {
+ foreach($term as $t) {
+ store_item_tag($channel['channel_id'],$x[0]['id'],TERM_OBJ_APP,$t['type'],escape_tags($t['term']),escape_tags($t['url']));
+ }
+ }
+ }
}
}
}