Exemple #1
0
 /**
  * Will find all versioning files and put the filesize in the database
  */
 protected function actionRecalculate()
 {
     $fp = FindParams::newInstance()->ignoreAcl();
     $stmt = Version::model()->find($fp);
     $success = 0;
     $failed = 0;
     while ($version = $stmt->fetch()) {
         $path = \GO::config()->file_storage_path . $version->path;
         if (file_exists($path)) {
             $pdo_statement = \GO::$db->query('UPDATE ' . Version::model()->tableName() . ' SET `size_bytes` = ' . filesize($path) . ';');
             if ($pdo_statement->execute()) {
                 $success++;
             } else {
                 $failed++;
             }
         }
     }
     echo $success . ' Done<br> ' . $failed . ' Failed';
 }
Exemple #2
0
 /**
  * Copy current file to the versioning system.
  */
 public function saveVersion()
 {
     $this->fireEvent('saveversion', array($this));
     if (\GO::config()->max_file_versions > -1) {
         $version = new Version();
         $version->file_id = $this->id;
         $version->size_bytes = $this->size;
         $version->save();
     }
 }
Exemple #3
0
 /**
  * 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;
 }