public function onBeforeFileAction(MOXMAN_Core_FileActionEventArgs $args) { switch ($args->getAction()) { case MOXMAN_Core_FileActionEventArgs::COPY: case MOXMAN_Core_FileActionEventArgs::ADD: if (!isset($args->getData()->thumb)) { if (MOXMAN_Core_FileActionEventArgs::ADD) { $file = $args->getFile(); } else { $file = $args->getTargetFile(); } $parentFile = $file->getParentFile(); // If not set, probably a folder? if (isset($args->getData()->fileSize)) { $fileSize = $args->getData()->fileSize; } else { $fileSize = 0; } // Recalculate quota after uploading a new file $dirs = MOXMAN::getUserStorage()->get("quota.dirs", new stdClass()); $this->recalcQuota($parentFile, $dirs); MOXMAN::getUserStorage()->put("quota.dirs", $dirs); $quotaSize = $this->parseSize($file->getConfig()->get("quota.size", "-1")); // Check if size of the root directory exceeds the configured max size $rootFile = $file->getFileSystem()->getRootFile(); if (isset($dirs->{$rootFile->getPublicPath()}) && $dirs->{$rootFile->getPublicPath()}->dsize + $fileSize > $quotaSize) { throw new MOXMAN_Exception("Quota exceeded when adding file: " . $file->getPublicPath() . " (" . $this->formatSize($dirs->{$rootFile->getPublicPath()}->dsize + $fileSize) . " > " . $this->formatSize($quotaSize) . ")."); } } break; } }
public function onBeforeFileAction(MOXMAN_Core_FileActionEventArgs $args) { switch ($args->getAction()) { case MOXMAN_Core_FileActionEventArgs::ADD: $args->setFile($this->renameFile($args->getFile())); break; case MOXMAN_Core_FileActionEventArgs::MOVE: $args->setTargetFile($this->renameFile($args->getTargetFile())); break; } }