. * */ namespace Friendica\Model\Post; use \BadMethodCallException; use Friendica\Core\Protocol; use Friendica\Database\Database; use Friendica\Database\DBA; use Friendica\Database\DBStructure; use Friendica\Model\Post; class Thread { /** * Insert a new post-thread entry * * @param integer $uri_id * @param array $fields * @return bool success * @throws \Exception */ public static function insert(int $uri_id, array $data = []) { if (empty($uri_id)) { throw new BadMethodCallException('Empty URI_id'); } $fields = DBStructure::getFieldsForTable('post-thread', $data); // Additionally assign the key fields $fields['uri-id'] = $uri_id; return DBA::insert('post-thread', $fields, Database::INSERT_IGNORE); } /** * Update a post-thread entry * * @param integer $uri_id * @param array $data * @param bool $insert_if_missing * @return bool * @throws \Exception */ public static function update(int $uri_id, array $data = [], bool $insert_if_missing = false) { if (empty($uri_id)) { throw new BadMethodCallException('Empty URI_id'); } $fields = DBStructure::getFieldsForTable('post-thread', $data); // Remove the key fields unset($fields['uri-id']); if (empty($fields)) { return true; } return DBA::update('post-thread', $fields, ['uri-id' => $uri_id], $insert_if_missing ? true : []); } /** * Delete a row from the post-thread 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-thread', $conditions, $options); } }