]> git.mxchange.org Git - friendica.git/commitdiff
We now are having an item class and a method to change item entries
authorMichael <heluecht@pirati.ca>
Tue, 9 Jan 2018 21:13:45 +0000 (21:13 +0000)
committerMichael <heluecht@pirati.ca>
Tue, 9 Jan 2018 21:13:45 +0000 (21:13 +0000)
mod/item.php
src/Model/Item.php [new file with mode: 0644]

index 8426c2d2ba87190be6ab1d00288d79967afc9f2f..5d9ca819962cb18b40f602c47555544e39e8b508 100644 (file)
@@ -21,6 +21,7 @@ use Friendica\Core\Worker;
 use Friendica\Database\DBM;
 use Friendica\Model\Contact;
 use Friendica\Model\GContact;
+use Friendica\Model\Item;
 use Friendica\Network\Probe;
 use Friendica\Protocol\Diaspora;
 use Friendica\Protocol\Email;
@@ -820,16 +821,11 @@ function item_post(App $a) {
                        'edited' => datetime_convert(),
                        'changed' => datetime_convert());
 
-               dba::update('item', $fields, ['id' => $post_id]);
-
-               create_tags_from_item($post_id);
-               create_files_from_item($post_id);
-               update_thread($post_id);
+               Item::update($fields, ['id' => $post_id]);
 
                // update filetags in pconfig
                file_tag_update_pconfig($uid,$categories_old,$categories_new,'category');
 
-               Worker::add(PRIORITY_HIGH, "Notifier", 'edit_post', $post_id);
                if (x($_REQUEST, 'return') && strlen($return_path)) {
                        logger('return: ' . $return_path);
                        goaway($return_path);
diff --git a/src/Model/Item.php b/src/Model/Item.php
new file mode 100644 (file)
index 0000000..c65e8f1
--- /dev/null
@@ -0,0 +1,56 @@
+<?php
+
+/**
+ * @file src/Model/Item.php
+ */
+
+namespace Friendica\Model;
+
+use Friendica\Core\Worker;
+use dba;
+
+require_once 'include/tags.php';
+require_once 'include/files.php';
+require_once 'include/threads.php';
+
+class Item
+{
+       /**
+        * @brief Update existing item entries
+        *
+        * @param array $fields The fields that are to be changed
+        * @param array $condition The condition for finding the item entries
+        *
+        * @return boolean success
+        */
+       public static function update(array $fields, array $condition)
+       {
+               if (empty($condition) || empty($fields)) {
+                       return false;
+               }
+
+               $success = dba::update('item', $fields, $condition);
+
+               if (!$success) {
+                       return false;
+               }
+
+               // We cannot simply expand the condition to check for origin entries
+               // The condition needn't to be a simple array but could be a complex condition.
+               $items = dba::select('item', ['id', 'origin'], $condition);
+               while ($item = dba::fetch($items)) {
+                       // We only need to notfiy others when it is an original entry from us
+                       if (!$item['origin']) {
+                               continue;
+                       }
+
+                       create_tags_from_item($item['id']);
+                       create_files_from_item($item['id']);
+                       update_thread($item['id']);
+
+                       Worker::add(PRIORITY_HIGH, "Notifier", 'edit_post', $item['id']);
+               }
+
+               return true;
+       }
+}