Example #1
0
 public function __construct($prefixString = '')
 {
     if (!\GO::modules()->isInstalled('files')) {
         throw new \Exception('The current action requires the files module to be activated for the current user.');
     }
     // Make sure the current user's folder exists.
     $userFolderModel = \GO\Files\Model\Folder::model()->findHomeFolder(\GO::user());
     if (empty($userFolderModel)) {
         $userFolder = new \GO\Base\Fs\Folder(\GO::config()->file_storage_path . 'users/' . \GO::user()->username);
         $userFolder->create();
         $userFolderModel = new \GO\Files\Model\Folder();
         $userFolderModel->findByPath('users/' . \GO::user()->username, true);
     }
     parent::__construct(\GO::config()->file_storage_path . $userFolderModel->path . '/' . $prefixString . \GO\Base\Util\Date::get_timestamp(time(), true) . '.log');
 }
Example #2
0
 public function actionRemoveDuplicates($params)
 {
     \GO::setMaxExecutionTime(300);
     \GO::setMemoryLimit(1024);
     $this->render('externalHeader');
     $tasklist = \GO\Tasks\Model\Tasklist::model()->findByPk($params['tasklist_id']);
     if (!$tasklist) {
         throw new \GO\Base\Exception\NotFound();
     }
     \GO\Base\Fs\File::setAllowDeletes(false);
     //VERY IMPORTANT:
     \GO\Files\Model\Folder::$deleteInDatabaseOnly = true;
     \GO::session()->closeWriting();
     //close writing otherwise concurrent requests are blocked.
     $checkModels = array("GO\\Tasks\\Model\\Task" => array('name', 'start_time', 'due_time', 'rrule', 'user_id', 'tasklist_id'));
     foreach ($checkModels as $modelName => $checkFields) {
         if (empty($params['model']) || $modelName == $params['model']) {
             echo '<h1>' . \GO::t('removeDuplicates') . '</h1>';
             $checkFieldsStr = 't.' . implode(', t.', $checkFields);
             $findParams = \GO\Base\Db\FindParams::newInstance()->ignoreAcl()->select('t.id, count(*) AS n, ' . $checkFieldsStr)->group($checkFields)->having('n>1');
             $findParams->getCriteria()->addCondition('tasklist_id', $tasklist->id);
             $stmt1 = \GO::getModel($modelName)->find($findParams);
             echo '<table border="1">';
             echo '<tr><td>ID</th><th>' . implode('</th><th>', $checkFields) . '</th></tr>';
             $count = 0;
             while ($dupModel = $stmt1->fetch()) {
                 $select = 't.id';
                 if (\GO::getModel($modelName)->hasFiles()) {
                     $select .= ', t.files_folder_id';
                 }
                 $findParams = \GO\Base\Db\FindParams::newInstance()->ignoreAcl()->select($select . ', ' . $checkFieldsStr)->order('id', 'ASC');
                 $findParams->getCriteria()->addCondition('tasklist_id', $tasklist->id);
                 foreach ($checkFields as $field) {
                     $findParams->getCriteria()->addCondition($field, $dupModel->getAttribute($field));
                 }
                 $stmt = \GO::getModel($modelName)->find($findParams);
                 $first = true;
                 while ($model = $stmt->fetch()) {
                     echo '<tr><td>';
                     if (!$first) {
                         echo '<span style="color:red">';
                     }
                     echo $model->id;
                     if (!$first) {
                         echo '</span>';
                     }
                     echo '</th>';
                     foreach ($checkFields as $field) {
                         echo '<td>' . $model->getAttribute($field, 'html') . '</td>';
                     }
                     echo '</tr>';
                     if (!$first) {
                         if (!empty($params['delete'])) {
                             if ($model->hasLinks() && $model->countLinks()) {
                                 echo '<tr><td colspan="99">' . \GO::t('skippedDeleteHasLinks') . '</td></tr>';
                             } elseif (($filesFolder = $model->getFilesFolder(false)) && ($filesFolder->hasFileChildren() || $filesFolder->hasFolderChildren())) {
                                 echo '<tr><td colspan="99">' . \GO::t('skippedDeleteHasFiles') . '</td></tr>';
                             } else {
                                 $model->delete();
                             }
                         }
                         $count++;
                     }
                     $first = false;
                 }
             }
             echo '</table>';
             echo '<p>' . sprintf(\GO::t('foundDuplicates'), $count) . '</p>';
             echo '<br /><br /><a href="' . \GO::url('tasks/tasklist/removeDuplicates', array('delete' => true, 'tasklist_id' => $tasklist->id)) . '">' . \GO::t('clickToDeleteDuplicates') . '</a>';
         }
     }
     $this->render('externalFooter');
 }