/**
  * Removes file from FS attached to instance
  *
  * @param $instance core_kernel_classes_Resource
  */
 public static function removeAttachedFile(core_kernel_classes_Resource $instance)
 {
     if (!is_null($instance)) {
         $contentUri = $instance->getOnePropertyValue(new core_kernel_classes_Property(BookletClassService::PROPERTY_FILE_CONTENT));
         if ($contentUri instanceof core_kernel_classes_Resource) {
             $file = new core_kernel_versioning_File($contentUri);
             $file->delete();
         }
     }
     \core_kernel_fileSystem_Cache::flushCache();
 }
 /**
  * creates a new FileSystem
  *
  * @access public
  * @author Jerome Bogaerts, <*****@*****.**>
  * @param  Resource type
  * @param  string url
  * @param  string login
  * @param  string password
  * @param  string path
  * @param  string label
  * @param  boolean enabled
  * @return core_kernel_versioning_Repository
  */
 public static function createFileSystem(core_kernel_classes_Resource $type, $url, $login, $password, $path, $label, $enabled = false)
 {
     $path = rtrim($path, "\\/") . DIRECTORY_SEPARATOR;
     if (!file_exists($path)) {
         if (!mkdir($path, 0700, true)) {
             throw new common_exception_Error("Could not create path '" . $path . "' for filesystem '" . $label . "'");
         }
     }
     $versioningRepositoryClass = new core_kernel_classes_Class(CLASS_GENERIS_VERSIONEDREPOSITORY);
     $resource = $versioningRepositoryClass->createInstanceWithProperties(array(RDFS_LABEL => $label, PROPERTY_GENERIS_VERSIONEDREPOSITORY_URL => $url, PROPERTY_GENERIS_VERSIONEDREPOSITORY_PATH => $path, PROPERTY_GENERIS_VERSIONEDREPOSITORY_TYPE => $type, PROPERTY_GENERIS_VERSIONEDREPOSITORY_LOGIN => $login, PROPERTY_GENERIS_VERSIONEDREPOSITORY_PASSWORD => $password, PROPERTY_GENERIS_VERSIONEDREPOSITORY_ENABLED => $enabled ? GENERIS_TRUE : GENERIS_FALSE));
     core_kernel_fileSystem_Cache::flushCache();
     return new core_kernel_fileSystem_FileSystem($resource);
 }
Beispiel #3
0
 /**
  * Short description of method disable
  *
  * @access public
  * @author Jerome Bogaerts, <*****@*****.**>
  * @return boolean
  */
 public function disable()
 {
     $returnValue = (bool) false;
     $classVersionedFiles = new core_kernel_classes_Class(CLASS_GENERIS_FILE);
     $files = $classVersionedFiles->searchInstances(array(PROPERTY_FILE_FILESYSTEM => $this), array('like' => false));
     $rootFile = $this->getRootFile();
     $used = false;
     foreach ($files as $file) {
         if (is_null($rootFile) || $file->getUri() != $rootFile->getUri()) {
             $used = true;
             break;
         }
     }
     if (!$used) {
         $this->editPropertyValues(new core_kernel_classes_Property(PROPERTY_GENERIS_VERSIONEDREPOSITORY_ENABLED), GENERIS_FALSE);
         common_Logger::i("The remote versioning repository " . $this->getUri() . " has been disabled");
         $returnValue = true;
         core_kernel_fileSystem_Cache::flushCache();
     } else {
         common_Logger::w("The remote versioning repository " . $this->getUri() . " could not be disabled, because it is in use by " . $file->getUri());
     }
     return (bool) $returnValue;
 }
Beispiel #4
0
 public static function flushCache()
 {
     common_cache_FileCache::singleton()->remove(self::SERIAL);
     self::$cache = array();
 }
 /**
  * render the repository form
  * @return void
  */
 public function editRepository()
 {
     //$myFormContainer = new tao_actions_form_Versioning();
     $clazz = $this->getCurrentClass();
     $repo = $this->getCurrentInstance();
     $myFormContainer = new tao_actions_form_Repository($clazz, $repo);
     $myForm = $myFormContainer->getForm();
     if ($myForm->isSubmited()) {
         if ($myForm->isValid()) {
             $oldState = $repo->getPropertyValues(new core_kernel_classes_Property(PROPERTY_GENERIS_VERSIONEDREPOSITORY_ENABLED));
             $oldState = count($oldState) == 1 ? current($oldState) : GENERIS_FALSE;
             $values = $myForm->getValues();
             $newState = $values[PROPERTY_GENERIS_VERSIONEDREPOSITORY_ENABLED];
             if ($oldState == GENERIS_TRUE && $newState != GENERIS_FALSE) {
                 throw new common_Exception('Cannot change an active Repository');
             }
             $values = $myForm->getValues();
             if (isset($values[PROPERTY_GENERIS_VERSIONEDREPOSITORY_ENABLED])) {
                 unset($values[PROPERTY_GENERIS_VERSIONEDREPOSITORY_ENABLED]);
             }
             // save properties
             $binder = new tao_models_classes_dataBinding_GenerisFormDataBinder($repo);
             $repo = $binder->bind($values);
             $message = __('Repository saved');
             core_kernel_fileSystem_Cache::flushCache();
             // check if enable/disable necessary
             if ($newState == GENERIS_TRUE && $oldState != GENERIS_TRUE) {
                 // enable the repository
                 $success = $repo->enable();
                 $message = $success ? __('Repository saved and enabled') : __('Repository saved, but unable to enable');
             } elseif ($newState != GENERIS_TRUE && $oldState == GENERIS_TRUE) {
                 // disable the repository
                 $success = $repo->disable();
                 $message = $success ? __('Repository saved and disabled') : __('Repository saved, but unable to disable');
             }
             $this->setData('message', $message);
             $this->setData('reload', true);
         }
     }
     $this->setData('formTitle', __('Revision control'));
     $this->setData('myForm', $myForm->render());
     $this->setView('form.tpl', 'tao');
 }