/**
  *
  * @service export_file delete
  * @param Gpf_Rpc_Params $params
  * @return Gpf_Rpc_Action
  */
 public function deleteFiles(Gpf_Rpc_Params $params)
 {
     $action = new Gpf_Rpc_Action($params);
     $action->setInfoMessage($this->_("File(s) %s was successfully deleted"));
     $action->setErrorMessage($this->_("Could not delete %s file(s)"));
     foreach ($action->getIds() as $id) {
         try {
             $export = new Gpf_Db_Export();
             $export->setPrimaryKeyValue($id);
             $export->load();
             $fileName = $export->getFileName();
             $export->delete();
         } catch (Exception $e) {
             $action->addError();
             continue;
         }
         $filePath = Gpf_Paths::getInstance()->getAccountDirectoryPath() . Gpf_Csv_ImportExportService::EXPORT_DIRECTORY . $fileName;
         $file = new Gpf_Io_File($filePath);
         if ($file->isExists()) {
             if ($file->delete()) {
                 $action->addOk();
             } else {
                 $action->addError();
             }
         } else {
             $action->addOk();
         }
     }
     return $action;
 }
    /**
     * @service theme write
     */
    public function revertFile(Gpf_Rpc_Params $params) {
        $action = new Gpf_Rpc_Action($params);
        try{
            $themeId = $action->getParam('themeId');
            $itemId = $action->getParam("Id");
            $themeBase = $this->getThemeFile($action->getParam('panelName'));

            $file_original = new Gpf_Io_File($themeBase.'/'.Gpf_Paths::DEFAULT_THEME.$itemId);
            $file_new = new Gpf_Io_File($themeBase.'/'.$themeId.$itemId);

            if($file_original->isExists() && $file_new->isExists()){
                if(!$file_new->delete()){
                    throw new Gpf_Exception(_("Revert of file has failed"));
                }else{
                    $action->setInfoMessage(_("Revert of file success"));
                }
            }else{
                $action->setInfoMessage(_("This file cannot be reverted"));
            }
            $action->addOk();
        }catch (Gpf_Exception $e){
            $action->addError();
            $action->setErrorMessage($e->getMessage());
        }
        return $action;
    }
Example #3
0
    protected function saveUploadedFile() {
        
        $file = new Gpf_Db_File();
        $file->set('filename', $this->name);
        $file->set('filesize', $this->size);
        $file->set('filetype', $this->type);
        $file->save();
             
        $dir = new Gpf_Io_File($this->getZipFolderUrl().$file->getFileId().'/');
        if ($dir->isExists()) {
            $dir->delete();
        }
        $dir->mkdir();
        $tmpZip = new Gpf_Io_File($this->getZipFolderUrl().$file->getFileId().'/'.$file->getFileId().".zip");
        $dir->copy(new Gpf_Io_File($this->tmpName),$tmpZip);
        
        $archive = new PclZip($this->getZipFolderUrl().$file->getFileId().'/'.$file->getFileId().".zip");
        $err = $archive->extract($this->getZipFolderUrl().$file->getFileId().'/');
        if ($err <= 0) {
            throw new Gpf_Exception("code: ".$err);
        }

        $tmpZip->delete();
 
        return $file;
    }
 private function clearTempDirectory($path)
 {
     foreach (new Gpf_Io_DirectoryIterator($path) as $fullFileName => $file) {
         $file = new Gpf_Io_File($fullFileName);
         $file->delete();
     }
 }
 private function deleteFiles($directory)
 {
     foreach (new Gpf_Io_DirectoryIterator($directory, '', true, false) as $fullFileName => $fileName) {
         $file = new Gpf_Io_File($fullFileName);
         $file->delete();
         $this->checkInterruption();
     }
 }
Example #6
0
 public static function clear(){
     $session = Gpf_Session::getInstance();
     $data =  $session->getVar(self::SESSION_VAR);
     if(!$data) return;
     $uploadFile = new Gpf_Io_File($data->getFile());
     $uploadFile->delete();
     $session->setVar(self::SESSION_VAR, null);
 }
Example #7
0
 public function execute() {
     $dir = new Gpf_Io_DirectoryIterator(Gpf_Paths::getInstance()->getAccountsPath(), '', true);
     foreach ($dir as $fullPath => $filename) {
     	if ($filename == 'engineconfig.php') {
     	    $file = new Gpf_Io_File($fullPath);
     	    $file->delete();
     	}
     }
 }
Example #8
0
 /**
  * Delete uploaded file from database or files directory
  *
  * @service uploaded_file delete
  * @param Gpf_Rpc_Params $params
  * @return Gpf_Rpc_Action
  */
 public function deleteFile(Gpf_Rpc_Params $params)
 {
     $action = new Gpf_Rpc_Action($params);
     if ($action->existsParam('fileid') && $action->getParam('fileid') != '') {
         $dbRow = new Gpf_Db_File();
         $dbRow->setFileId($action->getParam('fileid'));
         try {
             $dbRow->load();
         } catch (Gpf_DbEngine_NoRow $e) {
             throw new Exception($this->_("Failed to delete file. File doesn't exist in database."));
         }
         try {
             $dbRow->delete();
         } catch (Gpf_Exception $e) {
             $action->addError();
             $action->setErrorMessage($this->_('Failed to delete file from database.'));
             return $action;
         }
     } else {
         $fileUrl = $action->getParam('fileurl');
         $fileName = substr($fileUrl, strrpos($fileUrl, '/') + 1);
         $file = new Gpf_Io_File(Gpf_Paths::getInstance()->getAccountDirectoryPath() . Gpf_Paths::FILES_DIRECTORY . $fileName);
         if (!$file->delete()) {
             $action->addError();
             $action->setErrorMessage($this->_('Failed to delete file.'));
         }
     }
     $action->addOk();
     return $action;
 }
Example #9
0
 public function delete()
 {
     $this->file->delete();
 }
 private function checkAccountsWritable()
 {
     $requirement = new Gpf_Install_Requirement();
     $requirement->setPositiveName($this->_('Configuration directory is writable'));
     $requirement->setNegativeName($this->_('Configuration directory has to be writable'));
     $accountDirectory = Gpf_Paths::getInstance()->getAccountsPath();
     $result = @is_dir($accountDirectory) && is_writable($accountDirectory);
     if ($result) {
         $this->deleteIfExistsTestFilesAndDir($accountDirectory);
         $testFile = new Gpf_Io_File($accountDirectory . 'check');
         $subTestFile = new Gpf_Io_File($accountDirectory . 'check/subcheck');
         try {
             $testFile->open('w');
             $testFile->close();
             $testFile->delete();
         } catch (Exception $e) {
             $result = false;
             $requirement->setNegativeName($this->_('Could not create file inside %s directory', $accountDirectory));
         }
         try {
             $testFile->mkdir();
             $testFile->rmdir();
         } catch (Exception $e) {
             $result = false;
             $requirement->setNegativeName($this->_('Could not create directory inside %s directory', $accountDirectory));
         }
         try {
             $testFile->mkdir();
             $subTestFile->open('w');
             $subTestFile->close();
             $subTestFile->delete();
             $subTestFile->mkdir();
             $subTestFile->rmdir();
             $testFile->rmdir();
         } catch (Exception $e) {
             $result = false;
             $requirement->setNegativeName($this->_('Could not create file or directory inside %s subdirectory. Probably safe mode is not properly configured.', $accountDirectory));
         }
     }
     $requirement->setResult($result);
     $description = $this->_('Please make directory %s and all subdirectories writable by webserver.', $accountDirectory);
     if (stripos(PHP_OS, 'win') === false) {
         $description .= $this->_('On unix-like systems you can type "chmod -R 777 %s".', $accountDirectory);
     }
     $description .= $this->_('On any system you can set write permissions using your favourite FTP client.');
     $requirement->setFixDescription($description);
     $this->addRequirement($requirement);
 }
Example #11
0
 private function deleteCacheFileFromDirectory($directory, $fileName)
 {
     foreach (new Gpf_Io_DirectoryIterator($directory, '', false, false) as $fullName => $name) {
         if (strripos($name, '%%' . $this->encodeFileName($fileName))) {
             $fileToDelete = new Gpf_Io_File($fullName);
             $fileToDelete->delete();
             break;
         }
     }
 }
 /**
  * On deactivate remove manifest file
  */
 public function onDeactivate() {
     try {
         $file = new Gpf_Io_File(Gpf_Paths::getInstance()->getAccountConfigDirectoryPath() . self::getManifestFileName());
         $file->delete();
     } catch (Exception $e) {
     }
 }
Example #13
0
 public function cleanSavedFile(){
     if($this->isSaved()){
         $this->load();
         $file = new Gpf_Io_File($this->getData1());
         $file->delete();
     }
 }
 private function removeTemplateCache()
 {
     $accountDirectory = $this->getAccountDirectory();
     $cacheTemplates = $accountDirectory->getFileName() . Gpf_Paths::CACHE_DIRECTORY . Gpf_Templates_Smarty::COMPILED_TEMPLATES_DIR;
     foreach (new Gpf_Io_DirectoryIterator($cacheTemplates, '', true) as $fullName => $file) {
         $this->checkInterruption();
         $file = new Gpf_Io_File($fullName);
         $file->delete();
     }
 }
Example #15
0
 /**
  * Delete csv file from account directory
  */
 private function deleteLanguageFilesFromAccount()
 {
     //delete csv file from account
     $fileName = Gpf_Lang_CsvLanguage::getAccountCsvFileName($this->getCode());
     $file = new Gpf_Io_File($fileName);
     if ($file->isExists()) {
         $file->delete();
     }
     //TODO delete also cache language files from account
 }
 /**
  * @service template write
  * @param $fields
  * @return Gpf_Rpc_Action
  */
 public function deleteFile(Gpf_Rpc_Params $params)
 {
     $action = new Gpf_Rpc_Action($params);
     $templateName = $this->fixTemplateName($action->getParam("templatename"));
     $panelName = '';
     if ($action->existsParam("panelname")) {
         $panelName = $action->getParam("panelname");
     }
     if ($action->existsParam("theme") && $action->getParam("theme") != null && $action->getParam("theme") != "") {
         $theme = $action->getParam("theme");
         if ($theme == trim(Gpf_Paths::DEFAULT_THEME, '/')) {
             $action->setErrorMessage($this->_("Common template can not be deleted"));
             $action->addError();
             return $action;
         }
     } else {
         throw new Gpf_Exception("Theme not set");
     }
     $paths = Gpf_Paths::getInstance()->clonePaths($theme);
     $templateFile = new Gpf_Io_File($paths->getTemplatePath($templateName, $panelName));
     if ($templateFile->delete()) {
         $action->setInfoMessage($this->_("File deleted"));
         $action->addOk();
         return $action;
     }
     $action->setErrorMessage($this->_("File can not be deleted"));
     $action->addError();
     return $action;
 }