<?php
/**
- * @copyright Copyright (C) 2020, Friendica
+ * @copyright Copyright (C) 2010-2022, the Friendica project
*
* @license GNU AGPL version 3 or any later version
*
use \BadMethodCallException;
use Friendica\Database\Database;
use Friendica\Database\DBStructure;
+use Friendica\DI;
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 = [])
return false;
}
- $fields = DBStructure::getFieldsForTable('post-user', $data);
+ $fields = DI::dbaDefinition()->truncateFieldsForTable('post-user', $data);
// Additionally assign the key fields
$fields['uri-id'] = $uri_id;
$fields['unseen'] = false;
}
- return DBA::insert('post-user', $fields, Database::INSERT_IGNORE);
+ 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
throw new BadMethodCallException('Empty URI_id');
}
- $fields = DBStructure::getFieldsForTable('post-user', $data);
+ $fields = DI::dbaDefinition()->truncateFieldsForTable('post-user', $data);
// Remove the key fields
unset($fields['uri-id']);
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);
+ }
}