mirror of
https://github.com/friendica/friendica
synced 2025-04-26 05:10:11 +00:00
New class for handling delayed posts
This commit is contained in:
parent
aa4372447a
commit
2aa302c570
4 changed files with 149 additions and 25 deletions
112
src/Model/Post/Delayed.php
Normal file
112
src/Model/Post/Delayed.php
Normal file
|
@ -0,0 +1,112 @@
|
|||
<?php
|
||||
/**
|
||||
* @copyright Copyright (C) 2020, Friendica
|
||||
*
|
||||
* @license GNU AGPL version 3 or any later version
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace Friendica\Model\Post;
|
||||
|
||||
use Friendica\Core\Logger;
|
||||
use Friendica\Database\DBA;
|
||||
use Friendica\Core\Worker;
|
||||
use Friendica\Database\Database;
|
||||
use Friendica\Model\Item;
|
||||
use Friendica\Model\Tag;
|
||||
|
||||
class Delayed
|
||||
{
|
||||
/**
|
||||
* Insert a new delayed post
|
||||
*
|
||||
* @param string $uri
|
||||
* @param integer $uid
|
||||
* @param string $delayed
|
||||
* @param array $item
|
||||
* @param integer $notify
|
||||
* @param array $taglist
|
||||
* @param array $attachments
|
||||
* @return bool insert success
|
||||
*/
|
||||
public static function add(string $uri, int $uid, string $delayed, array $item, int $notify = 0, array $taglist = [], array $attachments = [])
|
||||
{
|
||||
if (self::exists($uri)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Logger::notice('Adding post for delayed publishing', ['uid' => $uid, 'delayed' => $delayed, 'uri' => $uri]);
|
||||
|
||||
Worker::add(['priority' => PRIORITY_HIGH, 'delayed' => $delayed], 'DelayedPublish', $item, $notify, $taglist, $attachments);
|
||||
return DBA::insert('delayed-post', ['uri' => $uri, 'uid' => $uid, 'delayed' => $delayed], Database::INSERT_IGNORE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a delayed post
|
||||
*
|
||||
* @param string $uri
|
||||
*
|
||||
* @return bool delete success
|
||||
*/
|
||||
private static function delete(string $uri)
|
||||
{
|
||||
return DBA::delete('delayed-post', ['uri' => $uri]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @param string $uri
|
||||
*
|
||||
* @return bool "true" if an entry with that URI exists
|
||||
*/
|
||||
public static function exists(string $uri)
|
||||
{
|
||||
return DBA::exists('delayed-post', ['uri' => $uri]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Publish a delayed post
|
||||
*
|
||||
* @param array $item
|
||||
* @param integer $notify
|
||||
* @param array $taglist
|
||||
* @param array $attachments
|
||||
* @return bool
|
||||
*/
|
||||
public static function publish(array $item, int $notify = 0, array $taglist = [], array $attachments = [])
|
||||
{
|
||||
$id = Item::insert($item, $notify);
|
||||
|
||||
Logger::notice('Post stored', ['id' => $id, 'uid' => $item['uid'], 'cid' => $item['contact-id']]);
|
||||
|
||||
if (!empty($id) && (!empty($taglist) || !empty($attachments))) {
|
||||
$feeditem = Item::selectFirst(['uri-id', 'uri'], ['id' => $id]);
|
||||
self::delete($feeditem['uri']);
|
||||
|
||||
foreach ($taglist as $tag) {
|
||||
Tag::store($feeditem['uri-id'], Tag::HASHTAG, $tag);
|
||||
}
|
||||
|
||||
foreach ($attachments as $attachment) {
|
||||
$attachment['uri-id'] = $feeditem['uri-id'];
|
||||
Media::insert($attachment);
|
||||
}
|
||||
}
|
||||
|
||||
return $id;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue