diff --git a/src/CliCommand/SitesDelete.php b/src/CliCommand/SitesDelete.php new file mode 100644 index 00000000..dafb83d1 --- /dev/null +++ b/src/CliCommand/SitesDelete.php @@ -0,0 +1,50 @@ +mvcFactory->makeTempModel('Sites'); + + $id = intval($input->getArgument('id')); + + $model + ->findOrFail($id) + ->delete(); + + return Command::SUCCESS; + } + + protected function configure(): void + { + $this + ->addArgument('id', InputArgument::REQUIRED, 'The numeric site ID to delete'); + } + +} \ No newline at end of file diff --git a/src/Model/Site.php b/src/Model/Site.php index 4ca8eb6d..0dfce69f 100644 --- a/src/Model/Site.php +++ b/src/Model/Site.php @@ -816,6 +816,20 @@ protected function isSiteSpecificTaskScheduled(string $type): bool ); } + protected function onBeforeDelete($id) + { + if (empty($id)) + { + return; + } + + // Remove all tasks attached to this site + /** @var Tasks $taskModel */ + $taskModel = $this->getContainer()->mvcFactory->makeTempModel('Tasks'); + $taskModel->setState('site_id', $id); + $taskModel->get(true)->delete(); + } + private function applyUserGroupsToQuery(Query $query): void { if (defined('AKEEBA_CLI'))