function write_setting($data)
 {
     global $CFG;
     /// TODO: Need code here that will move the current Moodle directory structure to the new location.
     if (empty($data)) {
         $data = $this->get_defaultsetting();
     }
     /// Validate the path, if we can.
     if ($repo = repository_factory::factory('alfresco')) {
         if ($repo->is_configured() && $repo->verify_setup()) {
             if (alfresco_validate_path($data)) {
                 //                    $newuuid = alfresco_uuid_from_path($data);
                 $newuuid = $repo->get_uuid_from_path($data);
                 if ($newuuid != $repo->muuid && !alfresco_root_move($repo->muuid, $newuuid)) {
                     return get_string('couldnotmoveroot', 'repository_alfresco');
                 } else {
                     return parent::write_setting($data);
                 }
             } else {
                 return get_string('invalidpath', 'repository_alfresco');
             }
         }
     }
     /// If the repository is not configured correctly, we just have to assume the
     /// path is valid as we can't connect to verify.
     return parent::write_setting($data);
 }
Ejemplo n.º 2
0
/**
 * Recursively determine whether the specified path is actually valid on the
 * configured repository.
 *
 * @param string $path
 * @return bool True if the path is valid, False otherwise.
 */
function alfresco_validate_path($path, $folders = null)
{
    if ($path == '/') {
        return true;
    }
    /// Remove any extraneous slashes from the ends of the string
    $path = trim($path, '/');
    $parts = explode('/', $path);
    /// Initialize the folder structure if a structure piece wasn't passed to this function.
    if ($folders == null) {
        $folders = alfresco_folder_structure();
    }
    /// Get the first piece from the list of path elements.
    $pathpiece = array_shift($parts);
    if (!empty($folders)) {
        foreach ($folders as $folder) {
            if ($folder['name'] == $pathpiece) {
                /// If there are no more path elements, we've succeeded!
                if (empty($parts)) {
                    return true;
                    /// If there are path elements left but no children from the current
                    /// folder, we've failed.
                } else {
                    if (!empty($parts) && empty($folder['children'])) {
                        return false;
                        /// Otherwise, keep looking below.
                    } else {
                        return alfresco_validate_path(implode('/', $parts), $folder['children']);
                    }
                }
            }
        }
    }
    return false;
}