PHP Class DNDataArchive

The model can also represent a request to upload a file later, through offline processes like mailing a DVD. In order to associate and authenticate those requests easily, an upload token is generated for every archive. The "OriginalEnvironment" points to original source of this snapshot (the one it was backed up from). It will be empty if the snapshot has been created with offline process. The "Environment" denotes the ownership of the snapshot. It will be initially set to match the "OriginalEnvironment", but can be changed later. During the offline process the ownership can be set up arbitrarily. When moving snapshots, the file always remains in its initial location. The archive can have associations to {@link DNDataTransfer}: - Zero transfers if a manual upload was requested, but not fulfilled yet - One transfer with Direction=get for a backup from an environment - One or more transfers with Direction=push for a restore to an environment The "Author" is either the person creating the archive through a "backup" operation, the person uploading through a web form, or the person requesting a manual upload. The "Mode" is what the "Author" said the file includes (either 'only assets', 'only database', or both). This is used in the ArchiveList.ss template.
Inheritance: extends DataObject
Show file Open project: silverstripe/deploynaut Class Usage Examples

Public Methods

Method Description
FileSize ( ) : string Calculates and returns a human-readable size of this archive file. If the file exists, it will determine whether to display the output in bytes, kilobytes, megabytes, or gigabytes.
attachFile ( string $sspakFilepath, DNDataTransfer $dataTransfer ) : boolean Attach an sspak file path to this archive and associate the transfer.
canDelete ( Member | null $member = null ) : boolean Whether a {@link Member} can delete this archive from staging area.
canDownload ( Member | null $member = null ) : true Whether a {@link Member} can download this archive to their PC.
canMoveTo ( DNEnvironment $targetEnv, Member | null $member = null ) : boolean Check if this member can move archive into the environment.
canRestore ( Member | null $member = null ) : true Whether a {@link Member} can restore this archive to an environment.
canView ( Member | null $member = null ) Inferred from both restore and backup permissions.
extractArchive ( string | null $workingDir = null ) : boolean Extract the current sspak contents into the given working directory.
fixArchivePermissions ( string | null $workingDir ) : boolean Given a path that already exists and contains an extracted sspak, including the assets, fix all of the file permissions so they're in a state ready to be pushed to remote servers.
generateFilename ( DNDataTransfer $dataTransfer ) : string Returns a unique filename, including project/environment/timestamp details.
generateFilepath ( DNDataTransfer $dataTransfer ) : string Returns a path unique to a specific transfer, including project/environment details.
generate_upload_token ( $chars = 8 ) : string Returns a unique token to correlate an offline item (posted DVD) with a specific archive placeholder.
getCMSFields ( )
getDefaultSearchContext ( )
getModeNice ( )
get_mode_map ( )
isPending ( ) : boolean Some archives don't have files attached to them yet, because a file has been posted offline and is waiting to be uploaded against this "archive placeholder".
onAfterDelete ( )
onBeforeWrite ( )
setArchiveFromFiles ( string | null $workingDir ) : boolean Given extracted sspak contents, create an sspak from it and overwrite the current ArchiveFile with it's contents.
validTargetEnvironments ( ) : ArrayList Finds all environments within this project where the archive can be moved to.
validateArchiveContents ( string | null $mode = null ) : ValidationResult Validate that an sspak contains the correct content.

Method Details

FileSize() public method

Calculates and returns a human-readable size of this archive file. If the file exists, it will determine whether to display the output in bytes, kilobytes, megabytes, or gigabytes.
public FileSize ( ) : string
return string The human-readable size of this archive file

attachFile() public method

Does the job of creating a {@link File} record, and setting correct paths into the assets directory.
public attachFile ( string $sspakFilepath, DNDataTransfer $dataTransfer ) : boolean
$sspakFilepath string
$dataTransfer DNDataTransfer
return boolean

canDelete() public method

Whether a {@link Member} can delete this archive from staging area.
public canDelete ( Member | null $member = null ) : boolean
$member Member | null The {@link Member} object to test against.
return boolean if $member (or the currently logged in member if null) can delete this archive

canDownload() public method

This only needs to be checked *once* per member and environment.
public canDownload ( Member | null $member = null ) : true
$member Member | null The {@link Member} object to test against.
return true if $member (or the currently logged in member if null) can download this archive

canMoveTo() public method

Check if this member can move archive into the environment.
public canMoveTo ( DNEnvironment $targetEnv, Member | null $member = null ) : boolean
$targetEnv DNEnvironment Environment to check.
$member Member | null The {@link Member} object to test against. If null, uses Member::currentMember();
return boolean true if $member can upload archives linked to this environment, false if they can't.

canRestore() public method

This only needs to be checked *once* per member and environment.
public canRestore ( Member | null $member = null ) : true
$member Member | null The {@link Member} object to test against.
return true if $member (or the currently logged in member if null) can upload this archive

canView() public method

Inferred from both restore and backup permissions.
public canView ( Member | null $member = null )
$member Member | null The {@link Member} object to test against.

extractArchive() public method

This also extracts the assets and database and puts them into /database.sql and /assets, respectively.
public extractArchive ( string | null $workingDir = null ) : boolean
$workingDir string | null The path to extract to
return boolean

fixArchivePermissions() public method

Normally, command line tar will use permissions found in the archive, but will substract the user's umask from them. This has a potential to create unreadable files, e.g. cygwin on Windows will pack files with mode 000, hence why this fix is necessary.
public fixArchivePermissions ( string | null $workingDir ) : boolean
$workingDir string | null The path of where the sspak has been extracted to
return boolean

generateFilename() public method

Returns a unique filename, including project/environment/timestamp details.
public generateFilename ( DNDataTransfer $dataTransfer ) : string
$dataTransfer DNDataTransfer
return string

generateFilepath() public method

Does not create the path on the filesystem. Can be used to store files related to this transfer.
public generateFilepath ( DNDataTransfer $dataTransfer ) : string
$dataTransfer DNDataTransfer
return string Absolute file path

generate_upload_token() public static method

Returns a unique token to correlate an offline item (posted DVD) with a specific archive placeholder.
public static generate_upload_token ( $chars = 8 ) : string
return string

getCMSFields() public method

public getCMSFields ( )

getDefaultSearchContext() public method

getModeNice() public method

public getModeNice ( )

get_mode_map() public static method

public static get_mode_map ( )

isPending() public method

Some archives don't have files attached to them yet, because a file has been posted offline and is waiting to be uploaded against this "archive placeholder".
public isPending ( ) : boolean
return boolean

onAfterDelete() public method

public onAfterDelete ( )

onBeforeWrite() public method

public onBeforeWrite ( )

setArchiveFromFiles() public method

Use GZIP=-1 for less compression on assets, which are already heavily compressed to begin with.
public setArchiveFromFiles ( string | null $workingDir ) : boolean
$workingDir string | null The path of where the sspak has been extracted to
return boolean

validTargetEnvironments() public method

Excludes current environment automatically.
public validTargetEnvironments ( ) : ArrayList
return ArrayList List of valid environments.

validateArchiveContents() public method

For example, if the user uploaded an sspak containing just the db, but declared in the form that it contained db+assets, then the archive is not valid.
public validateArchiveContents ( string | null $mode = null ) : ValidationResult
$mode string | null "db", "assets", or "all". This is the content we're checking for. Default to the archive setting
return ValidationResult