Last active
August 29, 2015 14:04
-
-
Save kingharrison/1e3951d53d13129a3687 to your computer and use it in GitHub Desktop.
Sample post_activate.php script that pulls user variables from install and writes out local confit files for ZF2 in a ZPK on Zend Server running on the IBM i
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
* This is the instasll script used to setup environmental variables when first installing K3S | |
*/ | |
/* | |
* This loads variables from the deployment script. All variables added as parameters are accessable as ZS_<PARAMETER_NAME> | |
*/ | |
$appLocation = getenv ( "ZS_APPLICATION_BASE_DIR" ); | |
if (! $appLocation) { | |
echo ("ZS_APPLICATION_BASE_DIR env var undefined"); | |
exit ( 1 ); | |
} | |
$dbHost = getenv ( "ZS_DB_HOST" ); | |
if (! $dbHost) { | |
echo ("ZS_DB_HOST env var undefined"); | |
exit ( 1 ); | |
} | |
$dbPassword = getenv ( "ZS_DB_PASSWORD" ); | |
if (! $dbPassword) { | |
echo ("ZS_DB_PASSWORD env var undefined"); | |
exit ( 1 ); | |
} | |
$dbUsername = getenv ( "ZS_DB_USERNAME" ); | |
if (! $dbUsername) { | |
echo ("ZS_DB_NAME env var undefined"); | |
exit ( 1 ); | |
} | |
$dbPrefix = getenv ( "ZS_DB_PREFIX" ); | |
if (! $dbPrefix) { | |
echo ("ZS_DB_PREFIX env var undefined"); | |
exit ( 1 ); | |
} | |
$programCalc = getenv ( "ZS_PROGRAM_CALC" ); | |
if (! $programCalc) { | |
echo ("ZS_PROGRAM_CALC env var undefined"); | |
exit ( 1 ); | |
} | |
$sessionLength = getenv ( "ZS_SESSION_LENGTH" ); | |
if (! $sessionLength) { | |
echo ("ZS_SESSION_LENGTH env var undefined"); | |
exit ( 1 ); | |
} | |
/* | |
* This loads the location of the files to be generated. | |
*/ | |
$db_file = $appLocation . "/config/autoload/db.local.php"; | |
$k3s_file = $appLocation . "/config/autoload/k3sbase.local.php"; | |
/* | |
* This section writes the db.local.php file to access the databse. On deployment this file is created and written. | |
*/ | |
$open_file = fopen ( $db_file, "w" ); | |
fwrite ( $open_file, "<?php \n" ); | |
fwrite ( $open_file, "/* \n" ); | |
fwrite ( $open_file, " * Here is all the local database information. I have contained it all in db.local.php to \n" ); | |
fwrite ( $open_file, "* ensure we can run on any type of machien and database. \n" ); | |
fwrite ( $open_file, "*/ \n" ); | |
fwrite ( $open_file, "return array ( \n" ); | |
fwrite ( $open_file, " 'db' => array ( \n" ); | |
fwrite ( $open_file, " 'driver' => 'IbmDb2', \n" ); | |
fwrite ( $open_file, " 'db' => '" . $dbHost . "', \n" ); | |
fwrite ( $open_file, " 'persistent' => true, \n" ); | |
fwrite ( $open_file, " 'username' => '" . $dbUsername . "', \n" ); | |
fwrite ( $open_file, " 'password' => '" . $dbPassword . "', \n" ); | |
fwrite ( $open_file, " 'driver_options' => array ( \n" ); | |
fwrite ( $open_file, " 'i5_naming' => DB2_I5_NAMING_ON, \n" ); | |
fwrite ( $open_file, " 'i5_libl' => '" . $dbPrefix . "_5DTA " . $dbPrefix . "_5OBJ " . $dbPrefix . "_5MOD " . $dbPrefix . "_5ZEND' \n" ); | |
fwrite ( $open_file, " ) \n" ); | |
fwrite ( $open_file, " ) \n" ); | |
fwrite ( $open_file, "); \n" ); | |
/* | |
* This section writes the k3sbase.local.php file for K3S-Replenish specific variables. | |
*/ | |
$open_file = fopen ( $k3s_file, "w" ); | |
fwrite ( $open_file, "<?php \n" ); | |
fwrite ( $open_file, "/* Here is all the local database information. I have contained it all in db.local.php to \n" ); | |
fwrite ( $open_file, " * ensure we can run on any type of machine and database. \n" ); | |
fwrite ( $open_file, "* \n" ); | |
fwrite ( $open_file, "*/ \n" ); | |
fwrite ( $open_file, "return array ( \n" ); | |
fwrite ( $open_file, " 'k3s_settings' => array ( \n" ); | |
fwrite ( $open_file, " 'session_length' => '" . $sessionLength . "', \n" ); | |
fwrite ( $open_file, " 'calculate_programs' => '" . $programCalc . "', \n" ); | |
fwrite ( $open_file, " ) \n" ); | |
fwrite ( $open_file, "); \n" ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment