]> git.mxchange.org Git - friendica.git/blobdiff - src/Model/Item.php
Added warning
[friendica.git] / src / Model / Item.php
index 1382e5217ea7a32b6c431bd76470f60abb0b2d4a..7c4a3cbffe1f43a74579c1de94a9c8731e1673b6 100644 (file)
@@ -78,6 +78,8 @@ class Item extends BaseObject
                        'author-id', 'author-link', 'author-name', 'author-avatar',
                        'owner-id', 'owner-link', 'owner-name', 'owner-avatar'];
 
+       // Never reorder or remove entries from this list. Just add new ones at the end, if needed.
+       // The item-activity table only stores the index and needs this array to know the matching activity.
        const ACTIVITIES = [ACTIVITY_LIKE, ACTIVITY_DISLIKE, ACTIVITY_ATTEND, ACTIVITY_ATTENDNO, ACTIVITY_ATTENDMAYBE];
 
        /**
@@ -86,7 +88,7 @@ class Item extends BaseObject
         * @param string $activity activity string
         * @return integer Activity index
         */
-       public static function activityToIndex($activity)
+       private static function activityToIndex($activity)
        {
                $index = array_search($activity, self::ACTIVITIES);
 
@@ -103,7 +105,7 @@ class Item extends BaseObject
         * @param integer $index activity index
         * @return string Activity string
         */
-       public static function indexToActivity($index)
+       private static function indexToActivity($index)
        {
                if (!isset(self::ACTIVITIES[$index])) {
                        return '';
@@ -748,9 +750,24 @@ class Item extends BaseObject
 
                while ($item = dba::fetch($items)) {
                        if (!empty($item['plink'])) {
-                               $content_fields['plink'] =  $item['plink'];
+                               $content_fields['plink'] = $item['plink'];
                        }
-                       if (!self::updateActivity($content_fields, ['uri' => $item['uri']])) {
+                       if (self::updateActivity($content_fields, ['uri' => $item['uri']])) {
+                               if (empty($item['iaid'])) {
+                                       $item_activity = dba::selectFirst('item-activity', ['id'], ['uri' => $item['uri']]);
+                                       if (DBM::is_result($item_activity)) {
+                                               $item_fields = ['iaid' => $item_activity['id'], 'icid' => null];
+                                               foreach (self::MIXED_CONTENT_FIELDLIST as $field) {
+                                                       $item_fields[$field] = '';
+                                               }
+                                               dba::update('item', $item_fields, ['id' => $item['id']]);
+
+                                               if (!empty($item['icid']) && !dba::exists('item', ['icid' => $item['icid']])) {
+                                                       dba::delete('item-content', ['id' => $item['icid']]);
+                                               }
+                                       }
+                               }
+                       } else {
                                self::updateContent($content_fields, ['uri' => $item['uri']]);
 
                                if (empty($item['icid'])) {
@@ -766,10 +783,6 @@ class Item extends BaseObject
                                                dba::update('item', $item_fields, ['id' => $item['id']]);
                                        }
                                }
-                       } else {
-                               if (empty($item['iaid'])) {
-                                       // To-Do
-                               }
                        }
 
                        if (!empty($tags)) {
@@ -1786,14 +1799,14 @@ class Item extends BaseObject
                if (empty($item['verb'])) {
                        return false;
                }
-
                $activity_index = self::activityToIndex($item['verb']);
 
-               if (!$activity_index) {
+               if ($activity_index < 0) {
                        return false;
                }
 
-               $fields = ['activity' => $activity_index];
+               $fields = ['activity' => $activity_index,
+                       'uri-hash' => hash('sha1', $condition['uri']) . hash('ripemd160', $condition['uri'])];
 
                logger('Update activity for URI ' . $condition['uri']);