protected function execute(InputInterface $input, OutputInterface $output) { $output->writeln('<info>Clearing tracker...</info>'); $trackerId = $input->getArgument('trackerId'); $tracker = \Tracker_Definition::get($trackerId); if (!$tracker) { throw new \Exception('Tracker Clear: Tracker not found'); } $perms = \Perms::get('tracker', $trackerId); if (!$perms->admin_trackers) { throw new \Exception('Tracker Clear: Admin permission required'); } $confirm = $input->getOption('confirm'); $utilities = new \Services_Tracker_Utilities(); if ($confirm) { $utilities->clearTracker($trackerId); $output->writeln('<info>Tracker clear done</info>'); } else { $name = $tracker->getConfiguration('name'); $output->writeln("<info>Use the --confirm option to proceed with the clear operation.</info>"); $output->writeln("<info> There is NO undo and no notifications will be sent.</info>"); $output->writeln("<info> All items in tracker #{$trackerId} \"{$name}\" will be deleted.</info>"); } return 0; }
function action_clear($input) { return TikiLib::lib('tiki')->allocate_extra('tracker_clear_items', function () use($input) { $trackerId = $input->trackerId->int(); $confirm = $input->confirm->int(); $perms = Perms::get('tracker', $trackerId); if (!$perms->admin_trackers) { throw new Services_Exception_Denied(tr('Reserved for tracker administrators')); } $definition = Tracker_Definition::get($trackerId); if (!$definition) { throw new Services_Exception_NotFound(); } if ($confirm) { $this->utilities->clearTracker($trackerId); return array('trackerId' => 0); } return array('trackerId' => $trackerId, 'name' => $definition->getConfiguration('name')); }); }