RENAME_FAILED
RENAME_FAILED
Return code constants for public VersionManager methods
VersionManager can be used to create and manage versions of files in a folder so that a user can revert the files to any version desired back to the time the folder under manager was first managed. It is used by Yioop's Wiki system to handle versions of image and other media resources for a Wiki page.
__construct(string $managed_folder = '.', string $archive_name = '.archive', string $hash_algorithm = 'sha256', integer $permissions = 511)
Creates an object which can be used to manage multiple versions of files in a managed folder, storing prior version in an archive folder using a hash_algorithm to determine how to name these archived files and saving these archived files according to some file system permissions.
string | $managed_folder | what folder should be managed with this versioning system |
string | $archive_name | file_name in the folder to use for the subfolder containing the archived versions of files |
string | $hash_algorithm | what hash algorithm should be used to generate archive filenames. Defaults to sha256 |
integer | $permissions | what to set the file permissions to for the archive file. To keep things simple this defaults to world read write. In practice you probably want to tailor this to the situation for security. If you set the value to <= 0 the permissions will be whatever your OS would use by default |
createVersion(string $file_changed = "", string $folder = "", integer $now, boolean $lock = true, array $force_update_list = array()) : mixed
If $file_changed is not a subpath of $folder then only the $folder file is involved in new version. I.e., a single repository dir file for folder will be made. If $file_changed is a nonexistent file in $folder then the dir's in path to $file_changed will be updated.
string | $file_changed | |
string | $folder | |
integer | $now | |
boolean | $lock | whether or not a lock should be obtained before carrying out the operation |
array | $force_update_list |
either an error code or the name of the hash_file in the repository for the version just created
headGetContents(string $file, boolean $lock = true) : integer
Read from the head version of the repository the contents of $file.
string | $file | name of file to get contents of |
boolean | $lock | whether or not a lock should be obtained before carrying out the operation |
success code
headPutContents(string $file, string $data, boolean $lock = true) : integer
Write $data into the file $file in the head version of the repository
string | $file | name of file to store data for |
string | $data | what to store in the file $file |
boolean | $lock | whether or not a lock should be obtained before carrying out the operation |
success code
headCopy(string $from_name, string $to_name, boolean $lock = true) : integer
Copies the data in a file $from_name in the head version of the repository to a different file named $to_name
string | $from_name | name of file or dir to copy |
string | $to_name | name of file or dir to save copy to |
boolean | $lock | whether or not a lock should be obtained before carrying out the operation |
success code
headMakeDirectory(string $dir, boolean $lock = true) : integer
Makes a directory named $dir in the current folder in the head version of the repository being managed
string | $dir | name of directory folder to make |
boolean | $lock | whether or not a lock should be obtained before carrying out the operation |
success code
headRename(string $old_name, string $new_name, boolean $lock = true) : integer
Renames the file $old_name in the head version of the repository to a different file named $new_name
string | $old_name | original name of file |
string | $new_name | what to change it to |
boolean | $lock | whether or not a lock should be obtained before carrying out the operation |
success code
headInfo(boolean $lock = true) : mixed
Returns the files in the root directory in the most recent version of the repository together with a TIMESTAMP of the date when the most recent version was made.
boolean | $lock | whether or not a lock should be obtained before carrying out the operation |
either any array [TIMESTAMP => time of last version, FILES => files in last version's folder] or LOCK_FAIL error code
versionGetContents(string $file, integer $timestamp, boolean $get_nearest_version = false, boolean $lock = true) : mixed
Retrieves the contents of a file from a particular version of the repository
string | $file | name of file to get data about |
integer | $timestamp | which version want to get file out of |
boolean | $get_nearest_version | if true then if $timestamp doesn't exist as a version get the nearest version after $timestamp |
boolean | $lock | whether or not a lock should be obtained before carrying out the operation |
either a string with the file's data or an error code
restoreVersion(integer $timestamp, boolean $lock = true, boolean $force_lock = false) : integer
Restores the version of the repository that existed at a timestamp to the managed folder. Files currently in the managed folder before the restored but which exist in the HEAD version of the repository are removed from the managed folder (kept in repository).
integer | $timestamp | of version what to restore to |
boolean | $lock | whether or not a lock should be obtained before carrying out the operation |
boolean | $force_lock | whether or not any existing lock should be ignored |
success code
getActiveVersion(integer $search_timestamp, boolean $lock = true)
Gets the most recent version timestamp of a version in the repository that is less than or equal to the searched for timestamp.
integer | $search_timestamp | want to find the version in the repository closest to, but not exceeding this value. |
boolean | $lock | whether or not a lock should be obtained before carrying out the operation |
getVersionsInRange(integer $start_time, integer $end_time, boolean $lock = true)
Gets all the versions times that exist in the repository and which are between in time two values.
integer | $start_time | look for timestamps in repository above or equal this value |
integer | $end_time | look for timestamps in repository below or equal this value |
boolean | $lock | whether or not a lock should be obtained before carrying out the operation |
getArchivePathHashName(string $hash_name) : string
Get the path in the repository archive that corresponds to the given hash name of an object that might be in the repository.
Currently, the archive consists of two nested folders based on prefixes of objects stored in the repository, so this method calculates those prefixes and tacks them on to the archive path.
string | $hash_name | to make a archive path for |
path to $hash_name object in repository archive
getArchiveFileAndPath(string $file, integer $timestamp, boolean $make_path = false) : array
Gets the hash file name and path within the archive repository for a file name from the managed folder that existed at timestamp
string | $file | name of file want to get the archive name and archive path for |
integer | $timestamp | of version want to compute archive filename and path for |
boolean | $make_path | whether to make folders (if they don't exists already) in the archive repository for the path calculated |
[hash_name, archive_path] to use for file in the repository for object given that version timestamp
getVersionPath(integer $timestamp, boolean $make_path = false) : string
Versions are stored in the version subfolder of the archive repository within a year folder within a day folder. Given a timestamp this function returns the path of the version folder it would correspond to
integer | $timestamp | to find version folder for |
boolean | $make_path | whether to make folders (if they don't exists already) in the archive repository for the path calculated |
path to version folder
getHashNamePath(string $file, integer $timestamp, boolean $get_nearest_version = false, string $path_so_far = "", string $hash_path_so_far = "") : string
Given a file or directory and a timestamp finds the path to that file in the repository by tranversing the repository and looking the hash names of folders subfolders in the repository.
The timestamp that is lookedup might not be the timestamp of the file because when created a version that file might not have changed so its old info is copied into the new version. This is why a traversal might be needed.
string | $file | name of file to get path for |
integer | $timestamp | which version in repository want to get file for |
boolean | $get_nearest_version | if true then if $timestamp doesn't exist as a version get the nearest version after $timestamp |
string | $path_so_far | path in managed folder that this recursive procedure has already traversed |
string | $hash_path_so_far | corresponding path to path_so_far but in the archive repository |
path to file in the archive repository
copyFromVersionOrHashName(string $file, string $target, integer $timestamp, string $hash_name_type = "", boolean $lock = true)
Copies to the target folder in the managed folder a file or directory that existed at a given timestamp in the archive repository
string | $file | file name of file or direcotry to copy to managed folder |
string | $target | folder to copy to |
integer | $timestamp | which archive version of the file to copy |
string | $hash_name_type | either f, l, or d depending on whether the object in the repository is known to be a file, link, or folder. If left empty then this is looked up in the repository |
boolean | $lock | whether or not a lock should be obtained before carrying out the operation |
traverseUnlinkHead(string $dir, integer $timestamp)
Recursively traverse a directory structure and call a callback function
string | $dir | name of folder to delete |
integer | $timestamp | only deletes if the file existed in the version given by the timestamp in the repository (by default this is the timestamp asscoaited with the HEAD version) |
deleteVersionFileOrFolder(string $file_or_dir, integer $timestamp)
This function is used in the process of recursively deleting a directory
string | $file_or_dir | the filename or directory name to be deleted |
integer | $timestamp | only deletes if the file existed in the version given by the timestamp in the repository |