From ab41ebe4930c4b5b4ae9e66767db01a28753526e Mon Sep 17 00:00:00 2001 From: Avinash Gusain Date: Wed, 10 May 2023 16:51:00 +0530 Subject: [PATCH 01/36] create task --- lib/AppInfo/Application.php | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php index 3574f538..d2b8ca2f 100644 --- a/lib/AppInfo/Application.php +++ b/lib/AppInfo/Application.php @@ -37,9 +37,15 @@ use OCP\User\Events\UserChangedEvent; use OCA\EcloudAccounts\Listeners\UserChangedListener; use OCP\AppFramework\Http\Events\BeforeTemplateRenderedEvent; use OCA\EcloudAccounts\Listeners\BeforeTemplateRenderedListener; +use OCP\Defaults; +use OCP\IUser; +use Symfony\Component\EventDispatcher\EventDispatcherInterface; +use Symfony\Component\EventDispatcher\GenericEvent; class Application extends App implements IBootstrap { public const APP_ID = 'ecloud-accounts'; + public const TASKS_CALENDAR_URI = 'tasks'; + public const TASKS_CALENDAR_NAME = 'Tasks'; public function __construct(array $urlParams = []) { parent::__construct(self::APP_ID, $urlParams); @@ -52,9 +58,31 @@ class Application extends App implements IBootstrap { } public function boot(IBootContext $context): void { + $context->injectFn([$this, 'createTasksCalendar']); $serverContainer = $context->getServerContainer(); $serverContainer->registerService('LDAPConnectionService', function ($c) { return new LDAPConnectionService(); }); } + + public function createTasksCalendar(CalDavBackend $calDav, Defaults $themingDefaults, EventDispatcherInterface $dispatcher): void { + $dispatcher->addListener(IUser::class . '::firstLogin', function (GenericEvent $event) use ($calDav, $themingDefaults) { + $user = $event->getSubject(); + if (!$user instanceof IUser) { + return; + } + $userId = $user->getUID(); + $principal = 'principals/users/' . $userId; + if ($calDav->getCalendarsForUserCount($principal) === 0) { + + $calDav->createCalendar($principal, self::TASKS_CALENDAR_URI, [ + '{DAV:}displayname' => self::TASKS_CALENDAR_NAME, + '{http://apple.com/ns/ical/}calendar-color' => $themingDefaults->getColorPrimary(), + 'components' => 'VEVENT' + ]); + + } + + }); + } } -- GitLab From 49db6bc4fa6b1f2fd54c291783fbc1b4615bc0d5 Mon Sep 17 00:00:00 2001 From: Avinash Gusain Date: Wed, 10 May 2023 16:56:00 +0530 Subject: [PATCH 02/36] create task --- lib/AppInfo/Application.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php index d2b8ca2f..46069201 100644 --- a/lib/AppInfo/Application.php +++ b/lib/AppInfo/Application.php @@ -26,19 +26,19 @@ declare(strict_types=1); namespace OCA\EcloudAccounts\AppInfo; +use OCA\EcloudAccounts\Listeners\BeforeTemplateRenderedListener; +use OCA\EcloudAccounts\Listeners\BeforeUserDeletedListener; +use OCA\EcloudAccounts\Listeners\UserChangedListener; +use OCA\EcloudAccounts\Service\LDAPConnectionService; use OCP\AppFramework\App; +use OCP\AppFramework\Bootstrap\IBootContext; use OCP\AppFramework\Bootstrap\IBootstrap; use OCP\AppFramework\Bootstrap\IRegistrationContext; -use OCP\AppFramework\Bootstrap\IBootContext; -use OCA\EcloudAccounts\Listeners\BeforeUserDeletedListener; -use OCA\EcloudAccounts\Service\LDAPConnectionService; -use OCP\User\Events\BeforeUserDeletedEvent; -use OCP\User\Events\UserChangedEvent; -use OCA\EcloudAccounts\Listeners\UserChangedListener; use OCP\AppFramework\Http\Events\BeforeTemplateRenderedEvent; -use OCA\EcloudAccounts\Listeners\BeforeTemplateRenderedListener; use OCP\Defaults; use OCP\IUser; +use OCP\User\Events\BeforeUserDeletedEvent; +use OCP\User\Events\UserChangedEvent; use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\EventDispatcher\GenericEvent; -- GitLab From 5f33de3699b98def52fc1a82eb8f1a806371dc4c Mon Sep 17 00:00:00 2001 From: Avinash Gusain Date: Wed, 10 May 2023 17:44:54 +0530 Subject: [PATCH 03/36] create task --- lib/AppInfo/Application.php | 3 --- 1 file changed, 3 deletions(-) diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php index 46069201..0866b2cd 100644 --- a/lib/AppInfo/Application.php +++ b/lib/AppInfo/Application.php @@ -74,15 +74,12 @@ class Application extends App implements IBootstrap { $userId = $user->getUID(); $principal = 'principals/users/' . $userId; if ($calDav->getCalendarsForUserCount($principal) === 0) { - $calDav->createCalendar($principal, self::TASKS_CALENDAR_URI, [ '{DAV:}displayname' => self::TASKS_CALENDAR_NAME, '{http://apple.com/ns/ical/}calendar-color' => $themingDefaults->getColorPrimary(), 'components' => 'VEVENT' ]); - } - }); } } -- GitLab From 67f125b6ab946f3cc4514e0aabfab02464f0ac0f Mon Sep 17 00:00:00 2001 From: Avinash Gusain Date: Wed, 10 May 2023 19:07:32 +0530 Subject: [PATCH 04/36] create task --- lib/AppInfo/Application.php | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php index 0866b2cd..bfd34310 100644 --- a/lib/AppInfo/Application.php +++ b/lib/AppInfo/Application.php @@ -35,6 +35,7 @@ use OCP\AppFramework\Bootstrap\IBootContext; use OCP\AppFramework\Bootstrap\IBootstrap; use OCP\AppFramework\Bootstrap\IRegistrationContext; use OCP\AppFramework\Http\Events\BeforeTemplateRenderedEvent; +use OCA\DAV\CalDAV\CalDavBackend; use OCP\Defaults; use OCP\IUser; use OCP\User\Events\BeforeUserDeletedEvent; -- GitLab From d0629502f93b719f6ac909344986a8097e2e1033 Mon Sep 17 00:00:00 2001 From: Avinash Gusain Date: Wed, 10 May 2023 23:42:58 +0530 Subject: [PATCH 05/36] create task --- lib/AppInfo/Application.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php index bfd34310..a17c6207 100644 --- a/lib/AppInfo/Application.php +++ b/lib/AppInfo/Application.php @@ -74,7 +74,8 @@ class Application extends App implements IBootstrap { } $userId = $user->getUID(); $principal = 'principals/users/' . $userId; - if ($calDav->getCalendarsForUserCount($principal) === 0) { + $calendar = $calDav->getCalendarByUri($principal, self::TASKS_CALENDAR_NAME); + if ($calendar === null) { $calDav->createCalendar($principal, self::TASKS_CALENDAR_URI, [ '{DAV:}displayname' => self::TASKS_CALENDAR_NAME, '{http://apple.com/ns/ical/}calendar-color' => $themingDefaults->getColorPrimary(), -- GitLab From a7e218e3892dde8a9e6542c267e227b834c7bf26 Mon Sep 17 00:00:00 2001 From: Avinash Gusain Date: Thu, 11 May 2023 11:47:38 +0530 Subject: [PATCH 06/36] repair step --- lib/Migration/CreateTasksCalendar.php | 97 +++++++++++++++++++++++++++ 1 file changed, 97 insertions(+) create mode 100644 lib/Migration/CreateTasksCalendar.php diff --git a/lib/Migration/CreateTasksCalendar.php b/lib/Migration/CreateTasksCalendar.php new file mode 100644 index 00000000..bea89892 --- /dev/null +++ b/lib/Migration/CreateTasksCalendar.php @@ -0,0 +1,97 @@ + + * + * @author Joas Schilling + * + * @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 . + * + */ + +namespace OCA\EcloudAccounts\Migration; + +use OCP\IConfig; +use OCP\IDBConnection; +use OCP\Migration\IOutput; +use OCP\Migration\IRepairStep; +use OCP\IUser; +use OCP\IUserManager; + + +/** + * Class EcloudAccounts + * + * @package OCA\EcloudAccounts\Migration + */ +class EcloudAccounts implements IRepairStep { + + public const APP_ID = 'ecloud-accounts'; + public const TASKS_CALENDAR_URI = 'tasks'; + public const TASKS_CALENDAR_NAME = 'Tasks'; + + /** @var IDBConnection */ + protected $connection; + + /** @var IConfig */ + protected $config; + + /** @var IUserManager */ + private $userManager; + + public function __construct(IDBConnection $connection, IConfig $config, IUserManager $userManager) { + $this->connection = $connection; + $this->config = $config; + $this->userManager = $userManager; + } + + /** + * Returns the step's name + * + * @return string + * @since 9.1.0 + */ + public function getName() { + return 'Fix by creating Tasks calendar for user if not exist.'; + } + + /** + * @param IOutput $output + */ + public function run(IOutput $output) { + if ($this->config->getAppValue(self::APP_ID, 'CreateTasksHasRun') === 'yes') { + $output->info('Repair step already executed'); + return; + } + $this->userManager->callForSeenUsers(function (IUser $user) { + $userId = $user->getUID(); + $principal = 'principals/users/' . $userId; + $calendar = $calDav->getCalendarByUri($principal, self::TASKS_CALENDAR_NAME); + if ($calendar === null) { + $calDav->createCalendar($principal, self::TASKS_CALENDAR_URI, [ + '{DAV:}displayname' => self::TASKS_CALENDAR_NAME, + '{http://apple.com/ns/ical/}calendar-color' => $themingDefaults->getColorPrimary(), + 'components' => 'VEVENT' + ]); + } + + }); + + // if everything is done, no need to redo the repair during next upgrade + $this->config->setAppValue(self::APP_ID, 'CreateTasksHasRun', 'yes'); + } + + +} -- GitLab From bce1a8c69b3fa6431fbd8cbf08de110a04770a87 Mon Sep 17 00:00:00 2001 From: Avinash Gusain Date: Thu, 11 May 2023 16:09:11 +0530 Subject: [PATCH 07/36] repair step --- lib/Migration/CreateTasksCalendar.php | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/lib/Migration/CreateTasksCalendar.php b/lib/Migration/CreateTasksCalendar.php index bea89892..d03af010 100644 --- a/lib/Migration/CreateTasksCalendar.php +++ b/lib/Migration/CreateTasksCalendar.php @@ -30,15 +30,13 @@ use OCP\Migration\IRepairStep; use OCP\IUser; use OCP\IUserManager; - /** * Class EcloudAccounts * * @package OCA\EcloudAccounts\Migration */ class EcloudAccounts implements IRepairStep { - - public const APP_ID = 'ecloud-accounts'; + public const APP_ID = 'ecloud-accounts'; public const TASKS_CALENDAR_URI = 'tasks'; public const TASKS_CALENDAR_NAME = 'Tasks'; @@ -48,13 +46,13 @@ class EcloudAccounts implements IRepairStep { /** @var IConfig */ protected $config; - /** @var IUserManager */ + /** @var IUserManager */ private $userManager; public function __construct(IDBConnection $connection, IConfig $config, IUserManager $userManager) { $this->connection = $connection; $this->config = $config; - $this->userManager = $userManager; + $this->userManager = $userManager; } /** @@ -75,8 +73,8 @@ class EcloudAccounts implements IRepairStep { $output->info('Repair step already executed'); return; } - $this->userManager->callForSeenUsers(function (IUser $user) { - $userId = $user->getUID(); + $this->userManager->callForSeenUsers(function (IUser $user) { + $userId = $user->getUID(); $principal = 'principals/users/' . $userId; $calendar = $calDav->getCalendarByUri($principal, self::TASKS_CALENDAR_NAME); if ($calendar === null) { @@ -86,12 +84,9 @@ class EcloudAccounts implements IRepairStep { 'components' => 'VEVENT' ]); } + }); - }); - - // if everything is done, no need to redo the repair during next upgrade + // if everything is done, no need to redo the repair during next upgrade $this->config->setAppValue(self::APP_ID, 'CreateTasksHasRun', 'yes'); } - - } -- GitLab From 5cd03dee79b83df3675223bce0659c6a4749edf8 Mon Sep 17 00:00:00 2001 From: Avinash Gusain Date: Thu, 11 May 2023 17:00:16 +0530 Subject: [PATCH 08/36] repair step --- appinfo/info.xml | 5 +++++ lib/Migration/CreateTasksCalendar.php | 1 - 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/appinfo/info.xml b/appinfo/info.xml index a695b9fa..fade1a3b 100644 --- a/appinfo/info.xml +++ b/appinfo/info.xml @@ -27,4 +27,9 @@ OCA\EcloudAccounts\Command\Migrate2FASecrets + + + OCA\EcloudAccounts\Migration\CreateTasksCalendar + + diff --git a/lib/Migration/CreateTasksCalendar.php b/lib/Migration/CreateTasksCalendar.php index d03af010..dfea2ae1 100644 --- a/lib/Migration/CreateTasksCalendar.php +++ b/lib/Migration/CreateTasksCalendar.php @@ -85,7 +85,6 @@ class EcloudAccounts implements IRepairStep { ]); } }); - // if everything is done, no need to redo the repair during next upgrade $this->config->setAppValue(self::APP_ID, 'CreateTasksHasRun', 'yes'); } -- GitLab From 2f41acd2ee9c88add21a080ed24dd55f2bd86417 Mon Sep 17 00:00:00 2001 From: Avinash Gusain Date: Thu, 11 May 2023 20:08:39 +0530 Subject: [PATCH 09/36] repair step --- appinfo/info.xml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/appinfo/info.xml b/appinfo/info.xml index fade1a3b..11911750 100644 --- a/appinfo/info.xml +++ b/appinfo/info.xml @@ -27,9 +27,9 @@ OCA\EcloudAccounts\Command\Migrate2FASecrets - - - OCA\EcloudAccounts\Migration\CreateTasksCalendar - + + + OCA\EcloudAccounts\Migration\CreateTasksCalendar + -- GitLab From a389ca741d334954ea0f4edb2a30250d77e1b75a Mon Sep 17 00:00:00 2001 From: Avinash Gusain Date: Thu, 11 May 2023 20:12:30 +0530 Subject: [PATCH 10/36] repair step --- lib/Migration/CreateTasksCalendar.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Migration/CreateTasksCalendar.php b/lib/Migration/CreateTasksCalendar.php index dfea2ae1..258aadf7 100644 --- a/lib/Migration/CreateTasksCalendar.php +++ b/lib/Migration/CreateTasksCalendar.php @@ -31,11 +31,11 @@ use OCP\IUser; use OCP\IUserManager; /** - * Class EcloudAccounts + * Class CreateTasksCalendar * * @package OCA\EcloudAccounts\Migration */ -class EcloudAccounts implements IRepairStep { +class CreateTasksCalendar implements IRepairStep { public const APP_ID = 'ecloud-accounts'; public const TASKS_CALENDAR_URI = 'tasks'; public const TASKS_CALENDAR_NAME = 'Tasks'; -- GitLab From 4de6e1d2800bccc19707cd7c9b60812210f280e9 Mon Sep 17 00:00:00 2001 From: Avinash Gusain Date: Thu, 11 May 2023 20:16:01 +0530 Subject: [PATCH 11/36] repair step --- lib/Migration/CreateTasksCalendar.php | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/Migration/CreateTasksCalendar.php b/lib/Migration/CreateTasksCalendar.php index 258aadf7..bbc47fa8 100644 --- a/lib/Migration/CreateTasksCalendar.php +++ b/lib/Migration/CreateTasksCalendar.php @@ -29,6 +29,7 @@ use OCP\Migration\IOutput; use OCP\Migration\IRepairStep; use OCP\IUser; use OCP\IUserManager; +use OCA\DAV\CalDAV\CalDavBackend; /** * Class CreateTasksCalendar @@ -49,10 +50,14 @@ class CreateTasksCalendar implements IRepairStep { /** @var IUserManager */ private $userManager; - public function __construct(IDBConnection $connection, IConfig $config, IUserManager $userManager) { + /** @var CalDavBackend */ + protected $calDav; + + public function __construct(IDBConnection $connection, IConfig $config, IUserManager $userManager, CalDavBackend $calDav) { $this->connection = $connection; $this->config = $config; $this->userManager = $userManager; + $this->calDav = $calDav; } /** @@ -76,9 +81,9 @@ class CreateTasksCalendar implements IRepairStep { $this->userManager->callForSeenUsers(function (IUser $user) { $userId = $user->getUID(); $principal = 'principals/users/' . $userId; - $calendar = $calDav->getCalendarByUri($principal, self::TASKS_CALENDAR_NAME); + $calendar = $this->calDav->getCalendarByUri($principal, self::TASKS_CALENDAR_NAME); if ($calendar === null) { - $calDav->createCalendar($principal, self::TASKS_CALENDAR_URI, [ + $this->calDav->createCalendar($principal, self::TASKS_CALENDAR_URI, [ '{DAV:}displayname' => self::TASKS_CALENDAR_NAME, '{http://apple.com/ns/ical/}calendar-color' => $themingDefaults->getColorPrimary(), 'components' => 'VEVENT' -- GitLab From 9b794d41dd6ae7cb890e41e84535b1f884bbc2d0 Mon Sep 17 00:00:00 2001 From: Avinash Gusain Date: Thu, 11 May 2023 20:19:58 +0530 Subject: [PATCH 12/36] repair step --- lib/Migration/CreateTasksCalendar.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/Migration/CreateTasksCalendar.php b/lib/Migration/CreateTasksCalendar.php index bbc47fa8..50ab40e5 100644 --- a/lib/Migration/CreateTasksCalendar.php +++ b/lib/Migration/CreateTasksCalendar.php @@ -30,6 +30,7 @@ use OCP\Migration\IRepairStep; use OCP\IUser; use OCP\IUserManager; use OCA\DAV\CalDAV\CalDavBackend; +use OCP\Defaults; /** * Class CreateTasksCalendar @@ -53,11 +54,16 @@ class CreateTasksCalendar implements IRepairStep { /** @var CalDavBackend */ protected $calDav; - public function __construct(IDBConnection $connection, IConfig $config, IUserManager $userManager, CalDavBackend $calDav) { + /** @var Defaults */ + protected $themingDefaults; + + + public function __construct(IDBConnection $connection, IConfig $config, IUserManager $userManager, CalDavBackend $calDav, Defaults $themingDefaults) { $this->connection = $connection; $this->config = $config; $this->userManager = $userManager; $this->calDav = $calDav; + $this->themingDefaults = $themingDefaults; } /** @@ -85,7 +91,7 @@ class CreateTasksCalendar implements IRepairStep { if ($calendar === null) { $this->calDav->createCalendar($principal, self::TASKS_CALENDAR_URI, [ '{DAV:}displayname' => self::TASKS_CALENDAR_NAME, - '{http://apple.com/ns/ical/}calendar-color' => $themingDefaults->getColorPrimary(), + '{http://apple.com/ns/ical/}calendar-color' => $this->themingDefaults->getColorPrimary(), 'components' => 'VEVENT' ]); } -- GitLab From 097ab78f794cde41d03758d3d26d86f7865481ee Mon Sep 17 00:00:00 2001 From: Avinash Gusain Date: Thu, 11 May 2023 20:39:53 +0530 Subject: [PATCH 13/36] repair step --- lib/Migration/CreateTasksCalendar.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/Migration/CreateTasksCalendar.php b/lib/Migration/CreateTasksCalendar.php index 50ab40e5..47a3a9f0 100644 --- a/lib/Migration/CreateTasksCalendar.php +++ b/lib/Migration/CreateTasksCalendar.php @@ -80,15 +80,20 @@ class CreateTasksCalendar implements IRepairStep { * @param IOutput $output */ public function run(IOutput $output) { + \OC::$server->getLogger()->error("here1"); if ($this->config->getAppValue(self::APP_ID, 'CreateTasksHasRun') === 'yes') { $output->info('Repair step already executed'); return; } + \OC::$server->getLogger()->error("here2"); $this->userManager->callForSeenUsers(function (IUser $user) { $userId = $user->getUID(); + \OC::$server->getLogger()->error("here user".$userId); $principal = 'principals/users/' . $userId; $calendar = $this->calDav->getCalendarByUri($principal, self::TASKS_CALENDAR_NAME); if ($calendar === null) { + \OC::$server->getLogger()->error("here4"); + \OC::$server->getLogger()->error("here user enter".$userId); $this->calDav->createCalendar($principal, self::TASKS_CALENDAR_URI, [ '{DAV:}displayname' => self::TASKS_CALENDAR_NAME, '{http://apple.com/ns/ical/}calendar-color' => $this->themingDefaults->getColorPrimary(), -- GitLab From 9cb9e6cad9030217807112bd18161f986b93003a Mon Sep 17 00:00:00 2001 From: Avinash Gusain Date: Thu, 11 May 2023 23:28:45 +0530 Subject: [PATCH 14/36] repair step --- lib/Migration/CreateTasksCalendar.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Migration/CreateTasksCalendar.php b/lib/Migration/CreateTasksCalendar.php index 47a3a9f0..a847edcf 100644 --- a/lib/Migration/CreateTasksCalendar.php +++ b/lib/Migration/CreateTasksCalendar.php @@ -90,7 +90,7 @@ class CreateTasksCalendar implements IRepairStep { $userId = $user->getUID(); \OC::$server->getLogger()->error("here user".$userId); $principal = 'principals/users/' . $userId; - $calendar = $this->calDav->getCalendarByUri($principal, self::TASKS_CALENDAR_NAME); + $calendar = $this->calDav->getCalendarByUri($principal, self::TASKS_CALENDAR_URI); if ($calendar === null) { \OC::$server->getLogger()->error("here4"); \OC::$server->getLogger()->error("here user enter".$userId); -- GitLab From 630bd1457bcd8b7bd4ce731d9cb7fb02a5cf715a Mon Sep 17 00:00:00 2001 From: Avinash Gusain Date: Thu, 11 May 2023 23:30:15 +0530 Subject: [PATCH 15/36] repair step --- lib/Migration/CreateTasksCalendar.php | 5 ----- 1 file changed, 5 deletions(-) diff --git a/lib/Migration/CreateTasksCalendar.php b/lib/Migration/CreateTasksCalendar.php index a847edcf..6334bdc3 100644 --- a/lib/Migration/CreateTasksCalendar.php +++ b/lib/Migration/CreateTasksCalendar.php @@ -80,20 +80,15 @@ class CreateTasksCalendar implements IRepairStep { * @param IOutput $output */ public function run(IOutput $output) { - \OC::$server->getLogger()->error("here1"); if ($this->config->getAppValue(self::APP_ID, 'CreateTasksHasRun') === 'yes') { $output->info('Repair step already executed'); return; } - \OC::$server->getLogger()->error("here2"); $this->userManager->callForSeenUsers(function (IUser $user) { $userId = $user->getUID(); - \OC::$server->getLogger()->error("here user".$userId); $principal = 'principals/users/' . $userId; $calendar = $this->calDav->getCalendarByUri($principal, self::TASKS_CALENDAR_URI); if ($calendar === null) { - \OC::$server->getLogger()->error("here4"); - \OC::$server->getLogger()->error("here user enter".$userId); $this->calDav->createCalendar($principal, self::TASKS_CALENDAR_URI, [ '{DAV:}displayname' => self::TASKS_CALENDAR_NAME, '{http://apple.com/ns/ical/}calendar-color' => $this->themingDefaults->getColorPrimary(), -- GitLab From 17f907df03b341e1c3cba8f3eddb43cc9d25df56 Mon Sep 17 00:00:00 2001 From: Avinash Gusain Date: Thu, 11 May 2023 23:32:05 +0530 Subject: [PATCH 16/36] repair step --- appinfo/info.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/appinfo/info.xml b/appinfo/info.xml index 11911750..44ce9959 100644 --- a/appinfo/info.xml +++ b/appinfo/info.xml @@ -31,5 +31,5 @@ OCA\EcloudAccounts\Migration\CreateTasksCalendar - + -- GitLab From 116ec50b6a7cfcec65593208aeac44ec5b0e0daa Mon Sep 17 00:00:00 2001 From: Avinash Gusain Date: Sat, 13 May 2023 01:29:15 +0530 Subject: [PATCH 17/36] VTodo added --- lib/AppInfo/Application.php | 17 +++- lib/Migration/CreateTasksCalendar.php | 110 +++++++++++++++++--------- 2 files changed, 87 insertions(+), 40 deletions(-) diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php index a17c6207..3153564a 100644 --- a/lib/AppInfo/Application.php +++ b/lib/AppInfo/Application.php @@ -42,11 +42,13 @@ use OCP\User\Events\BeforeUserDeletedEvent; use OCP\User\Events\UserChangedEvent; use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\EventDispatcher\GenericEvent; +use OCP\IDBConnection; class Application extends App implements IBootstrap { public const APP_ID = 'ecloud-accounts'; public const TASKS_CALENDAR_URI = 'tasks'; public const TASKS_CALENDAR_NAME = 'Tasks'; + public const TASKS_CALENDAR_COMPONENT = 'VTODO'; public function __construct(array $urlParams = []) { parent::__construct(self::APP_ID, $urlParams); @@ -66,7 +68,7 @@ class Application extends App implements IBootstrap { }); } - public function createTasksCalendar(CalDavBackend $calDav, Defaults $themingDefaults, EventDispatcherInterface $dispatcher): void { + public function createTasksCalendar(CalDavBackend $calDav,IDBConnection $db, Defaults $themingDefaults, EventDispatcherInterface $dispatcher): void { $dispatcher->addListener(IUser::class . '::firstLogin', function (GenericEvent $event) use ($calDav, $themingDefaults) { $user = $event->getSubject(); if (!$user instanceof IUser) { @@ -75,11 +77,20 @@ class Application extends App implements IBootstrap { $userId = $user->getUID(); $principal = 'principals/users/' . $userId; $calendar = $calDav->getCalendarByUri($principal, self::TASKS_CALENDAR_NAME); - if ($calendar === null) { + $query = $db->getQueryBuilder(); + $query->select($fields)->from('calendars') + ->where($query->expr()->eq('uri', $query->createNamedParameter(self::TASKS_CALENDAR_NAME))) + ->andWhere($query->expr()->eq('principaluri', $query->createNamedParameter($principal))) + ->andWhere($query->expr()->eq('components', $query->createNamedParameter(self::TASKS_CALENDAR_COMPONENT))) + ->setMaxResults(1); + $stmt = $query->executeQuery(); + $row = $stmt->fetch(); + $stmt->closeCursor(); + if ($row === false) { $calDav->createCalendar($principal, self::TASKS_CALENDAR_URI, [ '{DAV:}displayname' => self::TASKS_CALENDAR_NAME, '{http://apple.com/ns/ical/}calendar-color' => $themingDefaults->getColorPrimary(), - 'components' => 'VEVENT' + 'components' => self::TASKS_CALENDAR_COMPONENT ]); } }); diff --git a/lib/Migration/CreateTasksCalendar.php b/lib/Migration/CreateTasksCalendar.php index 6334bdc3..86d12eec 100644 --- a/lib/Migration/CreateTasksCalendar.php +++ b/lib/Migration/CreateTasksCalendar.php @@ -37,44 +37,71 @@ use OCP\Defaults; * * @package OCA\EcloudAccounts\Migration */ -class CreateTasksCalendar implements IRepairStep { - public const APP_ID = 'ecloud-accounts'; - public const TASKS_CALENDAR_URI = 'tasks'; - public const TASKS_CALENDAR_NAME = 'Tasks'; +class CreateTasksCalendar implements IRepairStep +{ + public const APP_ID = 'ecloud-accounts'; + public const TASKS_CALENDAR_URI = 'tasks'; + public const TASKS_CALENDAR_COMPONENT = 'VTODO'; - /** @var IDBConnection */ - protected $connection; + /** @var IDBConnection */ + protected $connection; - /** @var IConfig */ - protected $config; + /** @var IConfig */ + protected $config; - /** @var IUserManager */ - private $userManager; + /** @var IUserManager */ + private $userManager; - /** @var CalDavBackend */ - protected $calDav; + /** @var CalDavBackend */ + protected $calDav; - /** @var Defaults */ - protected $themingDefaults; + /** @var Defaults */ + protected $themingDefaults; - public function __construct(IDBConnection $connection, IConfig $config, IUserManager $userManager, CalDavBackend $calDav, Defaults $themingDefaults) { - $this->connection = $connection; - $this->config = $config; - $this->userManager = $userManager; - $this->calDav = $calDav; - $this->themingDefaults = $themingDefaults; - } + public function __construct(IDBConnection $connection, IConfig $config, IUserManager $userManager, CalDavBackend $calDav, Defaults $themingDefaults) + { + $this->connection = $connection; + $this->config = $config; + $this->userManager = $userManager; + $this->calDav = $calDav; + $this->themingDefaults = $themingDefaults; + } + + /** + * Returns the step's name + * + * @return string + * @since 9.1.0 + */ + public function getName() + { + return 'Fix by creating Tasks calendar for user if not exist.'; + } + + /** + * Returns the step's name + * + * @return string + * @since 9.1.0 + */ + public function getPrincipalUriByCalendar():array + { + $query = $this->db->getQueryBuilder(); + $query->select(['Distinct c1.principaluri']) + ->from('calendars', 'c1') + ->leftJoin('c1', 'calendars', 'c2', + $query->expr()->andX( + $query->expr()->eq('c1.principaluri', 'c2.principaluri'), + $query->expr()->eq('c2.uri', 'tasks'), + $query->expr()->eq('c2.components', 'vtodo') + ) + ) + ->where($query->expr()->isNull('c2.principaluri')); + $stmt = $query->executeQuery(); + return $stmt->fetchAll(); + } - /** - * Returns the step's name - * - * @return string - * @since 9.1.0 - */ - public function getName() { - return 'Fix by creating Tasks calendar for user if not exist.'; - } /** * @param IOutput $output @@ -84,18 +111,27 @@ class CreateTasksCalendar implements IRepairStep { $output->info('Repair step already executed'); return; } - $this->userManager->callForSeenUsers(function (IUser $user) { - $userId = $user->getUID(); - $principal = 'principals/users/' . $userId; - $calendar = $this->calDav->getCalendarByUri($principal, self::TASKS_CALENDAR_URI); - if ($calendar === null) { + //get all principal uri having no task calendar with component as TODO but have personal calendar + $result= $this->getPrincipalUriByCalendar(); + foreach ($result as $row) { + $principaluri = $row['principaluri']; + $query = $db->getQueryBuilder(); + $query->select($fields)->from('calendars') + ->where($query->expr()->eq('uri', $query->createNamedParameter(self::TASKS_CALENDAR_NAME))) + ->andWhere($query->expr()->eq('principaluri', $query->createNamedParameter($principal))) + ->andWhere($query->expr()->eq('components', $query->createNamedParameter(self::TASKS_CALENDAR_COMPONENT))) + ->setMaxResults(1); + $stmt = $query->executeQuery(); + $row = $stmt->fetch(); + $stmt->closeCursor(); + if ($row === false) { $this->calDav->createCalendar($principal, self::TASKS_CALENDAR_URI, [ '{DAV:}displayname' => self::TASKS_CALENDAR_NAME, '{http://apple.com/ns/ical/}calendar-color' => $this->themingDefaults->getColorPrimary(), - 'components' => 'VEVENT' + 'components' => 'VTODO' ]); } - }); + }; // if everything is done, no need to redo the repair during next upgrade $this->config->setAppValue(self::APP_ID, 'CreateTasksHasRun', 'yes'); } -- GitLab From 074b89e29d60e4ec3175854db1dcc503a506064e Mon Sep 17 00:00:00 2001 From: Avinash Gusain Date: Sat, 13 May 2023 01:46:26 +0530 Subject: [PATCH 18/36] with left join removed callForSeenUsers --- lib/Migration/CreateTasksCalendar.php | 24 +++++++----------------- 1 file changed, 7 insertions(+), 17 deletions(-) diff --git a/lib/Migration/CreateTasksCalendar.php b/lib/Migration/CreateTasksCalendar.php index 86d12eec..0ea41c79 100644 --- a/lib/Migration/CreateTasksCalendar.php +++ b/lib/Migration/CreateTasksCalendar.php @@ -114,23 +114,13 @@ class CreateTasksCalendar implements IRepairStep //get all principal uri having no task calendar with component as TODO but have personal calendar $result= $this->getPrincipalUriByCalendar(); foreach ($result as $row) { - $principaluri = $row['principaluri']; - $query = $db->getQueryBuilder(); - $query->select($fields)->from('calendars') - ->where($query->expr()->eq('uri', $query->createNamedParameter(self::TASKS_CALENDAR_NAME))) - ->andWhere($query->expr()->eq('principaluri', $query->createNamedParameter($principal))) - ->andWhere($query->expr()->eq('components', $query->createNamedParameter(self::TASKS_CALENDAR_COMPONENT))) - ->setMaxResults(1); - $stmt = $query->executeQuery(); - $row = $stmt->fetch(); - $stmt->closeCursor(); - if ($row === false) { - $this->calDav->createCalendar($principal, self::TASKS_CALENDAR_URI, [ - '{DAV:}displayname' => self::TASKS_CALENDAR_NAME, - '{http://apple.com/ns/ical/}calendar-color' => $this->themingDefaults->getColorPrimary(), - 'components' => 'VTODO' - ]); - } + $principal = $row['principaluri']; + $this->calDav->createCalendar($principal, self::TASKS_CALENDAR_URI, [ + '{DAV:}displayname' => self::TASKS_CALENDAR_NAME, + '{http://apple.com/ns/ical/}calendar-color' => $this->themingDefaults->getColorPrimary(), + 'components' => 'VTODO' + ]); + }; // if everything is done, no need to redo the repair during next upgrade $this->config->setAppValue(self::APP_ID, 'CreateTasksHasRun', 'yes'); -- GitLab From bd20a743705c2174791cbfcec3c7ec8e69a5c25b Mon Sep 17 00:00:00 2001 From: Avinash Gusain Date: Mon, 15 May 2023 00:07:20 +0530 Subject: [PATCH 19/36] code fix --- lib/AppInfo/Application.php | 6 +- lib/Migration/CreateTasksCalendar.php | 114 ++++++++++++-------------- 2 files changed, 57 insertions(+), 63 deletions(-) diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php index 3153564a..d99a0988 100644 --- a/lib/AppInfo/Application.php +++ b/lib/AppInfo/Application.php @@ -26,6 +26,7 @@ declare(strict_types=1); namespace OCA\EcloudAccounts\AppInfo; +use OCA\DAV\CalDAV\CalDavBackend; use OCA\EcloudAccounts\Listeners\BeforeTemplateRenderedListener; use OCA\EcloudAccounts\Listeners\BeforeUserDeletedListener; use OCA\EcloudAccounts\Listeners\UserChangedListener; @@ -35,14 +36,13 @@ use OCP\AppFramework\Bootstrap\IBootContext; use OCP\AppFramework\Bootstrap\IBootstrap; use OCP\AppFramework\Bootstrap\IRegistrationContext; use OCP\AppFramework\Http\Events\BeforeTemplateRenderedEvent; -use OCA\DAV\CalDAV\CalDavBackend; use OCP\Defaults; +use OCP\IDBConnection; use OCP\IUser; use OCP\User\Events\BeforeUserDeletedEvent; use OCP\User\Events\UserChangedEvent; use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\EventDispatcher\GenericEvent; -use OCP\IDBConnection; class Application extends App implements IBootstrap { public const APP_ID = 'ecloud-accounts'; @@ -68,7 +68,7 @@ class Application extends App implements IBootstrap { }); } - public function createTasksCalendar(CalDavBackend $calDav,IDBConnection $db, Defaults $themingDefaults, EventDispatcherInterface $dispatcher): void { + public function createTasksCalendar(CalDavBackend $calDav, IDBConnection $db, Defaults $themingDefaults, EventDispatcherInterface $dispatcher): void { $dispatcher->addListener(IUser::class . '::firstLogin', function (GenericEvent $event) use ($calDav, $themingDefaults) { $user = $event->getSubject(); if (!$user instanceof IUser) { diff --git a/lib/Migration/CreateTasksCalendar.php b/lib/Migration/CreateTasksCalendar.php index 0ea41c79..cc924875 100644 --- a/lib/Migration/CreateTasksCalendar.php +++ b/lib/Migration/CreateTasksCalendar.php @@ -23,84 +23,79 @@ namespace OCA\EcloudAccounts\Migration; +use OCA\DAV\CalDAV\CalDavBackend; +use OCP\Defaults; use OCP\IConfig; use OCP\IDBConnection; +use OCP\IUserManager; use OCP\Migration\IOutput; use OCP\Migration\IRepairStep; -use OCP\IUser; -use OCP\IUserManager; -use OCA\DAV\CalDAV\CalDavBackend; -use OCP\Defaults; /** * Class CreateTasksCalendar * * @package OCA\EcloudAccounts\Migration */ -class CreateTasksCalendar implements IRepairStep -{ - public const APP_ID = 'ecloud-accounts'; - public const TASKS_CALENDAR_URI = 'tasks'; - public const TASKS_CALENDAR_COMPONENT = 'VTODO'; +class CreateTasksCalendar implements IRepairStep { + public const APP_ID = 'ecloud-accounts'; + public const TASKS_CALENDAR_URI = 'tasks'; + public const TASKS_CALENDAR_COMPONENT = 'VTODO'; - /** @var IDBConnection */ - protected $connection; + /** @var IDBConnection */ + protected $connection; - /** @var IConfig */ - protected $config; + /** @var IConfig */ + protected $config; - /** @var IUserManager */ - private $userManager; + /** @var IUserManager */ + private $userManager; - /** @var CalDavBackend */ - protected $calDav; + /** @var CalDavBackend */ + protected $calDav; - /** @var Defaults */ - protected $themingDefaults; + /** @var Defaults */ + protected $themingDefaults; - public function __construct(IDBConnection $connection, IConfig $config, IUserManager $userManager, CalDavBackend $calDav, Defaults $themingDefaults) - { - $this->connection = $connection; - $this->config = $config; - $this->userManager = $userManager; - $this->calDav = $calDav; - $this->themingDefaults = $themingDefaults; - } + public function __construct(IDBConnection $connection, IConfig $config, IUserManager $userManager, CalDavBackend $calDav, Defaults $themingDefaults) { + $this->connection = $connection; + $this->config = $config; + $this->userManager = $userManager; + $this->calDav = $calDav; + $this->themingDefaults = $themingDefaults; + } - /** - * Returns the step's name - * - * @return string - * @since 9.1.0 - */ - public function getName() - { - return 'Fix by creating Tasks calendar for user if not exist.'; - } + /** + * Returns the step's name + * + * @return string + * @since 9.1.0 + */ + public function getName() { + return 'Fix by creating Tasks calendar for user if not exist.'; + } - /** - * Returns the step's name - * - * @return string - * @since 9.1.0 - */ - public function getPrincipalUriByCalendar():array - { - $query = $this->db->getQueryBuilder(); - $query->select(['Distinct c1.principaluri']) - ->from('calendars', 'c1') - ->leftJoin('c1', 'calendars', 'c2', - $query->expr()->andX( - $query->expr()->eq('c1.principaluri', 'c2.principaluri'), - $query->expr()->eq('c2.uri', 'tasks'), - $query->expr()->eq('c2.components', 'vtodo') - ) - ) + /** + * Returns the step's name + * + * @return string + * @since 9.1.0 + */ + public function getPrincipalUriByCalendar():array { + $query = $this->db->getQueryBuilder(); + $query->select(['Distinct c1.principaluri']) + ->from('calendars', 'c1') + ->leftJoin('c1', 'calendars', 'c2', + $query->expr()->andX( + $query->expr()->eq('c1.principaluri', 'c2.principaluri'), + $query->expr()->eq('c2.uri', 'tasks'), + $query->expr()->eq('c2.components', 'VTODO') + ) + ) ->where($query->expr()->isNull('c2.principaluri')); - $stmt = $query->executeQuery(); - return $stmt->fetchAll(); - } + $stmt = $query->executeQuery(); + return $stmt->fetchAll(); + } /** @@ -112,7 +107,7 @@ class CreateTasksCalendar implements IRepairStep return; } //get all principal uri having no task calendar with component as TODO but have personal calendar - $result= $this->getPrincipalUriByCalendar(); + $result = $this->getPrincipalUriByCalendar(); foreach ($result as $row) { $principal = $row['principaluri']; $this->calDav->createCalendar($principal, self::TASKS_CALENDAR_URI, [ @@ -120,7 +115,6 @@ class CreateTasksCalendar implements IRepairStep '{http://apple.com/ns/ical/}calendar-color' => $this->themingDefaults->getColorPrimary(), 'components' => 'VTODO' ]); - }; // if everything is done, no need to redo the repair during next upgrade $this->config->setAppValue(self::APP_ID, 'CreateTasksHasRun', 'yes'); -- GitLab From 6528b4519483dd0b0873fefdea5f234dc5dcbccd Mon Sep 17 00:00:00 2001 From: Avinash Gusain Date: Mon, 15 May 2023 10:29:26 +0530 Subject: [PATCH 20/36] code fix --- lib/AppInfo/Application.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php index d99a0988..35ff27e5 100644 --- a/lib/AppInfo/Application.php +++ b/lib/AppInfo/Application.php @@ -69,7 +69,7 @@ class Application extends App implements IBootstrap { } public function createTasksCalendar(CalDavBackend $calDav, IDBConnection $db, Defaults $themingDefaults, EventDispatcherInterface $dispatcher): void { - $dispatcher->addListener(IUser::class . '::firstLogin', function (GenericEvent $event) use ($calDav, $themingDefaults) { + $dispatcher->addListener(IUser::class . '::firstLogin', function (GenericEvent $event) use ($calDav, $themingDefaults, $db) { $user = $event->getSubject(); if (!$user instanceof IUser) { return; -- GitLab From 79ae4fa327301911779121cf87272d27a8b8ced4 Mon Sep 17 00:00:00 2001 From: Avinash Gusain Date: Mon, 15 May 2023 10:56:59 +0530 Subject: [PATCH 21/36] code fix --- lib/AppInfo/Application.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php index 35ff27e5..47f82a4c 100644 --- a/lib/AppInfo/Application.php +++ b/lib/AppInfo/Application.php @@ -76,10 +76,10 @@ class Application extends App implements IBootstrap { } $userId = $user->getUID(); $principal = 'principals/users/' . $userId; - $calendar = $calDav->getCalendarByUri($principal, self::TASKS_CALENDAR_NAME); + $calendar = $calDav->getCalendarByUri($principal, self::TASKS_CALENDAR_URI); $query = $db->getQueryBuilder(); - $query->select($fields)->from('calendars') - ->where($query->expr()->eq('uri', $query->createNamedParameter(self::TASKS_CALENDAR_NAME))) + $query->select('uri')->from('calendars') + ->where($query->expr()->eq('uri', $query->createNamedParameter(self::TASKS_CALENDAR_URI))) ->andWhere($query->expr()->eq('principaluri', $query->createNamedParameter($principal))) ->andWhere($query->expr()->eq('components', $query->createNamedParameter(self::TASKS_CALENDAR_COMPONENT))) ->setMaxResults(1); -- GitLab From 4d17bf21ff427dda3f4f1dc1fa80dc379c3084c0 Mon Sep 17 00:00:00 2001 From: Avinash Gusain Date: Mon, 15 May 2023 11:59:56 +0530 Subject: [PATCH 22/36] code fix --- lib/Migration/CreateTasksCalendar.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Migration/CreateTasksCalendar.php b/lib/Migration/CreateTasksCalendar.php index cc924875..321d6cf2 100644 --- a/lib/Migration/CreateTasksCalendar.php +++ b/lib/Migration/CreateTasksCalendar.php @@ -82,7 +82,7 @@ class CreateTasksCalendar implements IRepairStep { * @since 9.1.0 */ public function getPrincipalUriByCalendar():array { - $query = $this->db->getQueryBuilder(); + $query = $this->connection->getQueryBuilder(); $query->select(['Distinct c1.principaluri']) ->from('calendars', 'c1') ->leftJoin('c1', 'calendars', 'c2', -- GitLab From 779ec8cecebbc524ed40e34cb7b55bbace9903e5 Mon Sep 17 00:00:00 2001 From: Avinash Gusain Date: Mon, 15 May 2023 12:28:07 +0530 Subject: [PATCH 23/36] code fix --- lib/Migration/CreateTasksCalendar.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/Migration/CreateTasksCalendar.php b/lib/Migration/CreateTasksCalendar.php index 321d6cf2..45e6e6d4 100644 --- a/lib/Migration/CreateTasksCalendar.php +++ b/lib/Migration/CreateTasksCalendar.php @@ -83,14 +83,14 @@ class CreateTasksCalendar implements IRepairStep { */ public function getPrincipalUriByCalendar():array { $query = $this->connection->getQueryBuilder(); + $query= $expr = $qb->expr(); $query->select(['Distinct c1.principaluri']) ->from('calendars', 'c1') - ->leftJoin('c1', 'calendars', 'c2', - $query->expr()->andX( - $query->expr()->eq('c1.principaluri', 'c2.principaluri'), - $query->expr()->eq('c2.uri', 'tasks'), - $query->expr()->eq('c2.components', 'VTODO') - ) + ->leftJoin('c1', 'calendars', 'c2',$expr->andX( + $expr->eq('c1.principaluri', 'c2.principaluri'), + $expr->eq('c2.uri', $qb->createNamedParameter('tasks')), + $expr->eq('c2.components', $qb->createNamedParameter('VTODO')) + ) ) ->where($query->expr()->isNull('c2.principaluri')); $stmt = $query->executeQuery(); -- GitLab From ce2ede9c31f4e4cecc7da649447e9f9902c96fb8 Mon Sep 17 00:00:00 2001 From: Avinash Gusain Date: Mon, 15 May 2023 12:30:01 +0530 Subject: [PATCH 24/36] code fix --- lib/Migration/CreateTasksCalendar.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/Migration/CreateTasksCalendar.php b/lib/Migration/CreateTasksCalendar.php index 45e6e6d4..ebd8b5b2 100644 --- a/lib/Migration/CreateTasksCalendar.php +++ b/lib/Migration/CreateTasksCalendar.php @@ -83,14 +83,14 @@ class CreateTasksCalendar implements IRepairStep { */ public function getPrincipalUriByCalendar():array { $query = $this->connection->getQueryBuilder(); - $query= $expr = $qb->expr(); + $query = $expr = $qb->expr(); $query->select(['Distinct c1.principaluri']) ->from('calendars', 'c1') - ->leftJoin('c1', 'calendars', 'c2',$expr->andX( - $expr->eq('c1.principaluri', 'c2.principaluri'), - $expr->eq('c2.uri', $qb->createNamedParameter('tasks')), - $expr->eq('c2.components', $qb->createNamedParameter('VTODO')) - ) + ->leftJoin('c1', 'calendars', 'c2', $expr->andX( + $expr->eq('c1.principaluri', 'c2.principaluri'), + $expr->eq('c2.uri', $qb->createNamedParameter('tasks')), + $expr->eq('c2.components', $qb->createNamedParameter('VTODO')) + ) ) ->where($query->expr()->isNull('c2.principaluri')); $stmt = $query->executeQuery(); -- GitLab From 32dc92d9f0528334063670d37df9d12a52c7bf14 Mon Sep 17 00:00:00 2001 From: Avinash Gusain Date: Mon, 15 May 2023 12:35:18 +0530 Subject: [PATCH 25/36] code fix --- lib/Migration/CreateTasksCalendar.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/Migration/CreateTasksCalendar.php b/lib/Migration/CreateTasksCalendar.php index ebd8b5b2..2fdabea4 100644 --- a/lib/Migration/CreateTasksCalendar.php +++ b/lib/Migration/CreateTasksCalendar.php @@ -83,13 +83,13 @@ class CreateTasksCalendar implements IRepairStep { */ public function getPrincipalUriByCalendar():array { $query = $this->connection->getQueryBuilder(); - $query = $expr = $qb->expr(); + $expr = $query->expr(); $query->select(['Distinct c1.principaluri']) ->from('calendars', 'c1') ->leftJoin('c1', 'calendars', 'c2', $expr->andX( $expr->eq('c1.principaluri', 'c2.principaluri'), - $expr->eq('c2.uri', $qb->createNamedParameter('tasks')), - $expr->eq('c2.components', $qb->createNamedParameter('VTODO')) + $expr->eq('c2.uri', $query->createNamedParameter('tasks')), + $expr->eq('c2.components', $query->createNamedParameter('VTODO')) ) ) ->where($query->expr()->isNull('c2.principaluri')); -- GitLab From d0b29e35be2b88bbe34f2d8df4254c68650564e9 Mon Sep 17 00:00:00 2001 From: Avinash Gusain Date: Mon, 15 May 2023 12:40:54 +0530 Subject: [PATCH 26/36] code fix --- lib/Migration/CreateTasksCalendar.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/Migration/CreateTasksCalendar.php b/lib/Migration/CreateTasksCalendar.php index 2fdabea4..71c56a7f 100644 --- a/lib/Migration/CreateTasksCalendar.php +++ b/lib/Migration/CreateTasksCalendar.php @@ -39,6 +39,7 @@ use OCP\Migration\IRepairStep; class CreateTasksCalendar implements IRepairStep { public const APP_ID = 'ecloud-accounts'; public const TASKS_CALENDAR_URI = 'tasks'; + public const TASKS_CALENDAR_NAME = 'Tasks'; public const TASKS_CALENDAR_COMPONENT = 'VTODO'; /** @var IDBConnection */ @@ -84,7 +85,7 @@ class CreateTasksCalendar implements IRepairStep { public function getPrincipalUriByCalendar():array { $query = $this->connection->getQueryBuilder(); $expr = $query->expr(); - $query->select(['Distinct c1.principaluri']) + $query->select($query->createFunction('DISTINCT ' . $query->getColumnName('c1.principaluri'))) ->from('calendars', 'c1') ->leftJoin('c1', 'calendars', 'c2', $expr->andX( $expr->eq('c1.principaluri', 'c2.principaluri'), -- GitLab From 989534a54243a8ad6c95ba7b31885daa5667da49 Mon Sep 17 00:00:00 2001 From: Avinash Gusain Date: Mon, 15 May 2023 12:42:28 +0530 Subject: [PATCH 27/36] pipeline fix --- lib/Migration/CreateTasksCalendar.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Migration/CreateTasksCalendar.php b/lib/Migration/CreateTasksCalendar.php index 71c56a7f..ce1f833d 100644 --- a/lib/Migration/CreateTasksCalendar.php +++ b/lib/Migration/CreateTasksCalendar.php @@ -39,7 +39,7 @@ use OCP\Migration\IRepairStep; class CreateTasksCalendar implements IRepairStep { public const APP_ID = 'ecloud-accounts'; public const TASKS_CALENDAR_URI = 'tasks'; - public const TASKS_CALENDAR_NAME = 'Tasks'; + public const TASKS_CALENDAR_NAME = 'Tasks'; public const TASKS_CALENDAR_COMPONENT = 'VTODO'; /** @var IDBConnection */ -- GitLab From 84721ae12aa0f48e797ff17c2b6ec7c7cb307a44 Mon Sep 17 00:00:00 2001 From: Avinash Gusain Date: Mon, 15 May 2023 13:08:35 +0530 Subject: [PATCH 28/36] unique task url fix --- lib/Migration/CreateTasksCalendar.php | 39 +++++++++++++++++++++++---- 1 file changed, 34 insertions(+), 5 deletions(-) diff --git a/lib/Migration/CreateTasksCalendar.php b/lib/Migration/CreateTasksCalendar.php index ce1f833d..8a4732a1 100644 --- a/lib/Migration/CreateTasksCalendar.php +++ b/lib/Migration/CreateTasksCalendar.php @@ -77,12 +77,11 @@ class CreateTasksCalendar implements IRepairStep { } /** - * Returns the step's name + * Returns the array of calendars * - * @return string - * @since 9.1.0 + * @return array */ - public function getPrincipalUriByCalendar():array { + private function getPrincipalUriByCalendar():array { $query = $this->connection->getQueryBuilder(); $expr = $query->expr(); $query->select($query->createFunction('DISTINCT ' . $query->getColumnName('c1.principaluri'))) @@ -98,6 +97,35 @@ class CreateTasksCalendar implements IRepairStep { return $stmt->fetchAll(); } + /** + * Returns the unique Task Uri + * + * @return string + */ + private function getUniqueTaskUri($taskUri):string { + $qb = $this->connection->createQueryBuilder(); + $qb->select('COUNT(*)') + ->from('tasks') + ->where('name = :name') + ->setParameter('name', $taskUri); + + $count = $qb->execute()->fetchColumn(); + + // If the name already exists, add a suffix until you find an available task uri + if ($count > 0) { + $i = 1; + while ($count > 0) { + $newUriName = $taskUri . ' - ' . $i; + $qb->setParameter('name', $newUriName); + $count = $qb->execute()->fetchColumn(); + $i++; + } + $taskUri = $newUriName; + } + return $taskUri; + } + + /** * @param IOutput $output @@ -111,7 +139,8 @@ class CreateTasksCalendar implements IRepairStep { $result = $this->getPrincipalUriByCalendar(); foreach ($result as $row) { $principal = $row['principaluri']; - $this->calDav->createCalendar($principal, self::TASKS_CALENDAR_URI, [ + $taskUri = getUniqueTaskUri(self::TASKS_CALENDAR_NAME); + $this->calDav->createCalendar($principal, $taskUri, [ '{DAV:}displayname' => self::TASKS_CALENDAR_NAME, '{http://apple.com/ns/ical/}calendar-color' => $this->themingDefaults->getColorPrimary(), 'components' => 'VTODO' -- GitLab From 6e69f41aff1723de5b82aaab1b37049351209b3a Mon Sep 17 00:00:00 2001 From: Avinash Gusain Date: Mon, 15 May 2023 13:13:45 +0530 Subject: [PATCH 29/36] unique task url fix --- lib/Migration/CreateTasksCalendar.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Migration/CreateTasksCalendar.php b/lib/Migration/CreateTasksCalendar.php index 8a4732a1..4c2aa3e0 100644 --- a/lib/Migration/CreateTasksCalendar.php +++ b/lib/Migration/CreateTasksCalendar.php @@ -103,7 +103,7 @@ class CreateTasksCalendar implements IRepairStep { * @return string */ private function getUniqueTaskUri($taskUri):string { - $qb = $this->connection->createQueryBuilder(); + $qb = $this->connection->getQueryBuilder(); $qb->select('COUNT(*)') ->from('tasks') ->where('name = :name') @@ -139,7 +139,7 @@ class CreateTasksCalendar implements IRepairStep { $result = $this->getPrincipalUriByCalendar(); foreach ($result as $row) { $principal = $row['principaluri']; - $taskUri = getUniqueTaskUri(self::TASKS_CALENDAR_NAME); + $taskUri = $this->getUniqueTaskUri(self::TASKS_CALENDAR_NAME); $this->calDav->createCalendar($principal, $taskUri, [ '{DAV:}displayname' => self::TASKS_CALENDAR_NAME, '{http://apple.com/ns/ical/}calendar-color' => $this->themingDefaults->getColorPrimary(), -- GitLab From 6e8c67fdb056d434950d0de2a542499b692094ac Mon Sep 17 00:00:00 2001 From: Avinash Gusain Date: Mon, 15 May 2023 13:15:07 +0530 Subject: [PATCH 30/36] unique task url fix --- lib/Migration/CreateTasksCalendar.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/Migration/CreateTasksCalendar.php b/lib/Migration/CreateTasksCalendar.php index 4c2aa3e0..4c1caa8a 100644 --- a/lib/Migration/CreateTasksCalendar.php +++ b/lib/Migration/CreateTasksCalendar.php @@ -105,9 +105,9 @@ class CreateTasksCalendar implements IRepairStep { private function getUniqueTaskUri($taskUri):string { $qb = $this->connection->getQueryBuilder(); $qb->select('COUNT(*)') - ->from('tasks') - ->where('name = :name') - ->setParameter('name', $taskUri); + ->from('calendars') + ->where('uri = :uri') + ->setParameter('uri', $taskUri); $count = $qb->execute()->fetchColumn(); -- GitLab From 3ff9a112c513dc94483f761eef821c87f858a82c Mon Sep 17 00:00:00 2001 From: Avinash Gusain Date: Mon, 15 May 2023 13:16:11 +0530 Subject: [PATCH 31/36] unique task url fix --- lib/Migration/CreateTasksCalendar.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Migration/CreateTasksCalendar.php b/lib/Migration/CreateTasksCalendar.php index 4c1caa8a..0b88a35e 100644 --- a/lib/Migration/CreateTasksCalendar.php +++ b/lib/Migration/CreateTasksCalendar.php @@ -116,7 +116,7 @@ class CreateTasksCalendar implements IRepairStep { $i = 1; while ($count > 0) { $newUriName = $taskUri . ' - ' . $i; - $qb->setParameter('name', $newUriName); + $qb->setParameter('uri', $newUriName); $count = $qb->execute()->fetchColumn(); $i++; } -- GitLab From 6f80a75daabf8db8176cf3e728e708cd1670c6bc Mon Sep 17 00:00:00 2001 From: Avinash Gusain Date: Mon, 15 May 2023 13:17:34 +0530 Subject: [PATCH 32/36] unique task url fix --- lib/Migration/CreateTasksCalendar.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Migration/CreateTasksCalendar.php b/lib/Migration/CreateTasksCalendar.php index 0b88a35e..b6cd1f65 100644 --- a/lib/Migration/CreateTasksCalendar.php +++ b/lib/Migration/CreateTasksCalendar.php @@ -104,7 +104,7 @@ class CreateTasksCalendar implements IRepairStep { */ private function getUniqueTaskUri($taskUri):string { $qb = $this->connection->getQueryBuilder(); - $qb->select('COUNT(*)') + $qb->select('uri') ->from('calendars') ->where('uri = :uri') ->setParameter('uri', $taskUri); -- GitLab From 616f5b9ed53e5c8a2d7b926f7a754d8444453218 Mon Sep 17 00:00:00 2001 From: Avinash Gusain Date: Mon, 15 May 2023 13:27:46 +0530 Subject: [PATCH 33/36] unique task url fix --- lib/Migration/CreateTasksCalendar.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/Migration/CreateTasksCalendar.php b/lib/Migration/CreateTasksCalendar.php index b6cd1f65..d6984e9b 100644 --- a/lib/Migration/CreateTasksCalendar.php +++ b/lib/Migration/CreateTasksCalendar.php @@ -106,9 +106,8 @@ class CreateTasksCalendar implements IRepairStep { $qb = $this->connection->getQueryBuilder(); $qb->select('uri') ->from('calendars') - ->where('uri = :uri') - ->setParameter('uri', $taskUri); - + ->where($qb->expr()->eq('uri', $qb->createNamedParameter($taskUri))) + ->andWhere($qb->expr()->eq('principaluri', $qb->createNamedParameter($principal))); $count = $qb->execute()->fetchColumn(); // If the name already exists, add a suffix until you find an available task uri @@ -116,7 +115,8 @@ class CreateTasksCalendar implements IRepairStep { $i = 1; while ($count > 0) { $newUriName = $taskUri . ' - ' . $i; - $qb->setParameter('uri', $newUriName); + $qb->where($qb->expr()->eq('uri', $qb->createNamedParameter($newUriName))); + $qb->andWhere($qb->expr()->eq('principaluri', $qb->createNamedParameter($principal))); $count = $qb->execute()->fetchColumn(); $i++; } @@ -139,7 +139,7 @@ class CreateTasksCalendar implements IRepairStep { $result = $this->getPrincipalUriByCalendar(); foreach ($result as $row) { $principal = $row['principaluri']; - $taskUri = $this->getUniqueTaskUri(self::TASKS_CALENDAR_NAME); + $taskUri = $this->getUniqueTaskUri($principal, self::TASKS_CALENDAR_NAME); $this->calDav->createCalendar($principal, $taskUri, [ '{DAV:}displayname' => self::TASKS_CALENDAR_NAME, '{http://apple.com/ns/ical/}calendar-color' => $this->themingDefaults->getColorPrimary(), -- GitLab From 5a72fe0c0962544f118e32b983848069c254ef75 Mon Sep 17 00:00:00 2001 From: Avinash Gusain Date: Mon, 15 May 2023 13:32:52 +0530 Subject: [PATCH 34/36] unique task url fix --- lib/Migration/CreateTasksCalendar.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Migration/CreateTasksCalendar.php b/lib/Migration/CreateTasksCalendar.php index d6984e9b..ea54b5d5 100644 --- a/lib/Migration/CreateTasksCalendar.php +++ b/lib/Migration/CreateTasksCalendar.php @@ -102,7 +102,7 @@ class CreateTasksCalendar implements IRepairStep { * * @return string */ - private function getUniqueTaskUri($taskUri):string { + private function getUniqueTaskUri($principal,$taskUri):string { $qb = $this->connection->getQueryBuilder(); $qb->select('uri') ->from('calendars') -- GitLab From 9e8257b365f73627dd129ffce3d20db9be3d55ca Mon Sep 17 00:00:00 2001 From: Avinash Gusain Date: Mon, 15 May 2023 13:35:25 +0530 Subject: [PATCH 35/36] unique task url fix --- lib/Migration/CreateTasksCalendar.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Migration/CreateTasksCalendar.php b/lib/Migration/CreateTasksCalendar.php index ea54b5d5..1600bdc5 100644 --- a/lib/Migration/CreateTasksCalendar.php +++ b/lib/Migration/CreateTasksCalendar.php @@ -102,7 +102,7 @@ class CreateTasksCalendar implements IRepairStep { * * @return string */ - private function getUniqueTaskUri($principal,$taskUri):string { + private function getUniqueTaskUri($principal, $taskUri):string { $qb = $this->connection->getQueryBuilder(); $qb->select('uri') ->from('calendars') -- GitLab From df4c791776fc4f485b227833452d97a8d21733c0 Mon Sep 17 00:00:00 2001 From: Avinash Gusain Date: Mon, 15 May 2023 13:41:55 +0530 Subject: [PATCH 36/36] unique task url fix --- lib/Migration/CreateTasksCalendar.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/Migration/CreateTasksCalendar.php b/lib/Migration/CreateTasksCalendar.php index 1600bdc5..b7b8f24d 100644 --- a/lib/Migration/CreateTasksCalendar.php +++ b/lib/Migration/CreateTasksCalendar.php @@ -114,7 +114,8 @@ class CreateTasksCalendar implements IRepairStep { if ($count > 0) { $i = 1; while ($count > 0) { - $newUriName = $taskUri . ' - ' . $i; + $newUriName = $taskUri . '-' . $i; + $qb->select('uri'); $qb->where($qb->expr()->eq('uri', $qb->createNamedParameter($newUriName))); $qb->andWhere($qb->expr()->eq('principaluri', $qb->createNamedParameter($principal))); $count = $qb->execute()->fetchColumn(); @@ -139,7 +140,7 @@ class CreateTasksCalendar implements IRepairStep { $result = $this->getPrincipalUriByCalendar(); foreach ($result as $row) { $principal = $row['principaluri']; - $taskUri = $this->getUniqueTaskUri($principal, self::TASKS_CALENDAR_NAME); + $taskUri = $this->getUniqueTaskUri($principal, self::TASKS_CALENDAR_URI); $this->calDav->createCalendar($principal, $taskUri, [ '{DAV:}displayname' => self::TASKS_CALENDAR_NAME, '{http://apple.com/ns/ical/}calendar-color' => $this->themingDefaults->getColorPrimary(), -- GitLab