]> git.mxchange.org Git - friendica.git/blobdiff - src/Model/Post/User.php
Use rawContent for Special Options to avoid a protected options() method
[friendica.git] / src / Model / Post / User.php
index 69225f042347a711cd6b9be4542354d09c2a4b90..0da3062a0ba33d07e437728636f0b96acd8d7119 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /**
- * @copyright Copyright (C) 2020, Friendica
+ * @copyright Copyright (C) 2010-2022, the Friendica project
  *
  * @license GNU AGPL version 3 or any later version
  *
@@ -23,18 +23,18 @@ namespace Friendica\Model\Post;
 
 use Friendica\Database\DBA;
 use \BadMethodCallException;
-use Friendica\Core\Logger;
+use Friendica\Database\Database;
 use Friendica\Database\DBStructure;
 
 class User
 {
        /**
-        * Insert a new URI user entry
+        * Insert a new post user entry
         *
         * @param integer $uri_id
         * @param integer $uid
         * @param array   $fields
-        * @return bool
+        * @return int    ID of inserted post-user
         * @throws \Exception
         */
        public static function insert(int $uri_id, int $uid, array $data = [])
@@ -58,19 +58,24 @@ class User
                        $fields['unseen'] = false;
                }
 
-               return DBA::insert('post-user', $fields);
+               if (!DBA::insert('post-user', $fields, Database::INSERT_IGNORE)) {
+                       return 0;
+               }
+
+               return DBA::lastInsertId();
        }
 
        /**
-        * Update a URI user entry
+        * Update a post user entry
         *
         * @param integer $uri_id
         * @param integer $uid
-        * @param array   $fields
+        * @param array   $data
+        * @param bool    $insert_if_missing
         * @return bool
         * @throws \Exception
         */
-       public static function update(int $uri_id, int $uid, array $data = [])
+       public static function update(int $uri_id, int $uid, array $data = [], bool $insert_if_missing = false)
        {
                if (empty($uri_id)) {
                        throw new BadMethodCallException('Empty URI_id');
@@ -86,7 +91,22 @@ class User
                        return true;
                }
 
-Logger::info('Blubb-Update', ['uri-id' => $uri_id, 'uid' => $uid, 'fields' => $fields]);
-               return DBA::update('post-user', $fields, ['uri-id' => $uri_id, 'uid' => $uid], true);
+               return DBA::update('post-user', $fields, ['uri-id' => $uri_id, 'uid' => $uid], $insert_if_missing ? true : []);
+       }
+
+       /**
+        * Delete a row from the post-user table
+        *
+        * @param array        $conditions Field condition(s)
+        * @param array        $options
+        *                           - cascade: If true we delete records in other tables that depend on the one we're deleting through
+        *                           relations (default: true)
+        *
+        * @return boolean was the delete successful?
+        * @throws \Exception
+        */
+       public static function delete(array $conditions, array $options = [])
+       {
+               return DBA::delete('post-user', $conditions, $options);
        }
 }