diff --git a/appinfo/application.php b/appinfo/application.php index 9404fae3..88f15dfe 100644 --- a/appinfo/application.php +++ b/appinfo/application.php @@ -33,7 +33,6 @@ use OCA\Activity\Display; use OCA\Activity\GroupHelper; use OCA\Activity\FilesHooks; use OCA\Activity\MailQueueHandler; -use OCA\Activity\MockUtilSendMail; use OCA\Activity\Navigation; use OCA\Activity\ParameterHelper; use OCA\Activity\UserSettings; @@ -112,9 +111,13 @@ class Application extends App { }); $container->registerService('Hooks', function(IContainer $c) { + /** @var \OC\Server $server */ + $server = $c->query('ServerContainer'); + return new FilesHooks( $c->query('ActivityData'), $c->query('UserSettings'), + $server->getDatabaseConnection(), $c->query('CurrentUID') ); }); @@ -196,6 +199,9 @@ class Application extends App { }); $container->registerService('ActivitiesController', function(IContainer $c) { + /** @var \OC\Server $server */ + $server = $c->query('ServerContainer'); + return new Activities( $c->query('AppName'), $c->query('Request'), @@ -204,6 +210,7 @@ class Application extends App { $c->query('GroupHelper'), $c->query('Navigation'), $c->query('UserSettings'), + $server->getDateTimeFormatter(), $c->query('CurrentUID') ); }); diff --git a/appinfo/update.php b/appinfo/update.php index 1e4c6538..70c5c28c 100644 --- a/appinfo/update.php +++ b/appinfo/update.php @@ -1,6 +1,7 @@ getConfig()->getAppValue('activity', 'installed_version'); +$connection = \OC::$server->getDatabaseConnection(); if (version_compare($installedVersion, '1.2.2', '<')) { $mistakes = [ @@ -11,18 +12,16 @@ if (version_compare($installedVersion, '1.2.2', '<')) { foreach ($mistakes as $entry) { list($table, $column) = $entry; - $query = \OCP\DB::prepare( + + $numEntries = $connection->executeUpdate( 'DELETE FROM `' . $table . '` WHERE `' . $column . "` NOT LIKE '%]' AND `" . $column . "` NOT LIKE '%}'" ); - $numEntries = $query->execute(); \OC::$server->getLogger()->debug('Deleting ' . $numEntries . ' activities with a broken ' . $column . ' value.', ['app' => 'acitivity']); } } if (version_compare($installedVersion, '1.2.2', '<')) { - $update = \OCP\DB::prepare('UPDATE `*PREFIX*activity` SET `app` = ? WHERE `type` = ?'); - $update->execute(array('files_sharing', 'shared')); - $update = \OCP\DB::prepare('UPDATE `*PREFIX*activity_mq` SET `amq_appid` = ? WHERE `amq_type` = ?'); - $update->execute(array('files_sharing', 'shared')); + $connection->executeUpdate('UPDATE `*PREFIX*activity` SET `app` = ? WHERE `type` = ?', array('files_sharing', 'shared')); + $connection->executeUpdate('UPDATE `*PREFIX*activity_mq` SET `amq_appid` = ? WHERE `amq_type` = ?', array('files_sharing', 'shared')); } diff --git a/controller/activities.php b/controller/activities.php index 49add7fa..7ee6bc7f 100644 --- a/controller/activities.php +++ b/controller/activities.php @@ -23,7 +23,6 @@ namespace OCA\Activity\Controller; -use OC\Files\View; use OCA\Activity\Data; use OCA\Activity\Display; use OCA\Activity\GroupHelper; @@ -31,6 +30,7 @@ use OCA\Activity\Navigation; use OCA\Activity\UserSettings; use OCP\AppFramework\Controller; use OCP\AppFramework\Http\TemplateResponse; +use OCP\IDateTimeFormatter; use OCP\IRequest; class Activities extends Controller { @@ -51,6 +51,9 @@ class Activities extends Controller { /** @var \OCA\Activity\UserSettings */ protected $settings; + /** @var IDateTimeFormatter */ + protected $dateTimeFormatter; + /** @var string */ protected $user; @@ -64,15 +67,25 @@ class Activities extends Controller { * @param GroupHelper $helper * @param Navigation $navigation * @param UserSettings $settings + * @param IDateTimeFormatter $dateTimeFormatter * @param string $user */ - public function __construct($appName, IRequest $request, Data $data, Display $display, GroupHelper $helper, Navigation $navigation, UserSettings $settings, $user) { + public function __construct($appName, + IRequest $request, + Data $data, + Display $display, + GroupHelper $helper, + Navigation $navigation, + UserSettings $settings, + IDateTimeFormatter $dateTimeFormatter, + $user) { parent::__construct($appName, $request); $this->data = $data; $this->display = $display; $this->helper = $helper; $this->navigation = $navigation; $this->settings = $settings; + $this->dateTimeFormatter = $dateTimeFormatter; $this->user = $user; } @@ -106,6 +119,7 @@ class Activities extends Controller { return new TemplateResponse('activity', 'stream.list', [ 'activity' => $this->data->read($this->helper, $this->settings, $pageOffset * self::DEFAULT_PAGE_SIZE, self::DEFAULT_PAGE_SIZE, $filter), 'displayHelper' => $this->display, + 'dateTimeFormatter' => $this->dateTimeFormatter, ], ''); } } diff --git a/controller/settings.php b/controller/settings.php index a35d8459..d29fc7dc 100644 --- a/controller/settings.php +++ b/controller/settings.php @@ -69,7 +69,15 @@ class Settings extends Controller { * @param IL10N $l10n * @param string $user */ - public function __construct($appName, IRequest $request, IConfig $config, ISecureRandom $random, IURLGenerator $urlGenerator, Data $data, UserSettings $userSettings, IL10N $l10n, $user) { + public function __construct($appName, + IRequest $request, + IConfig $config, + ISecureRandom $random, + IURLGenerator $urlGenerator, + Data $data, + UserSettings $userSettings, + IL10N $l10n, + $user) { parent::__construct($appName, $request); $this->config = $config; $this->random = $random; diff --git a/js/settings.js b/js/settings.js index b1505f47..9fb18241 100644 --- a/js/settings.js +++ b/js/settings.js @@ -8,11 +8,12 @@ $(document).ready(function() { }); } - $('#activity_notifications input[type=checkbox]').change(saveSettings); + var $activityNotifications = $('#activity_notifications'); + $activityNotifications.find('input[type=checkbox]').change(saveSettings); - $('#activity_notifications select').change(saveSettings); + $activityNotifications.find('select').change(saveSettings); - $('#activity_notifications .activity_select_group').click(function() { + $activityNotifications.find('.activity_select_group').click(function() { var selectGroup = '#activity_notifications .' + $(this).attr('data-select-group'); var checkedBoxes = $(selectGroup + ':checked').length; $(selectGroup).attr('checked', true); diff --git a/lib/api.php b/lib/api.php index b762666d..f804479d 100644 --- a/lib/api.php +++ b/lib/api.php @@ -32,7 +32,7 @@ class Api { const DEFAULT_LIMIT = 30; - static public function get($param) { + static public function get() { $app = new AppInfo\Application(); $data = $app->getContainer()->query('ActivityData'); diff --git a/lib/backgroundjob/emailnotification.php b/lib/backgroundjob/emailnotification.php index 16af8ba9..633a0799 100644 --- a/lib/backgroundjob/emailnotification.php +++ b/lib/backgroundjob/emailnotification.php @@ -23,6 +23,7 @@ namespace OCA\Activity\BackgroundJob; +use OC\BackgroundJob\TimedJob; use OCA\Activity\AppInfo\Application; use OCA\Activity\MailQueueHandler; use OCP\IConfig; @@ -33,7 +34,7 @@ use OCP\ILogger; * * @package OCA\Activity\BackgroundJob */ -class EmailNotification extends \OC\BackgroundJob\TimedJob { +class EmailNotification extends TimedJob { const CLI_EMAIL_BATCH_SIZE = 500; const WEB_EMAIL_BATCH_SIZE = 25; @@ -72,7 +73,7 @@ class EmailNotification extends \OC\BackgroundJob\TimedJob { } } - public function fixDIForJobs() { + protected function fixDIForJobs() { $application = new Application(); $this->mqHandler = $application->getContainer()->query('MailQueueHandler'); diff --git a/lib/backgroundjob/expireactivities.php b/lib/backgroundjob/expireactivities.php index e81be9b3..6005a8f1 100644 --- a/lib/backgroundjob/expireactivities.php +++ b/lib/backgroundjob/expireactivities.php @@ -23,23 +23,48 @@ namespace OCA\Activity\BackgroundJob; +use OC\BackgroundJob\TimedJob; +use OCA\Activity\AppInfo\Application; +use OCA\Activity\Data; +use OCP\IConfig; + /** * Class ExpireActivities * * @package OCA\Activity\BackgroundJob */ -class ExpireActivities extends \OC\BackgroundJob\TimedJob { - public function __construct() { +class ExpireActivities extends TimedJob { + /** @var Data */ + protected $data; + /** @var IConfig */ + protected $config; + + /** + * @param Data $data + * @param IConfig $config + */ + public function __construct(Data $data = null, IConfig $config = null) { // Run once per day $this->setInterval(60 * 60 * 24); + + if ($data === null || $config === null) { + $this->fixDIForJobs(); + } else { + $this->data = $data; + $this->config = $config; + } + } + + protected function fixDIForJobs() { + $application = new Application(); + + $this->data = $application->getContainer()->query('ActivityData'); + $this->config = \OC::$server->getConfig(); } protected function run($argument) { // Remove activities that are older then one year - $expireDays = \OCP\Config::getSystemValue('activity_expire_days', 365); - $data = new \OCA\Activity\Data( - \OC::$server->getActivityManager() - ); - $data->expire($expireDays); + $expireDays = $this->config->getSystemValue('activity_expire_days', 365); + $this->data->expire($expireDays); } } diff --git a/lib/display.php b/lib/display.php index a0f21b5d..3e758089 100644 --- a/lib/display.php +++ b/lib/display.php @@ -24,9 +24,11 @@ namespace OCA\Activity; use OC\Files\View; +use OCP\Files; +use OCP\IDateTimeFormatter; +use OCP\IPreview; +use OCP\IURLGenerator; use OCP\Template; -use OCP\User; -use OCP\Util; /** * Class Display @@ -34,13 +36,13 @@ use OCP\Util; * @package OCA\Activity */ class Display { - /** @var \OCP\IDateTimeFormatter */ + /** @var IDateTimeFormatter */ protected $dateTimeFormatter; - /** @var \OCP\IPreview */ + /** @var IPreview */ protected $preview; - /** @var \OCP\IURLGenerator */ + /** @var IURLGenerator */ protected $urlGenerator; /** @var View */ @@ -49,15 +51,15 @@ class Display { /** * Constructor * - * @param \OCP\IDateTimeFormatter $dateTimeFormatter - * @param \OCP\IPreview $preview - * @param \OCP\IURLGenerator $urlGenerator + * @param IDateTimeFormatter $dateTimeFormatter + * @param IPreview $preview + * @param IURLGenerator $urlGenerator * @param View $view */ - public function __construct(\OCP\IDateTimeFormatter $dateTimeFormatter, - \OCP\IPreview $preview, - \OCP\IURLGenerator $urlGenerator, - \OC\Files\View $view) { + public function __construct(IDateTimeFormatter $dateTimeFormatter, + IPreview $preview, + IURLGenerator $urlGenerator, + View $view) { $this->view = $view; $this->preview = $preview; $this->dateTimeFormatter = $dateTimeFormatter; @@ -74,8 +76,6 @@ class Display { $tmpl = new Template('activity', 'stream.item'); $tmpl->assign('formattedDate', $this->dateTimeFormatter->formatDateTime($activity['timestamp'])); $tmpl->assign('formattedTimestamp', Template::relative_modified_date($activity['timestamp'])); - $tmpl->assign('user', $activity['user']); - $tmpl->assign('displayName', User::getDisplayName($activity['user'])); if (strpos($activity['subjectformatted']['markup']['trimmed'], 'assign('previewLink', $this->getPreviewLink($activity['file'], $is_dir)); // show a preview image if the file still exists - $mimeType = \OCP\Files::getMimeType($activity['file']); + $mimeType = Files::getMimeType($activity['file']); if ($mimeType && !$is_dir && $this->preview->isMimeSupported($mimeType) && $exist) { $tmpl->assign('previewImageLink', $this->urlGenerator->linkToRoute('core_ajax_preview', array( diff --git a/lib/fileshooks.php b/lib/fileshooks.php index 32dc232d..31e6378e 100755 --- a/lib/fileshooks.php +++ b/lib/fileshooks.php @@ -27,7 +27,7 @@ use OC\Files\View; use OCA\Activity\Extension\Files; use OCA\Activity\Extension\Files_Sharing; use OCP\Activity\IExtension; -use OCP\DB; +use OCP\IDBConnection; use OCP\Share; use OCP\Util; @@ -42,6 +42,9 @@ class FilesHooks { /** @var \OCA\Activity\UserSettings */ protected $userSettings; + /** @var \OCP\IDBConnection */ + protected $connection; + /** @var string|false */ protected $currentUser; @@ -50,11 +53,13 @@ class FilesHooks { * * @param Data $activityData * @param UserSettings $userSettings + * @param IDBConnection $connection * @param string|false $currentUser */ - public function __construct(Data $activityData, UserSettings $userSettings, $currentUser) { + public function __construct(Data $activityData, UserSettings $userSettings, IDBConnection $connection, $currentUser) { $this->activityData = $activityData; $this->userSettings = $userSettings; + $this->connection = $connection; $this->currentUser = $currentUser; } @@ -158,8 +163,10 @@ class FilesHooks { if ($uidOwner !== $this->currentUser) { Filesystem::initMountPoints($uidOwner); $info = Filesystem::getFileInfo($path); - $ownerView = new View('/'.$uidOwner.'/files'); - $path = $ownerView->getPath($info['fileid']); + if ($info !== false) { + $ownerView = new View('/' . $uidOwner . '/files'); + $path = $ownerView->getPath((int) $info['fileid']); + } } return array($path, $uidOwner); @@ -228,14 +235,9 @@ class FilesHooks { // Check when there was a naming conflict and the target is different // for some of the users - $query = DB::prepare('SELECT `share_with`, `file_target` FROM `*PREFIX*share` WHERE `parent` = ? '); - $result = $query->execute(array($params['id'])); - if (DB::isError($result)) { - Util::writeLog('OCA\Activity\Hooks::shareFileOrFolderWithGroup', DB::getErrorMessage($result), Util::ERROR); - } else { - while ($row = $result->fetchRow()) { - $affectedUsers[$row['share_with']] = $row['file_target']; - } + $query = $this->connection->executeQuery('SELECT `share_with`, `file_target` FROM `*PREFIX*share` WHERE `parent` = ? ', [(int) $params['id']]); + while ($row = $query->fetch()) { + $affectedUsers[$row['share_with']] = $row['file_target']; } foreach ($affectedUsers as $user => $path) { diff --git a/lib/navigation.php b/lib/navigation.php index 4cf1fe30..28ba46e2 100644 --- a/lib/navigation.php +++ b/lib/navigation.php @@ -26,7 +26,6 @@ namespace OCA\Activity; use \OCP\Activity\IManager; use \OCP\IURLGenerator; use \OCP\Template; -use \OCP\Util; /** * Class Navigation @@ -43,6 +42,9 @@ class Navigation { /** @var \OCP\IURLGenerator */ protected $URLGenerator; + /** @var UserSettings */ + protected $userSettings; + /** @var string */ protected $active; @@ -63,7 +65,13 @@ class Navigation { * @param string $rssToken * @param null|string $active Navigation entry that should be marked as active */ - public function __construct(\OC_L10N $l, IManager $manager, IURLGenerator $URLGenerator, UserSettings $userSettings, $user, $rssToken, $active = 'all') { + public function __construct(\OC_L10N $l, + IManager $manager, + IURLGenerator $URLGenerator, + UserSettings $userSettings, + $user, + $rssToken, + $active = 'all') { $this->l = $l; $this->activityManager = $manager; $this->URLGenerator = $URLGenerator; diff --git a/lib/parameterhelper.php b/lib/parameterhelper.php index da5ed7f9..2a69d1ea 100644 --- a/lib/parameterhelper.php +++ b/lib/parameterhelper.php @@ -27,7 +27,6 @@ use OCP\Activity\IManager; use OCP\IConfig; use OCP\IL10N; use OCP\IUserManager; -use OCP\User; use OCP\Util; use OC\Files\View; @@ -58,7 +57,12 @@ class ParameterHelper { * @param IL10N $l * @param string $user */ - public function __construct(IManager $activityManager, IUserManager $userManager, View $rootView, IConfig $config, IL10N $l, $user) { + public function __construct(IManager $activityManager, + IUserManager $userManager, + View $rootView, + IConfig $config, + IL10N $l, + $user) { $this->activityManager = $activityManager; $this->userManager = $userManager; $this->rootView = $rootView; diff --git a/templates/personal.php b/templates/personal.php index b1060c48..d5368bfa 100644 --- a/templates/personal.php +++ b/templates/personal.php @@ -63,7 +63,7 @@ style('activity', 'settings');
- t('Send emails:')); ?> +