2018-01-09 22:13:45 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @file src/Model/Item.php
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Friendica\Model;
|
|
|
|
|
|
|
|
use Friendica\Core\Worker;
|
2018-01-10 18:05:20 +01:00
|
|
|
use Friendica\Model\Term;
|
2018-01-09 22:13:45 +01:00
|
|
|
use dba;
|
|
|
|
|
|
|
|
require_once 'include/tags.php';
|
|
|
|
require_once 'include/threads.php';
|
|
|
|
|
|
|
|
class Item
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @brief Update existing item entries
|
|
|
|
*
|
|
|
|
* @param array $fields The fields that are to be changed
|
|
|
|
* @param array $condition The condition for finding the item entries
|
|
|
|
*
|
2018-01-09 23:16:16 +01:00
|
|
|
* In the future we may have to change permissions as well.
|
|
|
|
* Then we had to add the user id as third parameter.
|
|
|
|
*
|
|
|
|
* A return value of "0" doesn't mean an error - but that 0 rows had been changed.
|
|
|
|
*
|
|
|
|
* @return integer|boolean number of affected rows - or "false" if there was an error
|
2018-01-09 22:13:45 +01:00
|
|
|
*/
|
|
|
|
public static function update(array $fields, array $condition)
|
|
|
|
{
|
|
|
|
if (empty($condition) || empty($fields)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
$success = dba::update('item', $fields, $condition);
|
|
|
|
|
|
|
|
if (!$success) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-01-09 23:16:16 +01:00
|
|
|
$rows = dba::affected_rows();
|
|
|
|
|
2018-01-09 22:13:45 +01:00
|
|
|
// We cannot simply expand the condition to check for origin entries
|
|
|
|
// The condition needn't to be a simple array but could be a complex condition.
|
|
|
|
$items = dba::select('item', ['id', 'origin'], $condition);
|
|
|
|
while ($item = dba::fetch($items)) {
|
|
|
|
// We only need to notfiy others when it is an original entry from us
|
|
|
|
if (!$item['origin']) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
create_tags_from_item($item['id']);
|
2018-01-10 18:05:20 +01:00
|
|
|
Term::createFromItem($item['id']);
|
2018-01-09 22:13:45 +01:00
|
|
|
update_thread($item['id']);
|
|
|
|
|
|
|
|
Worker::add(PRIORITY_HIGH, "Notifier", 'edit_post', $item['id']);
|
|
|
|
}
|
|
|
|
|
2018-01-09 23:16:16 +01:00
|
|
|
return $rows;
|
2018-01-09 22:13:45 +01:00
|
|
|
}
|
|
|
|
}
|