Repository URL to install this package:
Version:
0.0.1-0 ▾
|
zendcddemo-apps-gotcms-project
/
zendcddemo-files
/
apps
/
gotcms_project
/
scripts-deploy
/
pre_activate.php
|
---|
<?php
/* The script pre_activate.php should contain code that should make the changes in the server
* environment so that the application is fully functional. For example, this may include
* changing symbolic links to "data" directories from previous to current versions,
* upgrading an existing DB schema, or setting up a "Down for Maintenance"
* message on the live version of the application
* The following environment variables are accessable to the script:
*
* - ZS_RUN_ONCE_NODE - a Boolean flag stating whether the current node is
* flagged to handle "Run Once" actions. In a cluster, this flag will only be set when
* the script is executed on once cluster member, which will allow users to write
* code that is only executed once per cluster for all different hook scripts. One example
* for such code is setting up the database schema or modifying it. In a
* single-server setup, this flag will always be set.
* - ZS_WEBSERVER_TYPE - will contain a code representing the web server type
* ("IIS" or "APACHE")
* - ZS_WEBSERVER_VERSION - will contain the web server version
* - ZS_WEBSERVER_UID - will contain the web server user id
* - ZS_WEBSERVER_GID - will contain the web server user group id
* - ZS_PHP_VERSION - will contain the PHP version Zend Server uses
* - ZS_APPLICATION_BASE_DIR - will contain the directory to which the deployed
* application is staged.
* - ZS_CURRENT_APP_VERSION - will contain the version number of the application
* being installed, as it is specified in the package descriptor file
* - ZS_PREVIOUS_APP_VERSION - will contain the previous version of the application
* being updated, if any. If this is a new installation, this variable will be
* empty. This is useful to detect update scenarios and handle upgrades / downgrades
* in hook scripts
* - ZS_<PARAMNAME> - will contain value of parameter defined in deployment.xml, as specified by
* user during deployment.
*/
//who executes the script
// Rename and symlink direcories to shared folders
//recursive copy function
function recursive_copy($source, $dest) {
foreach (
$iterator = new RecursiveIteratorIterator(
new RecursiveDirectoryIterator($source, RecursiveDirectoryIterator::SKIP_DOTS), RecursiveIteratorIterator::SELF_FIRST) as $item
)
{
if ($item->isDir()) {
if(!is_dir($dest . DIRECTORY_SEPARATOR . $iterator->getSubPathName())) {
echo "Creating dir: ".$dest . DIRECTORY_SEPARATOR . $iterator->getSubPathName()."\n";
mkdir($dest . DIRECTORY_SEPARATOR . $iterator->getSubPathName());
}
} else {
if(!is_file($dest . DIRECTORY_SEPARATOR . $iterator->getSubPathName())) {
echo "Copying file: ".$dest . DIRECTORY_SEPARATOR . $iterator->getSubPathName()."\n";
copy($item, $dest . DIRECTORY_SEPARATOR . $iterator->getSubPathName());
}
}
}
}
function share_folders($baseDir, $sharedFolder, $fromDir) {
//rename the dir to dir.bak
$srcDir = rtrim(realpath($baseDir.'/'.$fromDir), '/');
echo "BaseDir: $baseDir\n";
echo "FromDir: $fromDir\n";
echo "realpath src: $srcDir\n";
$origDir = $baseDir.'/'.$fromDir;
$bakDir = "$srcDir.bak-".date('ddmmyyHis');
//ensure target exists in shared
$targetDir = $sharedFolder.'/'.$fromDir;
if(!is_dir($targetDir)) {
echo "Creating dir: $targetDir\n";
if(!mkdir($targetDir, 0755, true)) {
echo "Failed creating target dir $targetDir\n";
}
}
//copy all resources
recursive_copy($srcDir, $targetDir);
//Symlink
if(is_link($origDir)){
echo "Unlinking existing link: $origDir\n";
unlink($origDir);
} elseif(is_dir($origDir)) {
echo "Moving $origDir to $bakDir\n";
rename($origDir, $bakDir);
}
echo "Symlinking $origDir to $targetDir\n";
symlink($targetDir, $origDir);
}
$baseDir = getenv('ZS_APPLICATION_BASE_DIR');
$sharedBaseDir = getenv('ZS_SHARED_DIR');
share_folders($baseDir, $sharedBaseDir, 'public/frontend');
share_folders($baseDir, $sharedBaseDir, 'module/Development/views/layout');
share_folders($baseDir, $sharedBaseDir, 'module/Development/views/view');
share_folders($baseDir, $sharedBaseDir, 'module/Development/views/script');
share_folders($baseDir, $sharedBaseDir, 'public/media');
echo "Done sharing folders.\n";
exit(0);