public function init() { $this->addElementPrefixPath('Shineisp_Decorator', 'Shineisp/Decorator/', 'decorator'); $this->addElement('select', 'locale', array('decorators' => array('Bootstrap'), 'label' => 'Language', 'class' => 'form-control', 'multioptions' => Languages::getLanguageFiles(PUBLIC_PATH . "/languages"))); $this->addElement('textarea', 'agreement', array('filters' => array('StringTrim'), 'decorators' => array('Bootstrap'), 'class' => 'form-control', 'label' => 'Agreements', 'rows' => '10', 'value' => Shineisp_Commons_Utilities::readfile(PUBLIC_PATH . "/../LICENSE"))); $this->addElement('select', 'chkagreement', array('decorators' => array('Bootstrap'), 'label' => 'I agree with the legal terms', 'class' => 'form-control', 'multioptions' => array(1 => 'YES, I agree with the legal terms', 0 => 'NO, I disagree with these legal terms'))); $this->addElement('submit', 'submit', array('label' => 'Continue', 'decorators' => array('Bootstrap'), 'class' => 'btn btn-primary btn-lg')); }
/** * Load of the configuration file * @return SimpleXMLElement */ public static function loadConfig() { $confFile = APPLICATION_PATH . "/configs/config.xml"; try { if (file_exists($confFile) && is_readable($confFile)) { $config = Shineisp_Commons_Utilities::readfile($confFile); if (!empty($config)) { $config = new Zend_Config_Xml($confFile); if (simplexml_load_file($confFile)) { Shineisp_Registry::set('config', $config); return simplexml_load_file($confFile); } else { throw new Exception("XML Config file is not readable or not well-formed"); } } } } catch (Exception $e) { echo $e->getMessage(); echo "<xmp>"; echo $e->getTraceAsString(); echo "</xmp>"; exit; } }
/** * (non-PHPdoc) * @see Zend_Controller_Plugin_Abstract::preDispatch() */ public function preDispatch(Zend_Controller_Request_Abstract $request) { $dayssincefirstsetup = 0; $migration = new Doctrine_Migration(APPLICATION_PATH . '/configs/migrations'); $LatestVersion = $migration->getLatestVersion(); $CurrentVersion = $migration->getCurrentVersion(); try { // Check if the config file has been created $isReady = Shineisp_Main::isReady(); if ($isReady) { // Execute the migration if ($CurrentVersion < $LatestVersion) { // write a log message Shineisp_Commons_Utilities::log("Upgrade: Current Version is {$CurrentVersion} and the latest available version is {$LatestVersion}"); $dbconfig = Shineisp_Main::databaseConfig(); // Update the version in the config.xml file previously created Settings::saveConfig($dbconfig, $LatestVersion); if ($CurrentVersion > 0) { Shineisp_Commons_Utilities::log("Upgrade: Migrate ShineISP version from {$CurrentVersion} to {$LatestVersion}"); $migration->migrate(); } } $db = Doctrine_Manager::getInstance()->getCurrentConnection(); // Read and execute all the sql files saved in the /application/configs/data/sql directory $path = PROJECT_PATH . "/application/configs/data/sql"; if (is_dir($path)) { $directory_iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path)); try { // get the first setup date $setupdate = Settings::getConfigSetupDate(); if (empty($setupdate)) { throw new Exception('Setup date is not set in the config.xml file'); } // for each sql file do ... foreach ($directory_iterator as $filename => $path_object) { // get the sql file information $info = pathinfo($filename); if (!empty($info['extension']) && $info['extension'] == "sql") { $name = $info['filename']; // get the first part of the name with the filename that contains the date: YYYYMMddHis-NAME.sql $arrName = explode("-", $name); // if the string is a valid date get the days betweeen the sql file name and the day of the setup of shineisp if (!empty($arrName[0]) && Zend_Date::isdate($arrName[0], 'YYYYMMddHis')) { $sqldate = new Zend_Date($arrName[0], 'YYYYMMddHis'); $mysetupdate = new Zend_Date($setupdate, 'YYYYMMddHis'); // get the difference of the two dates $diff = $sqldate->sub($mysetupdate)->toValue(); $dayssincefirstsetup = floor($diff / 60 / 60 / 24); unset($sqldate); unset($mysetupdate); } // SQL files post installation will be executed if ($dayssincefirstsetup >= 0) { // read the sql $sql = Shineisp_Commons_Utilities::readfile($info['dirname'] . "/" . $info['basename']); if (!empty($sql)) { // execute the sql strings $result = $db->execute($sql); // close the db connection $db->close(); if ($result) { // write a log message Shineisp_Commons_Utilities::log($info['filename'] . ".sql has been executed."); // rename the sql rename($info['dirname'] . "/" . $info['basename'], $info['dirname'] . "/" . $info['filename'] . ".sql.old"); } } } else { // rename the sql rename($info['dirname'] . "/" . $info['basename'], $info['dirname'] . "/" . $info['filename'] . ".sql.old"); // write a log message Shineisp_Commons_Utilities::log($info['filename'] . ".sql has been skipped because already set in the doctrine data setup."); } } } } catch (Exception $e) { die($e->getMessage()); } } } // Execute the migration if ($CurrentVersion < $LatestVersion) { $dbconfig = Shineisp_Main::databaseConfig(); // Update the version in the config.xml file previously created Settings::saveConfig($dbconfig, $LatestVersion); if ($CurrentVersion > 0) { $migration->migrate(); } } } catch (Exception $e) { Zend_Debug::dump($e->getMessage()); die; } }