mirror of
https://github.com/friendica/friendica
synced 2025-04-28 15:04:26 +02:00
Extract Item::prepareOriginPost() into ItemInserter
This commit is contained in:
parent
9b9432090b
commit
61a975bf36
2 changed files with 36 additions and 9 deletions
|
@ -843,14 +843,6 @@ class Item
|
||||||
return self::GRAVITY_UNKNOWN; // Should not happen
|
return self::GRAVITY_UNKNOWN; // Should not happen
|
||||||
}
|
}
|
||||||
|
|
||||||
private static function prepareOriginPost(array $item): array
|
|
||||||
{
|
|
||||||
$item = DI::contentItem()->initializePost($item);
|
|
||||||
$item = DI::contentItem()->finalizePost($item, false);
|
|
||||||
|
|
||||||
return $item;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Inserts item record
|
* Inserts item record
|
||||||
*
|
*
|
||||||
|
@ -861,6 +853,8 @@ class Item
|
||||||
*/
|
*/
|
||||||
public static function insert(array $item, int $notify = 0, bool $post_local = true): int
|
public static function insert(array $item, int $notify = 0, bool $post_local = true): int
|
||||||
{
|
{
|
||||||
|
$itemInserter = new ItemInserter(DI::contentItem());
|
||||||
|
|
||||||
$orig_item = $item;
|
$orig_item = $item;
|
||||||
|
|
||||||
$priority = Worker::PRIORITY_HIGH;
|
$priority = Worker::PRIORITY_HIGH;
|
||||||
|
@ -869,7 +863,7 @@ class Item
|
||||||
|
|
||||||
// If it is a posting where users should get notifications, then define it as wall posting
|
// If it is a posting where users should get notifications, then define it as wall posting
|
||||||
if ($notify) {
|
if ($notify) {
|
||||||
$item = self::prepareOriginPost($item);
|
$item = $itemInserter->prepareOriginPost($item);
|
||||||
|
|
||||||
if (is_int($notify) && in_array($notify, Worker::PRIORITIES)) {
|
if (is_int($notify) && in_array($notify, Worker::PRIORITIES)) {
|
||||||
$priority = $notify;
|
$priority = $notify;
|
||||||
|
|
33
src/Model/ItemInserter.php
Normal file
33
src/Model/ItemInserter.php
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
// Copyright (C) 2010-2024, the Friendica project
|
||||||
|
// SPDX-FileCopyrightText: 2010-2024 the Friendica project
|
||||||
|
//
|
||||||
|
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||||
|
|
||||||
|
namespace Friendica\Model;
|
||||||
|
|
||||||
|
use Friendica\Content\Item as ItemContent;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A helper class for inserting an Item Model
|
||||||
|
*
|
||||||
|
* @see Item::insert()
|
||||||
|
*/
|
||||||
|
final class ItemInserter
|
||||||
|
{
|
||||||
|
private ItemContent $itemContent;
|
||||||
|
|
||||||
|
public function __construct(ItemContent $itemContent)
|
||||||
|
{
|
||||||
|
$this->itemContent = $itemContent;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function prepareOriginPost(array $item): array
|
||||||
|
{
|
||||||
|
$item = $this->itemContent->initializePost($item);
|
||||||
|
$item = $this->itemContent->finalizePost($item, false);
|
||||||
|
|
||||||
|
return $item;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue