2013-08-28 19:36:48 +04:00
|
|
|
<?php
|
|
|
|
/**
|
2016-07-22 13:37:41 +03:00
|
|
|
* @copyright Copyright (c) 2016, ownCloud, Inc.
|
|
|
|
*
|
|
|
|
* @author Frank Karlitschek <frank@karlitschek.de>
|
|
|
|
* @author Joas Schilling <coding@schilljs.com>
|
2016-02-12 11:14:27 +03:00
|
|
|
* @author Thomas Müller <thomas.mueller@tmit.eu>
|
2013-08-28 19:36:48 +04:00
|
|
|
*
|
2016-02-12 11:14:27 +03:00
|
|
|
* @license AGPL-3.0
|
2013-08-28 19:36:48 +04:00
|
|
|
*
|
2016-02-12 11:14:27 +03:00
|
|
|
* This code is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License, version 3,
|
|
|
|
* as published by the Free Software Foundation.
|
2013-08-28 19:36:48 +04:00
|
|
|
*
|
2016-02-12 11:14:27 +03:00
|
|
|
* This program is distributed in the hope that it will be useful,
|
2013-08-28 19:36:48 +04:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2016-02-12 11:14:27 +03:00
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
2013-08-28 19:36:48 +04:00
|
|
|
*
|
2016-02-12 11:14:27 +03:00
|
|
|
* You should have received a copy of the GNU Affero General Public License, version 3,
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
2013-08-28 19:36:48 +04:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace OCA\Activity;
|
|
|
|
|
2020-03-02 15:55:13 +03:00
|
|
|
use Doctrine\DBAL\Platforms\MySqlPlatform;
|
2020-07-21 18:58:46 +03:00
|
|
|
use OCA\Activity\Filter\AllFilter;
|
2015-08-20 14:03:59 +03:00
|
|
|
use OCP\Activity\IEvent;
|
2014-12-03 14:27:07 +03:00
|
|
|
use OCP\Activity\IExtension;
|
2016-10-20 19:02:18 +03:00
|
|
|
use OCP\Activity\IFilter;
|
2015-08-14 13:32:49 +03:00
|
|
|
use OCP\Activity\IManager;
|
2015-11-04 11:26:52 +03:00
|
|
|
use OCP\DB\QueryBuilder\IQueryBuilder;
|
2015-08-14 13:32:49 +03:00
|
|
|
use OCP\IDBConnection;
|
2015-09-15 12:32:09 +03:00
|
|
|
use OCP\IL10N;
|
2014-07-14 15:13:23 +04:00
|
|
|
|
2013-08-28 19:36:48 +04:00
|
|
|
/**
|
2013-09-17 16:27:41 +04:00
|
|
|
* @brief Class for managing the data in the activities
|
|
|
|
*/
|
2015-02-05 14:45:40 +03:00
|
|
|
class Data {
|
2015-08-14 13:32:49 +03:00
|
|
|
/** @var IManager */
|
2014-07-14 15:13:23 +04:00
|
|
|
protected $activityManager;
|
|
|
|
|
2015-08-14 13:32:49 +03:00
|
|
|
/** @var IDBConnection */
|
|
|
|
protected $connection;
|
|
|
|
|
2015-02-05 14:45:40 +03:00
|
|
|
/**
|
2015-08-14 13:32:49 +03:00
|
|
|
* @param IManager $activityManager
|
|
|
|
* @param IDBConnection $connection
|
2015-02-05 14:45:40 +03:00
|
|
|
*/
|
2016-08-31 19:20:02 +03:00
|
|
|
public function __construct(IManager $activityManager, IDBConnection $connection) {
|
2014-07-14 15:13:23 +04:00
|
|
|
$this->activityManager = $activityManager;
|
2015-08-14 13:32:49 +03:00
|
|
|
$this->connection = $connection;
|
2014-07-14 15:13:23 +04:00
|
|
|
}
|
|
|
|
|
2013-08-28 19:36:48 +04:00
|
|
|
/**
|
2014-06-04 19:31:54 +04:00
|
|
|
* Send an event into the activity stream
|
|
|
|
*
|
2015-08-20 14:03:59 +03:00
|
|
|
* @param IEvent $event
|
2020-06-17 15:40:20 +03:00
|
|
|
* @return int
|
2013-08-28 19:36:48 +04:00
|
|
|
*/
|
2020-06-17 15:40:20 +03:00
|
|
|
public function send(IEvent $event): int {
|
2015-08-20 14:03:59 +03:00
|
|
|
if ($event->getAffectedUser() === '' || $event->getAffectedUser() === null) {
|
2015-08-10 14:03:09 +03:00
|
|
|
return false;
|
2013-10-02 17:32:27 +04:00
|
|
|
}
|
2013-08-28 19:36:48 +04:00
|
|
|
|
|
|
|
// store in DB
|
2015-09-15 12:32:09 +03:00
|
|
|
$queryBuilder = $this->connection->getQueryBuilder();
|
2015-08-14 16:34:12 +03:00
|
|
|
$queryBuilder->insert('activity')
|
|
|
|
->values([
|
|
|
|
'app' => $queryBuilder->createParameter('app'),
|
|
|
|
'subject' => $queryBuilder->createParameter('subject'),
|
|
|
|
'subjectparams' => $queryBuilder->createParameter('subjectparams'),
|
|
|
|
'message' => $queryBuilder->createParameter('message'),
|
|
|
|
'messageparams' => $queryBuilder->createParameter('messageparams'),
|
2015-08-19 18:39:38 +03:00
|
|
|
'file' => $queryBuilder->createParameter('object_name'),
|
2015-08-14 16:34:12 +03:00
|
|
|
'link' => $queryBuilder->createParameter('link'),
|
|
|
|
'user' => $queryBuilder->createParameter('user'),
|
|
|
|
'affecteduser' => $queryBuilder->createParameter('affecteduser'),
|
|
|
|
'timestamp' => $queryBuilder->createParameter('timestamp'),
|
|
|
|
'priority' => $queryBuilder->createParameter('priority'),
|
|
|
|
'type' => $queryBuilder->createParameter('type'),
|
|
|
|
'object_type' => $queryBuilder->createParameter('object_type'),
|
|
|
|
'object_id' => $queryBuilder->createParameter('object_id'),
|
|
|
|
])
|
|
|
|
->setParameters([
|
2015-08-20 14:03:59 +03:00
|
|
|
'app' => $event->getApp(),
|
|
|
|
'type' => $event->getType(),
|
|
|
|
'affecteduser' => $event->getAffectedUser(),
|
|
|
|
'user' => $event->getAuthor(),
|
|
|
|
'timestamp' => (int) $event->getTimestamp(),
|
|
|
|
'subject' => $event->getSubject(),
|
|
|
|
'subjectparams' => json_encode($event->getSubjectParameters()),
|
|
|
|
'message' => $event->getMessage(),
|
|
|
|
'messageparams' => json_encode($event->getMessageParameters()),
|
2015-08-18 10:06:05 +03:00
|
|
|
'priority' => IExtension::PRIORITY_MEDIUM,
|
2015-08-20 14:03:59 +03:00
|
|
|
'object_type' => $event->getObjectType(),
|
|
|
|
'object_id' => (int) $event->getObjectId(),
|
|
|
|
'object_name' => $event->getObjectName(),
|
|
|
|
'link' => $event->getLink(),
|
2015-08-14 16:34:12 +03:00
|
|
|
])
|
|
|
|
->execute();
|
2013-10-01 12:53:46 +04:00
|
|
|
|
2020-06-17 15:40:20 +03:00
|
|
|
return $this->connection->lastInsertId('activity');
|
2013-08-28 19:36:48 +04:00
|
|
|
}
|
|
|
|
|
2014-04-16 18:51:47 +04:00
|
|
|
/**
|
2015-08-19 18:39:38 +03:00
|
|
|
* Send an event as email
|
2014-04-16 18:51:47 +04:00
|
|
|
*
|
2015-08-20 14:03:59 +03:00
|
|
|
* @param IEvent $event
|
2015-08-19 18:39:38 +03:00
|
|
|
* @param int $latestSendTime Activity $timestamp + batch setting of $affectedUser
|
2014-04-16 18:51:47 +04:00
|
|
|
* @return bool
|
|
|
|
*/
|
2018-10-11 13:11:30 +03:00
|
|
|
public function storeMail(IEvent $event, int $latestSendTime): bool {
|
|
|
|
$affectedUser = $event->getAffectedUser();
|
|
|
|
if ($affectedUser === '' || $affectedUser === null) {
|
2015-08-20 14:03:59 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-10-11 13:11:30 +03:00
|
|
|
$query = $this->connection->getQueryBuilder();
|
|
|
|
$query->insert('activity_mq')
|
2015-09-15 12:32:09 +03:00
|
|
|
->values([
|
2018-10-11 13:11:30 +03:00
|
|
|
'amq_appid' => $query->createNamedParameter($event->getApp()),
|
|
|
|
'amq_subject' => $query->createNamedParameter($event->getSubject()),
|
|
|
|
'amq_subjectparams' => $query->createNamedParameter(json_encode($event->getSubjectParameters())),
|
|
|
|
'amq_affecteduser' => $query->createNamedParameter($affectedUser),
|
|
|
|
'amq_timestamp' => $query->createNamedParameter((int) $event->getTimestamp()),
|
|
|
|
'amq_type' => $query->createNamedParameter($event->getType()),
|
|
|
|
'amq_latest_send' => $query->createNamedParameter($latestSendTime),
|
|
|
|
'object_type' => $query->createNamedParameter($event->getObjectType()),
|
|
|
|
'object_id' => $query->createNamedParameter($event->getObjectId()),
|
|
|
|
]);
|
|
|
|
$query->execute();
|
2014-04-16 18:51:47 +04:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-11-04 11:26:52 +03:00
|
|
|
/**
|
|
|
|
* Read a list of events from the activity stream
|
|
|
|
*
|
|
|
|
* @param GroupHelper $groupHelper Allows activities to be grouped
|
|
|
|
* @param UserSettings $userSettings Gets the settings of the user
|
|
|
|
* @param string $user User for whom we display the stream
|
|
|
|
*
|
|
|
|
* @param int $since The integer ID of the last activity that has been seen.
|
|
|
|
* @param int $limit How many activities should be returned
|
|
|
|
* @param string $sort Should activities be given ascending or descending
|
|
|
|
*
|
|
|
|
* @param string $filter Filter the activities
|
|
|
|
* @param string $objectType Allows to filter the activities to a given object. May only appear together with $objectId
|
|
|
|
* @param int $objectId Allows to filter the activities to a given object. May only appear together with $objectType
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*
|
|
|
|
* @throws \OutOfBoundsException if the user (Code: 1) or the since (Code: 2) is invalid
|
2015-12-14 15:56:58 +03:00
|
|
|
* @throws \BadMethodCallException if the user has selected to display no types for this filter (Code: 3)
|
2015-11-04 11:26:52 +03:00
|
|
|
*/
|
|
|
|
public function get(GroupHelper $groupHelper, UserSettings $userSettings, $user, $since, $limit, $sort, $filter, $objectType = '', $objectId = 0) {
|
|
|
|
// get current user
|
|
|
|
if ($user === '') {
|
|
|
|
throw new \OutOfBoundsException('Invalid user', 1);
|
|
|
|
}
|
|
|
|
|
2016-10-20 19:02:18 +03:00
|
|
|
$activeFilter = null;
|
|
|
|
try {
|
|
|
|
$activeFilter = $this->activityManager->getFilterById($filter);
|
|
|
|
} catch (\InvalidArgumentException $e) {
|
|
|
|
// Unknown filter => ignore and show all activities
|
|
|
|
}
|
|
|
|
|
2015-11-04 11:26:52 +03:00
|
|
|
$query = $this->connection->getQueryBuilder();
|
|
|
|
$query->select('*')
|
|
|
|
->from('activity');
|
|
|
|
|
2020-07-21 18:58:46 +03:00
|
|
|
$query->where($query->expr()->eq('affecteduser', $query->createNamedParameter($user)));
|
|
|
|
|
|
|
|
if ($activeFilter instanceof IFilter && !($activeFilter instanceof AllFilter)) {
|
|
|
|
$notificationTypes = $userSettings->getNotificationTypes();
|
|
|
|
$notificationTypes = $activeFilter->filterTypes($notificationTypes);
|
|
|
|
$notificationTypes = array_unique($notificationTypes);
|
|
|
|
|
|
|
|
$query->andWhere($query->expr()->in('type', $query->createNamedParameter($notificationTypes, IQueryBuilder::PARAM_STR_ARRAY)));
|
|
|
|
}
|
|
|
|
|
2015-11-04 11:26:52 +03:00
|
|
|
if ($filter === 'self') {
|
|
|
|
$query->andWhere($query->expr()->eq('user', $query->createNamedParameter($user)));
|
|
|
|
|
2016-04-11 15:52:32 +03:00
|
|
|
} else if ($filter === 'by') {
|
2015-11-04 11:26:52 +03:00
|
|
|
$query->andWhere($query->expr()->neq('user', $query->createNamedParameter($user)));
|
|
|
|
|
2016-04-11 15:52:32 +03:00
|
|
|
} else if ($filter === 'all' && !$userSettings->getUserSetting($user, 'setting', 'self')) {
|
|
|
|
$query->andWhere($query->expr()->orX(
|
|
|
|
$query->expr()->neq('user', $query->createNamedParameter($user)),
|
|
|
|
$query->expr()->notIn('type', $query->createNamedParameter([
|
|
|
|
'file_created',
|
|
|
|
'file_changed',
|
|
|
|
'file_deleted',
|
|
|
|
'file_restored',
|
|
|
|
], IQueryBuilder::PARAM_STR_ARRAY))
|
|
|
|
));
|
|
|
|
|
2015-11-04 11:26:52 +03:00
|
|
|
} else if ($filter === 'filter') {
|
|
|
|
if (!$userSettings->getUserSetting($user, 'setting', 'self')) {
|
2016-04-11 15:52:32 +03:00
|
|
|
$query->andWhere($query->expr()->orX(
|
|
|
|
$query->expr()->neq('user', $query->createNamedParameter($user)),
|
|
|
|
$query->expr()->notIn('type', $query->createNamedParameter([
|
|
|
|
'file_created',
|
|
|
|
'file_changed',
|
|
|
|
'file_deleted',
|
|
|
|
'file_restored',
|
|
|
|
], IQueryBuilder::PARAM_STR_ARRAY))
|
|
|
|
));
|
2015-11-04 11:26:52 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
$query->andWhere($query->expr()->eq('object_type', $query->createNamedParameter($objectType)));
|
|
|
|
$query->andWhere($query->expr()->eq('object_id', $query->createNamedParameter($objectId)));
|
|
|
|
}
|
|
|
|
|
2016-10-20 19:02:18 +03:00
|
|
|
if ($activeFilter instanceof IFilter) {
|
|
|
|
$apps = $activeFilter->allowedApps();
|
|
|
|
if (!empty($apps)) {
|
|
|
|
$query->andWhere($query->expr()->in('app', $query->createNamedParameter($apps, IQueryBuilder::PARAM_STR_ARRAY)));
|
2015-11-04 11:26:52 +03:00
|
|
|
}
|
2016-10-20 19:02:18 +03:00
|
|
|
}
|
2015-11-04 11:26:52 +03:00
|
|
|
|
2016-10-20 19:02:18 +03:00
|
|
|
if (
|
|
|
|
$filter === 'files_favorites' ||
|
|
|
|
(in_array($filter, ['all', 'by', 'self']) && $userSettings->getUserSetting($user, 'stream', 'files_favorites'))
|
|
|
|
) {
|
|
|
|
try {
|
|
|
|
$favoriteFilter = $this->activityManager->getFilterById('files_favorites');
|
|
|
|
/** @var \OCA\Files\Activity\Filter\Favorites $favoriteFilter */
|
|
|
|
$favoriteFilter->filterFavorites($query);
|
|
|
|
} catch (\InvalidArgumentException $e) {
|
|
|
|
}
|
2015-11-04 11:26:52 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Order and specify the offset
|
|
|
|
*/
|
|
|
|
$sqlSort = ($sort === 'asc') ? 'ASC' : 'DESC';
|
|
|
|
$headers = $this->setOffsetFromSince($query, $user, $since, $sqlSort);
|
|
|
|
$query->orderBy('timestamp', $sqlSort)
|
|
|
|
->addOrderBy('activity_id', $sqlSort);
|
|
|
|
|
|
|
|
$query->setMaxResults($limit + 1);
|
|
|
|
|
|
|
|
$result = $query->execute();
|
|
|
|
$hasMore = false;
|
|
|
|
while ($row = $result->fetch()) {
|
|
|
|
if ($limit === 0) {
|
|
|
|
$hasMore = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
$headers['X-Activity-Last-Given'] = (int) $row['activity_id'];
|
|
|
|
$groupHelper->addActivity($row);
|
|
|
|
$limit--;
|
|
|
|
}
|
|
|
|
$result->closeCursor();
|
|
|
|
|
|
|
|
return ['data' => $groupHelper->getActivities(), 'has_more' => $hasMore, 'headers' => $headers];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param IQueryBuilder $query
|
|
|
|
* @param string $user
|
|
|
|
* @param int $since
|
|
|
|
* @param string $sort
|
|
|
|
*
|
|
|
|
* @return array Headers that should be set on the response
|
|
|
|
*
|
|
|
|
* @throws \OutOfBoundsException If $since is not owned by $user
|
|
|
|
*/
|
|
|
|
protected function setOffsetFromSince(IQueryBuilder $query, $user, $since, $sort) {
|
|
|
|
if ($since) {
|
|
|
|
$queryBuilder = $this->connection->getQueryBuilder();
|
2016-12-19 18:57:41 +03:00
|
|
|
$queryBuilder->select(['affecteduser', 'timestamp'])
|
2015-11-04 11:26:52 +03:00
|
|
|
->from('activity')
|
|
|
|
->where($queryBuilder->expr()->eq('activity_id', $queryBuilder->createNamedParameter((int) $since)));
|
|
|
|
$result = $queryBuilder->execute();
|
|
|
|
$activity = $result->fetch();
|
|
|
|
$result->closeCursor();
|
|
|
|
|
|
|
|
if ($activity) {
|
|
|
|
if ($activity['affecteduser'] !== $user) {
|
|
|
|
throw new \OutOfBoundsException('Invalid since', 2);
|
|
|
|
}
|
|
|
|
$timestamp = (int) $activity['timestamp'];
|
|
|
|
|
|
|
|
if ($sort === 'DESC') {
|
|
|
|
$query->andWhere($query->expr()->lte('timestamp', $query->createNamedParameter($timestamp)));
|
|
|
|
$query->andWhere($query->expr()->lt('activity_id', $query->createNamedParameter($since)));
|
|
|
|
} else {
|
|
|
|
$query->andWhere($query->expr()->gte('timestamp', $query->createNamedParameter($timestamp)));
|
|
|
|
$query->andWhere($query->expr()->gt('activity_id', $query->createNamedParameter($since)));
|
|
|
|
}
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Couldn't find the since, so find the oldest one and set the header
|
|
|
|
*/
|
2015-12-14 14:19:18 +03:00
|
|
|
$fetchQuery = $this->connection->getQueryBuilder();
|
|
|
|
$fetchQuery->select('activity_id')
|
2015-11-04 11:26:52 +03:00
|
|
|
->from('activity')
|
2015-12-14 14:19:18 +03:00
|
|
|
->where($fetchQuery->expr()->eq('affecteduser', $fetchQuery->createNamedParameter($user)))
|
2015-11-04 11:26:52 +03:00
|
|
|
->orderBy('timestamp', $sort)
|
|
|
|
->setMaxResults(1);
|
2015-12-14 14:19:18 +03:00
|
|
|
$result = $fetchQuery->execute();
|
2015-11-04 11:26:52 +03:00
|
|
|
$activity = $result->fetch();
|
|
|
|
$result->closeCursor();
|
|
|
|
|
|
|
|
if ($activity !== false) {
|
|
|
|
return [
|
|
|
|
'X-Activity-First-Known' => (int) $activity['activity_id'],
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
|
2014-12-10 18:11:57 +03:00
|
|
|
/**
|
|
|
|
* Verify that the filter is valid
|
|
|
|
*
|
2015-01-16 11:05:02 +03:00
|
|
|
* @param string $filterValue
|
2014-12-10 18:11:57 +03:00
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function validateFilter($filterValue) {
|
|
|
|
if (!isset($filterValue)) {
|
|
|
|
return 'all';
|
|
|
|
}
|
|
|
|
|
2014-07-02 17:16:40 +04:00
|
|
|
switch ($filterValue) {
|
2015-08-14 17:12:08 +03:00
|
|
|
case 'filter':
|
2014-07-02 17:16:40 +04:00
|
|
|
return $filterValue;
|
2014-06-03 20:16:45 +04:00
|
|
|
default:
|
2016-10-20 19:02:18 +03:00
|
|
|
try {
|
|
|
|
$this->activityManager->getFilterById($filterValue);
|
2014-07-02 17:16:40 +04:00
|
|
|
return $filterValue;
|
2016-10-20 19:02:18 +03:00
|
|
|
} catch (\InvalidArgumentException $e) {
|
|
|
|
return 'all';
|
2014-07-02 17:16:40 +04:00
|
|
|
}
|
2014-06-03 20:16:45 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-28 21:32:28 +04:00
|
|
|
/**
|
2014-06-04 16:15:23 +04:00
|
|
|
* Delete old events
|
|
|
|
*
|
2014-06-03 14:32:37 +04:00
|
|
|
* @param int $expireDays Minimum 1 day
|
2013-09-17 16:27:41 +04:00
|
|
|
*/
|
2014-07-14 15:13:23 +04:00
|
|
|
public function expire($expireDays = 365) {
|
2014-06-03 14:32:37 +04:00
|
|
|
$ttl = (60 * 60 * 24 * max(1, $expireDays));
|
2013-08-28 21:32:28 +04:00
|
|
|
|
2013-09-17 16:27:41 +04:00
|
|
|
$timelimit = time() - $ttl;
|
2014-07-14 15:13:23 +04:00
|
|
|
$this->deleteActivities(array(
|
2014-06-04 16:15:23 +04:00
|
|
|
'timestamp' => array($timelimit, '<'),
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Delete activities that match certain conditions
|
|
|
|
*
|
2014-06-04 18:52:08 +04:00
|
|
|
* @param array $conditions Array with conditions that have to be met
|
|
|
|
* 'field' => 'value' => `field` = 'value'
|
|
|
|
* 'field' => array('value', 'operator') => `field` operator 'value'
|
2014-06-04 16:15:23 +04:00
|
|
|
*/
|
2014-07-14 15:13:23 +04:00
|
|
|
public function deleteActivities($conditions) {
|
2014-06-04 16:15:23 +04:00
|
|
|
$sqlWhere = '';
|
|
|
|
$sqlParameters = $sqlWhereList = array();
|
|
|
|
foreach ($conditions as $column => $comparison) {
|
2014-06-04 16:57:11 +04:00
|
|
|
$sqlWhereList[] = " `$column` " . ((is_array($comparison) && isset($comparison[1])) ? $comparison[1] : '=') . ' ? ';
|
2014-06-04 16:15:23 +04:00
|
|
|
$sqlParameters[] = (is_array($comparison)) ? $comparison[0] : $comparison;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!empty($sqlWhereList)) {
|
2014-06-04 16:57:11 +04:00
|
|
|
$sqlWhere = ' WHERE ' . implode(' AND ', $sqlWhereList);
|
2014-06-04 16:15:23 +04:00
|
|
|
}
|
|
|
|
|
2020-03-02 15:55:13 +03:00
|
|
|
// Add galera safe delete chunking if using mysql
|
|
|
|
// Stops us hitting wsrep_max_ws_rows when large row counts are deleted
|
|
|
|
if($this->connection->getDatabasePlatform() instanceof MySqlPlatform) {
|
|
|
|
// Then use chunked delete
|
|
|
|
$max = 100000;
|
|
|
|
$query = $this->connection->prepare(
|
|
|
|
'DELETE FROM `*PREFIX*activity`' . $sqlWhere . " LIMIT " . $max);
|
|
|
|
do {
|
|
|
|
$query->execute($sqlParameters);
|
|
|
|
$deleted = $query->rowCount();
|
|
|
|
} while($deleted === $max);
|
|
|
|
} else {
|
|
|
|
// Dont use chunked delete - let the DB handle the large row count natively
|
|
|
|
$query = $this->connection->prepare(
|
|
|
|
'DELETE FROM `*PREFIX*activity`' . $sqlWhere);
|
|
|
|
$query->execute($sqlParameters);
|
|
|
|
}
|
2020-06-17 15:40:20 +03:00
|
|
|
}
|
2020-03-02 15:55:13 +03:00
|
|
|
|
2020-06-17 15:40:20 +03:00
|
|
|
public function getById(int $activityId): ?IEvent {
|
|
|
|
$query = $this->connection->getQueryBuilder();
|
|
|
|
$query->select('*')
|
|
|
|
->from('activity')
|
|
|
|
->where($query->expr()->eq('activity_id', $query->createNamedParameter($activityId)));
|
2020-03-02 15:55:13 +03:00
|
|
|
|
2020-06-17 15:40:20 +03:00
|
|
|
$result = $query->execute();
|
|
|
|
$hasMore = false;
|
|
|
|
if ($row = $result->fetch()) {
|
|
|
|
$event = $this->activityManager->generateEvent();
|
|
|
|
$event->setApp((string) $row['app'])
|
|
|
|
->setType((string) $row['type'])
|
|
|
|
->setAffectedUser((string) $row['affecteduser'])
|
|
|
|
->setAuthor((string) $row['user'])
|
|
|
|
->setTimestamp((int) $row['timestamp'])
|
|
|
|
->setSubject((string) $row['subject'], (array) json_decode($row['subjectparams'], true))
|
|
|
|
->setMessage((string) $row['message'], (array) json_decode($row['messageparams'], true))
|
|
|
|
->setObject((string) $row['object_type'], (int) $row['object_id'], (string) $row['file'])
|
|
|
|
->setLink((string) $row['link']);
|
|
|
|
|
|
|
|
return $event;
|
|
|
|
} else {
|
|
|
|
return null;
|
|
|
|
}
|
2013-08-28 21:32:28 +04:00
|
|
|
}
|
2013-08-28 19:36:48 +04:00
|
|
|
}
|