server = ezcWebdavServer::getInstance(); $this->backend = $backend; } /** * Purges all outdated locks under $path. * * This method analyses all locks under $path and purges the locks which * have not been accessed for the timeout configured in the lock property. * * @param string $path * @return void * * @throws ezcWebdavLockPurgerException * in case an error occurs during the lock purge process. Error * might occur if the user identified by $adminCredentials does not * have the appropriate permissions to write resources or if the * backend is inconsistent. */ public function purgeLocks( $path = '/' ) { $this->prepareEnvironment(); try { $purger = new ezcWebdavLockPurger( $this->backend ); $purger->purgeLocks( $path ); } catch ( ezcWebdavException $e ) { $this->restoreEnvironment(); throw $e; } $this->restoreEnvironment(); } /** * Prepares the server for administrative operations. * * Removes any configured auth mechanism in the server and stores it for * later restoring. Registers the lock plugin, if it is not registered, * yet. Locks the backend. */ private function prepareEnvironment() { if ( $this->server->auth !== null ) { $this->serverAuth = $this->server->auth; $this->server->auth = null; } $lockConf = null; if ( !$this->server->pluginRegistry->hasPlugin( ezcWebdavLockPlugin::PLUGIN_NAMESPACE ) ) { $lockConf = new ezcWebdavLockPluginConfiguration(); $this->server->pluginRegistry->registerPlugin( $lockConf ); $this->serverHadLockPlugin = false; } else { $lockConf = $this->server->pluginRegistry->getPluginConfig( ezcWebdavLockPlugin::PLUGIN_NAMESPACE ); $this->serverHadLockPlugin = true; } $this->backend->lock( $lockConf->options->backendLockWaitTime, $lockConf->options->backendLockTimeout ); } /** * Restores the original server settings. * * Restores the original server auth (if it was set) and removes the lock * plugin again, if it was not set before. Unlocks the backend. */ private function restoreEnvironment() { $this->backend->unlock(); if ( $this->serverAuth !== null ) { $this->server->auth = $this->serverAuth; } if ( !$this->serverHadLockPlugin ) { $this->server->pluginRegistry->unregisterPlugin( new ezcWebdavLockPluginConfiguration() ); } $this->serverAuth = null; $this->serverHadLockPlugin = null; } } ?>