protected function init() { \GO::$disableModelCache = true; //for less memory usage \GO::setMaxExecutionTime(0); //allow long runs GO::setMemoryLimit(256); ini_set('display_errors', 'on'); }
private function _processExport($data) { \GO::setMaxExecutionTime(0); $className = $data['savedExportModel']->class_name; $class = new $className($data['savedExportModel']->export_columns); // Get the model for this export $this->_model = $class->getModel(); // Translate orientation from horizontal/vertical to landscape/portrait $this->_orientation = $data['savedExportModel']->orientation === 'H' ? 'L' : 'P'; // Retreive the name of the file $this->_title = $class->getName(); // Show the headers in the export (could be 1 instead of true or 0 instead of false) $this->_showHeader = $data['savedExportModel']->include_column_names == true ? true : false; // Use database column names or human readable column names $this->_humanHeaders = $data['savedExportModel']->use_db_column_names == true ? false : true; // Get the findparams for the export $this->_findParams = $class->getFindParams(); // Create the column model $this->_columnModel = $class->getColumnModel(); // Create the store for this export $this->_store = $class->getStore(); }
protected function actionDownload($params) { \GO::session()->closeWriting(); \GO::setMaxExecutionTime(0); if (isset($params['path'])) { $folder = \GO\Files\Model\Folder::model()->findByPath(dirname($params['path'])); $file = $folder->hasFile(\GO\Base\Fs\File::utf8Basename($params['path'])); } else { $file = \GO\Files\Model\File::model()->findByPk($params['id'], false, true); } if (!$file) { throw new \GO\Base\Exception\NotFound(); } if (!empty($params['random_code'])) { if ($file->random_code != $params['random_code']) { throw new \GO\Base\Exception\NotFound(); } if (time() > $file->expire_time) { throw new \Exception(\GO::t('downloadLinkExpired', 'files')); } } else { $public = substr($file->path, 0, 6) == 'public'; if (!$public) { if (!\GO::user()) { \GO\Base\Util\Http::basicAuth(); } if (!$file->checkPermissionLevel(\GO\Base\Model\Acl::READ_PERMISSION)) { throw new \GO\Base\Exception\AccessDenied(); } } } // Show the file inside the browser or give it as a download $inline = true; // Defaults to show inside the browser if (isset($params['inline']) && $params['inline'] == "false") { $inline = false; } \GO\Base\Util\Http::outputDownloadHeaders($file->fsFile, $inline, !empty($params['cache'])); $file->open(); $this->fireEvent('beforedownload', array(&$this, &$params, &$file)); $file->fsFile->output(); }
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'); }
/** * The function that will be called when importing users * * @param array $params * @return array * @throws Exception When the controller cannot be found, an exeption will be thrown */ protected function actionImport($params) { $response = array(); // $params['updateExisting'] = true; $params['updateFindAttributes'] = 'username'; $params['file'] = $_FILES['files']['tmp_name'][0]; \GO::setMaxExecutionTime(0); if ($params['controller'] == 'GO\\Users\\Controller\\UserController') { $controller = new UserController(); } else { throw new \Exception("No or wrong controller given"); } $response = array_merge($response, $controller->run("importCsv", $params, false)); $response['success'] = true; return $response; }
/** * * Defaults to a CSV import. * * Custom fields can be specified in the header with cf\$categoryName\$fieldName * * eg. name,attribute,cf\Test\Textfield * * Command line: * * ./groupoffice biling/order/import --file=/path/to/file.csv --delimiter=, --enclosure=" * * @param array $params */ protected function actionImport($params) { $summarylog = new \GO\Base\Component\SummaryLog(); \GO::$disableModelCache = true; //for less memory usage \GO::setMaxExecutionTime(0); \GO::session()->closeWriting(); //close writing otherwise concurrent requests are blocked. $attributeIndexMap = isset($params['attributeIndexMap']) ? $attributeIndexMap = json_decode($params['attributeIndexMap'], true) : array(); if (is_file($params['file'])) { if (!isset($params['importType'])) { $params['importType'] = 'Csv'; } $fileClassName = 'GO\\Base\\Fs\\' . $params['importType'] . 'File'; if ($params['importType'] == 'Xls' && !empty($params['maxColumnNr'])) { $importFile = new $fileClassName($params['file'], $params['maxColumnNr']); } else { $importFile = new $fileClassName($params['file']); } if (!empty($params['delimiter'])) { $importFile->delimiter = $params['delimiter']; } if (!empty($params['enclosure'])) { $importFile->enclosure = $params['enclosure']; } if (php_sapi_name() == 'cli') { if (!empty($importFile->delimiter)) { echo "Delimiter: " . $importFile->delimiter . "\n"; } if (!empty($importFile->enclosure)) { echo "Enclosure: " . $importFile->enclosure . "\n"; } echo "File: " . $importFile->path() . "\n\n"; } if (!$importFile->convertToUtf8()) { exit("ERROR: Could not convert to UTF8. Is the file writable?\n\n"); } $headers = $importFile->getRecord(); //Map the field headers to the index in the record. //eg. name=>2,user_id=>4, etc. if (empty($attributeIndexMap)) { for ($i = 0, $m = count($headers); $i < $m; $i++) { if (substr($headers[$i], 0, 3) == 'cf\\') { $cf = $this->_resolveCustomField($headers[$i]); if ($cf) { $attributeIndexMap[$i] = $cf; } } else { $attributeIndexMap[$i] = $headers[$i]; } } } while ($record = $importFile->getRecord()) { $attributes = array(); $model = false; foreach ($attributeIndexMap as $index => $attributeName) { if ($index >= 0) { $attributes[trim($attributeName)] = $record[$index]; } } if (!empty($params['updateExisting']) && !empty($params['updateFindAttributes'])) { $findBy = explode(',', $params['updateFindAttributes']); $attr = array(); foreach ($findBy as $attrib) { $attr[$attrib] = $attributes[$attrib]; } $model = \GO::getModel($this->model)->findSingleByAttributes($attr); } if (!$model) { $model = new $this->model(); } // If there are given baseparams to the importer if (isset($params['importBaseParams'])) { $baseParams = json_decode($params['importBaseParams'], true); foreach ($baseParams as $attr => $val) { $attributes[$attr] = $val; } } if ($this->beforeImport($params, $model, $attributes, $record)) { // //Unset some default attributes set in the code // $defaultAttributes = $model->defaultAttributes(); // foreach($defaultAttributes as $column => $value) // unset($model->{$column}); $columns = $model->getColumns(); foreach ($columns as $col => $attr) { if (isset($attributes[$col])) { // if($attr['gotype']=='unixtimestamp' || $attr['gotype']=='unixdate'){ // $attributes[$col]=strtotime($attributes[$col]); // if ($attr['gotype'] == 'number') { $attributes[$col] = preg_replace('/[^.,\\s0-9]+/', '', $attributes[$col]); } } } foreach ($attributes as $name => $value) { $attributes[$name] = trim($value); if (empty($attributes[$name])) { unset($attributes[$name]); } } // True is set because import needs to be checked by the model. $model->setAttributes($attributes, $params['importType'] != 'Xls'); $this->_parseImportDates($model); try { if ($model->save()) { $this->afterImport($model, $attributes, $record); $summarylog->addSuccessful(); } else { $nameStr = !empty($record[0]) ? $record[0] : '"' . \GO::t('namelessItem') . '"'; $summarylog->addError($nameStr, implode("\n", $model->getValidationErrors())); } } catch (\Exception $e) { $summarylog->addError($record[0], $e->getMessage()); } // try{ // $model->save(); // $summarylog->addSuccessful(); // } // catch(\Exception $e){ // $summarylog->addError($record[0], $e->getMessage()); // } // $summarylog->add(); } } } else { //$summarylog->addError('NO FILE FOUND', 'There is no file found that can be imported!'); } return $summarylog; }