/** * The code that needs to be called when the cron is running * * @param GO\Base\Cron\CronJob $cronJob * @param GO\Base\Model\User $user */ public function run(GO\Base\Cron\CronJob $cronJob, GO\Base\Model\User $user = null) { $filesStmt = File::model()->find(FindParams::newInstance()->ignoreAcl()->criteria(FindCriteria::newInstance()->addCondition('expire_time', time(), '<')->addCondition('expire_time', '0', '>')->addCondition('random_code', '', '!=')->addCondition('delete_when_expired', '1'))); foreach ($filesStmt as $fileModel) { $fileModel->delete(); } }
public function formatRawOutput($key, &$attributes, \GO\Customfields\Model\AbstractCustomFieldsRecord $model) { $column = $model->getColumn($key); if (!$column) { return null; } $fieldId = $column['customfield']->id; $findParams = \GO\Base\Db\FindParams::newInstance()->ignoreAcl()->order('mf.order')->joinModel(array('model' => 'GO\\Site\\Model\\MultifileFile', 'localTableAlias' => 't', 'localField' => 'id', 'foreignField' => 'file_id', 'tableAlias' => 'mf'))->criteria(\GO\Base\Db\FindCriteria::newInstance()->addCondition('model_id', $model->model_id, '=', 'mf')->addCondition('field_id', $fieldId, '=', 'mf')); return \GO\Files\Model\File::model()->find($findParams, 'false', true); }
public function formatDisplay($key, &$attributes, \GO\Customfields\Model\AbstractCustomFieldsRecord $model) { $html = ""; if (!empty($attributes[$key])) { $file = \GO\Files\Model\File::model()->findByPath($attributes[$key]); if ($file) { if (!\GO\Customfields\Model\AbstractCustomFieldsRecord::$formatForExport) { $html = '<a href="#" onclick="GO.linkHandlers[\'GO\\Files\\Model\\File\'].call(this,\'' . $attributes[$key] . '\');">' . basename($attributes[$key]) . '</a>' . '<a href="#" onclick=\'' . $file->getDefaultHandler()->getHandler($file) . '\' style="display:block;float: right;" class="go-icon btn-edit"> </a>'; //$html='<a href="#" title="'.$attributes[$key].'">'.$attributes[$key].'</a>'; } else { $html = $attributes[$key]; } } } return $html; }
public function actionRecent($params) { $start = !empty($params['start']) ? $params['start'] : 0; $limit = !empty($params['limit']) ? $params['limit'] : 20; $store = \GO\Base\Data\Store::newInstance(\GO\Files\Model\File::model()); $store->getColumnModel()->formatColumn('path', '$model->path', array(), array('first_name', 'last_name')); $store->getColumnModel()->formatColumn('weekday', '$fullDays[date("w", $model->mtime)]." ".\\GO\\Base\\Util\\Date::get_timestamp($model->mtime, false);', array('fullDays' => \GO::t('full_days')), array('first_name', 'last_name')); $store->setStatement(\GO\Files\Model\File::model()->findRecent($start, $limit)); $response = $store->getData(); $store->setStatement(\GO\Files\Model\File::model()->findRecent()); $response['total'] = $store->getTotal(); return $response; }
public static function checkFolderTrigger(&$self, &$response, &$model, &$params, $modifiedAttributes) { $trigger = Model\Trigger::model()->findSingleByAttributes(array('model_type_id' => \GO\Files\Model\File::model()->modelTypeId(), 'model_attribute' => 'folder_id', 'model_attribute_value' => $model->id)); if (!empty($params['wf_process_id'])) { if (!$trigger) { \GO::debug('NO EXISTING TRIGGER FOUND, CREATE NEW TRIGGER'); $trigger = new Model\Trigger(); $trigger->model_type_id = \GO\Files\Model\File::model()->modelTypeId(); $trigger->model_attribute = 'folder_id'; $trigger->model_attribute_value = $model->id; } $trigger->process_id = $params['wf_process_id']; $trigger->save(); } elseif ($trigger) { $trigger->delete(); } }
/** * Download an attachment from the current ticket/message * The file will be outputted to the broser with downloadheaders * * @throws \GO\Base\Exception\AccessDenied */ protected function actionDownloadAttachment() { // Find the cuttent ticket $ticket = \GO\Tickets\Model\Ticket::model()->findSingleByAttributes(array('ticket_number' => $_GET['ticket_number'], 'ticket_verifier' => $_GET['ticket_verifier'])); // Throw an AccessDenied exception when the ticket is not found if (!$ticket) { throw new \GO\Base\Exception\AccessDenied(); } // Get the file from the GET['file'] parameter. $file = \GO\Files\Model\File::model()->findSingleByAttributes(array('id' => $_GET['file'], 'folder_id' => $ticket->files_folder_id)); // If the file is found then output it to the browser if ($file) { $fsFile = $file->fsFile; \GO\Base\Util\Http::outputDownloadHeaders($fsFile, false); $fsFile->output(); } }
protected function actionSave($id) { // throw new \GO\Base\Exception\AccessDenied(); $file = \GO\Files\Model\File::model()->findByPk($id); if (!$file) { throw new \GO\Base\Exception\NotFound(); } if (empty($_FILES)) { throw new Exception("Server did not recieve a file. Perhaps the file was too large?"); } $upfile = array_shift($_FILES); if (empty($upfile['tmp_name'])) { throw new Exception("Server did not recieve a file. Perhaps the file was too large?"); } $file->replace(new \GO\Base\Fs\File($upfile['tmp_name']), false); //GOTA java program will check for the following string. Anything else will //be treated as an error. // echo 'SUCCESS'; $response['success'] = true; return $response; }
/** * Delete the current file * * @return void */ public function delete() { $this->checkWritePermission(true); $file = \GO\Files\Model\File::model()->findByPath($this->relpath); $file->delete(); }
protected function actionEditinglist() { $empty_editing = true; if ($list = \GO::session()->values['googledrive']['editing']) { if (!count(\GO::session()->values['googledrive']['editing']) < 1) { $empty_editing = false; } } if (!$empty_editing) { $list = \GO::session()->values['googledrive']['editing']; $response['success'] = true; $response['values'] = []; $response['names'] = []; foreach ($list as $k => $v) { $goFile = \GO\Files\Model\File::model()->findByPk($k); array_push($response['values'], $k); array_push($response['names'], $goFile->name); } } else { throw new Exception("No hay archivos abiertos"); $response['success'] = false; } return $response; }
public static function initListeners() { \GO\Files\Model\File::model()->addListener('save', 'GO\\Filesearch\\FilesearchModule', 'save'); \GO\Files\Model\File::model()->addListener('delete', 'GO\\Filesearch\\FilesearchModule', 'delete'); }
public function start(\GO\Base\Model\User $user = null, $reset = false) { if ($user === null) { $user = GO::user(); } GO::session()->runAsRoot(); GO::setMaxExecutionTime(0); self::log("Dropbox sync for user " . $user->username); $dbxUser = User::model()->findByPk($user->id); if ($reset) { $dbxUser->delta_cursor = ""; $folder = self::getHomeFolder($user); $folder->removeChildren(); } $dbxClient = self::getClient($user); self::log("Getting Dropbox Changes"); $hasMore = true; while ($hasMore) { $delta = $dbxClient->Delta(empty($dbxUser->delta_cursor) ? null : $dbxUser->delta_cursor); // var_dump($delta); // exit(); if (!isset($delta)) { throw new \Exception("Could not get delta from Dropbox!"); } $hasMore = $delta->has_more; foreach ($delta->entries as $entry) { flush(); //$entry[1]['path'] = with case. Otherwise we just have a string to lowered path for deleting $dbxPath = isset($entry[1]->path) ? $entry[1]->path : $entry[0]; $goPath = self::dbxToGoPath($dbxPath, $user); if (!isset($entry[1])) { //should be deleted $file = File::model()->findByPath($goPath, false); if ($file) { self::log("Deleting file on Group-Office " . $goPath); $file->delete(); } else { $folder = Folder::model()->findByPath($goPath, false, array(), false); if ($folder) { self::log("Deleting folder on Group-Office " . $goPath); $folder->delete(); } else { self::log("Could not find path for delete file on Group-Office " . $goPath); } } } else { if ($entry[1]->is_dir) { self::log("Create folder on Group-Office " . $entry[1]->path . " -> " . $goPath); $folder = Folder::model()->findByPath($goPath, true); } else { self::log("Download from Dropbox " . $entry[1]->path . " -> " . $goPath); $folder = Folder::model()->findByPath(dirname($goPath), true, array(), false); $name = \GO\Base\Fs\File::utf8Basename($goPath); $path = $folder->fsFolder->createChild($name)->path(); //$f = fopen($path, "w+b"); $fileMetadata = $dbxClient->DownloadFile($entry[0], $path); //fclose($f); touch($path, strtotime($fileMetadata->modified)); //todo needs optimize $folder->syncFilesystem(); } } } } $dbxUser->delta_cursor = $delta->cursor; $dbxUser->save(); self::log("Applying Group-Office changes to Dropbox"); $folder = self::getHomeFolder($user); $goSnapshot = self::getGroupOfficeSnapShot($folder); $dbxSnapshot = self::getDropboxSnapshot($user); foreach ($goSnapshot as $path => $props) { $dbxPath = self::goToDbxPath($props['path'], $user); $dbxPathToLower = strtolower($dbxPath); if (!isset($dbxSnapshot[$dbxPathToLower]) || $dbxSnapshot[$dbxPathToLower]['mtime'] < $props['mtime']) { if (is_file(GO::config()->file_storage_path . $props['path'])) { self::log("Upload to Dropbox " . $path . " -> " . $dbxPath); $localPath = GO::config()->file_storage_path . $props['path']; $meta = $dbxClient->UploadFile($localPath, $dbxPath, true); if (!isset($meta)) { throw new \Exception("Failed to create file '" . $dbxPath . "' on Dropbox"); } } elseif (!isset($dbxSnapshot[$dbxPathToLower])) { self::log("Create folder on Dropbox " . $path . " -> " . $dbxPath); $folderMetaData = $dbxClient->CreateFolder($dbxPath); if (!isset($folderMetaData)) { throw new \Exception("Failed to create folder '" . $dbxPath . "' on Dropbox"); } } } } //reverse sort for deleting so that deeper files are deleted first. krsort($dbxSnapshot); foreach ($dbxSnapshot as $path => $props) { $goPath = strtolower(self::dbxToGoPath($path, $user)); if (!isset($goSnapshot[$goPath])) { self::log("Deleting on dropbox " . $path); if (!$dbxClient->Delete($path)) { throw new \Exception("Failed to delete '" . $path . "'"); } } } //get delta again so we won't process our own changes next sync $delta = $dbxClient->Delta($dbxUser->delta_cursor); $dbxUser->delta_cursor = $delta->cursor; $dbxUser->save(); self::log("Done!"); }
protected function actionImages($params) { if (isset($params["id"])) { $currentFile = \GO\Files\Model\File::model()->findByPk($params["id"]); } else { $currentFile = \GO\Files\Model\File::model()->findByPath($params["path"]); } $folder = $currentFile->folder(); $thumbParams = json_decode($params['thumbParams'], true); $response["success"] = true; $response['images'] = array(); $response['index'] = $index = 0; if (!isset($params["sort"])) { $params["sort"] = "name"; } if (!isset($params["dir"])) { $params["dir"] = "ASC"; } $findParams = \GO\Base\Db\FindParams::newInstance()->order($params["sort"], $params["dir"]); $stmt = $folder->files($findParams); while ($file = $stmt->fetch()) { if ($file->isImage()) { if ($file->id == $currentFile->id) { $response['index'] = $index; } $index++; $response['images'][] = array("name" => $file->name, "download_path" => $file->downloadUrl, "src" => $file->getThumbUrl($thumbParams)); } } return $response; }
/** * This method will (re)calculate the used diskspace for this user * @param integer $bytes The amount of bytes to add to the users used diskspace (negative for substraction) * @return User itself for chaining eg. $user->calculatedDiskUsage()->save() */ public function calculatedDiskUsage($bytes = false) { if (GO::modules()->isInstalled('files')) { if (!$bytes) { //recalculated $fp = \GO\Base\Db\FindParams::newInstance()->select('SUM(size) as total_size')->joinModel(array('model' => 'GO\\Files\\Model\\Folder', 'localTableAlias' => 't', 'localField' => 'folder_id', 'tableAlias' => 'd'))->criteria(\GO\Base\Db\FindCriteria::newInstance()->addCondition('quota_user_id', $this->id, '=', 'd')); $sumFilesize = \GO\Files\Model\File::model()->findSingle($fp); $fpVer = \GO\Base\Db\FindParams::newInstance()->select('SUM(size_bytes) as total_size')->joinModel(array('model' => 'GO\\Files\\Model\\File', 'localTableAlias' => 't', 'localField' => 'file_id', 'tableAlias' => 'f'))->joinModel(array('model' => 'GO\\Files\\Model\\Folder', 'localTableAlias' => 'f', 'localField' => 'folder_id', 'tableAlias' => 'd'))->criteria(\GO\Base\Db\FindCriteria::newInstance()->addCondition('quota_user_id', $this->id, '=', 'd')); $sumVersionsize = \GO\Files\Model\Version::model()->findSingle($fpVer); //GO::debug($sumFilesize->total_size); if ($sumFilesize) { $this->disk_usage = $sumFilesize->total_size + $sumVersionsize->total_size; } } else { $this->disk_usage += $bytes; } } else { throw new \Exceptions('Can not calculated diskusage without the files module'); } return $this; }
/** * Check if this folder has files. * * @return boolean */ public function hasFileChildren() { $file = File::model()->findSingleByAttribute('folder_id', $this->id); return $file != false; }