Пример #1
0
 /**
  * Export stats.
  * @param $groupId
  * @param $type
  * @param $saveTo
  * @return bool
  * @throws \Exception
  */
 public function export($groupId, $type, $saveTo)
 {
     if (!$this->actionParser->groupExists($groupId)) {
         throw new \Exception('Group ID does not exist: ' . $groupId);
     }
     if ($type != 'csv') {
         throw new \Exception('Unknown export type: ' . $type);
     }
     $actions = $this->actionParser->parseGroup($groupId);
     $fullRows = $this->actionParser->getFullRows($actions);
     $fullRows = $this->filterRows($fullRows);
     $this->exportToCSV($fullRows, $saveTo);
     $this->display->outputMessage('Export saved to: ' . $saveTo);
     return true;
 }
Пример #2
0
 public function execute()
 {
     $this->prepare();
     if ($this->dbManager->hasTriggers()) {
         throw new \Exception('dbtrack is still running.');
     } else {
         if (!$this->dbManager->trackingTablesExist()) {
             throw new \Exception('Tracking tables do not exist. Use <dbt start> to start.');
         }
     }
     $actionParser = new ActionParser($this->dbms, $this->dbManager);
     $this->helper = new Helper($this->dbms, $this->dbManager);
     $options = $this->parseOptions($this->options);
     if (!isset($options[0]) || empty($options[0])) {
         throw new \Exception('No dbtrack group id specified. Use <dbt stats> to get one.');
     }
     if (!$actionParser->groupExists($options[0])) {
         throw new \Exception('Group ID does not exist: ' . $options[0]);
     }
     $allGroups = $actionParser->getAllGroups($options[0]);
     $revertedActions = 0;
     $this->dbms->beginTransaction();
     try {
         foreach ($allGroups as $group) {
             $actions = $actionParser->parseGroup($group->id);
             $actions = array_reverse($actions);
             $revertedActions += count($actions);
             if ($this->helper->revert($actions)) {
                 $sql = "DELETE FROM dbtrack_data\n                        WHERE actionid IN (SELECT id FROM dbtrack_actions WHERE groupid = :groupid)";
                 $this->dbms->executeQuery($sql, array('groupid' => $group->id));
                 $sql = "DELETE FROM dbtrack_actions WHERE groupid = :groupid";
                 $this->dbms->executeQuery($sql, array('groupid' => $group->id));
             }
         }
         $this->dbms->commitTransaction();
     } catch (\Exception $e) {
         $this->dbms->rollbackTransaction();
         throw new \Exception($e->getMessage(), 0, $e);
     }
     $this->userInteraction->outputMessage($revertedActions . ' action(s) have been reverted.');
     return true;
 }