public function installAction() { $this->view->form = $form = new Install_Form_Confirm(array('title' => 'Install Package?', 'description' => 'Are you sure you want to install this package?', 'submitLabel' => 'Install Package', 'cancelHref' => $this->view->url(array('action' => 'index')), 'useToken' => true)); if (!$this->getRequest()->isPost()) { return; } if (!$form->isValid($this->getRequest()->getPost())) { return; } // Do the disable $packageName = $this->_getParam('package'); $package = null; foreach ($this->_packageManager->listInstalledPackages() as $installedPackage) { if ($installedPackage->getKey() == $packageName) { $package = $installedPackage; } } // Enable/disable $operation = new Engine_Package_Manager_Operation_Install($this->_packageManager, $package); $errors = array(); $queryError = false; // Run preinstall $result = $this->_packageManager->execute($operation, 'preinstall'); if (!empty($result['errors'])) { $queryError = true; $errors = array_merge($errors, $result['errors']); } if (isset($queryError) && $queryError) { $this->view->queryError = true; $this->view->errors = $errors; return; } // Run install $result = $this->_packageManager->execute($operation, 'install'); if (!empty($result['errors'])) { $queryError = true; $errors = array_merge($errors, $result['errors']); } if (isset($queryError) && $queryError) { $this->view->queryError = true; $this->view->errors = $errors; return; } // Run postinstall $result = $this->_packageManager->execute($operation, 'postinstall'); if (!empty($result['errors'])) { $queryError = true; $errors = array_merge($errors, $result['errors']); } if (isset($queryError) && $queryError) { $this->view->queryError = true; $this->view->errors = $errors; return; } // Redirect if no error if (!isset($queryError) || !$queryError) { return $this->_helper->redirector->gotoRoute(array('action' => 'index')); } }
public function dbCreateAction() { // Leave if not ready if (empty($this->_session->mysql)) { return $this->_helper->redirector->gotoRoute(array('action' => 'db-info')); } $this->view->code = 0; // Connect again try { $config = $this->dbFormToConfig($this->_session->mysql); // Connect! $adapter = Zend_Db::factory($config['adapter'], $config['params']); $adapter->getServerVersion(); } catch (Exception $e) { $this->view->code = 1; $this->view->error = 'Adapter Error: ' . $e->getMessage(); return; } // attempt to disable strict mode try { $adapter->query("SET SQL_MODE = ''"); } catch (Exception $e) { } // Check if database config already exists $configFile = APPLICATION_PATH . '/application/settings/database.php'; if (file_exists($configFile) && !($this->_getParam('force', 0) >= 1)) { $this->view->code = 2; $this->view->error = 'We found an existing database configuration file. Do you want to overwrite it?'; return; } // Put database.php into place if (!file_exists($configFile) || $this->_getParam('force', 0) >= 1) { $contents = ''; $contents .= '<?php defined(\'_ENGINE\') or die(\'Access Denied\'); '; $contents .= 'return ' . var_export($config, true); $contents .= '; ?>'; if (!@file_put_contents($configFile, $contents) && !($this->_getParam('force', 0) >= 2)) { $this->view->code = 3; $this->view->error = 'Your existing database configuration file is not writeable. Please login to your server via FTP and set full permissions (CHMOD 0777) on /application/settings/database.php, then refresh this page.'; return; } } // Create database shtuff $files = array(APPLICATION_PATH . '/application/modules/Core/settings/my.sql', APPLICATION_PATH . '/application/modules/Activity/settings/my.sql', APPLICATION_PATH . '/application/modules/Authorization/settings/my.sql', APPLICATION_PATH . '/application/modules/User/settings/my.sql', APPLICATION_PATH . '/application/modules/Messages/settings/my.sql', APPLICATION_PATH . '/application/modules/Network/settings/my.sql', APPLICATION_PATH . '/application/modules/Invite/settings/my.sql', APPLICATION_PATH . '/application/modules/Fields/settings/my.sql', APPLICATION_PATH . '/application/modules/Storage/settings/my.sql', APPLICATION_PATH . '/application/modules/Announcement/settings/my.sql', APPLICATION_PATH . '/application/modules/Payment/settings/my.sql'); try { foreach ($files as $file) { $sql = file_get_contents($file); if (!$sql) { throw new Engine_Exception('Unable to read sql file'); } $queries = Engine_Package_Utilities::sqlSplit($sql); foreach ($queries as $query) { $adapter->query($query); } } } catch (Exception $e) { $this->view->error = $e->getMessage(); return; } // Update some other stuff $settingsTable = new Zend_Db_Table(array('db' => $adapter, 'name' => 'engine4_core_settings')); // Generate new secret key $row = $settingsTable->find('core.secret')->current(); if (null === $row) { $row = $settingsTable->createRow(); $row->name = 'core.secret'; } if ($row->value == 'staticSalt' || $row->value == 'NULL' || !$row->value) { $row->value = sha1(time() . php_uname() . dirname(__FILE__) . rand(1000000, 9000000)); $row->save(); } // Save key $row = $settingsTable->find('core.license.key')->current(); if (null === $row) { $row = $settingsTable->createRow(); $row->name = 'core.license.key'; } $row->value = $this->_session->license['key']; $row->save(); // Save stats $row = $settingsTable->find('core.license.statistics')->current(); if (null === $row) { $row = $settingsTable->createRow(); $row->name = 'core.license.statistics'; } $row->value = $this->_session->license['statistics']; $row->save(); // Save email if (!empty($this->_session->license->email)) { $row = $settingsTable->find('core.license.email')->current(); if (null === $row) { $row = $settingsTable->createRow(); $row->name = 'core.license.email'; } if (isset($this->_session->license['email'])) { $row->value = $this->_session->license['email']; } $row->save(); } // Save creation date $row = $settingsTable->find('core.site.creation')->current(); if (null === $row) { $row = $settingsTable->createRow(); $row->name = 'core.site.creation'; } $row->value = date('Y-m-d H:i:s'); $row->save(); // Execute the install hooks $packageManager = new Engine_Package_Manager(array("basePath" => APPLICATION_PATH, "db" => $adapter)); foreach ($packageManager->listInstalledPackages() as $package) { try { $operation = new Engine_Package_Manager_Operation_Install($packageManager, $package); $packageManager->execute($operation, "preinstall"); $packageManager->execute($operation, "install"); $packageManager->execute($operation, "postinstall"); } catch (Exception $e) { $this->view->error = $e->getMessage(); return; } } // Check if branding should be placed $session = $this->_session; $db = $adapter; if (!empty($session->license['key'])) { $license = $session->license['key']; } else { $license = null; // $license = $db->select() // ->from('engine4_core_settings', 'value') // ->where('`name` = ?', 'core.license.key') // ->query() // ->fetchColumn(); } //if( $license ) { // $handle = @fopen("http://www.socialengine.com/remote/branding?license={$license}", "r"); // $doBranding = @stream_get_contents($handle); // @fclose($handle); //} else { $doBranding = false; //} if ($doBranding == 1) { $select = new Zend_Db_Select($db); // profile page $select->from('engine4_core_pages')->where('name = ?', 'footer')->limit(1); $page_id = $select->query()->fetchObject()->page_id; // widget.branding // Check if it's already been placed $select = new Zend_Db_Select($db); $select->from('engine4_core_content')->where('page_id = ?', $page_id)->where('type = ?', 'widget')->where('name = ?', 'branding'); $info = $select->query()->fetch(); if (empty($info)) { // container_id (will always be there) $select = new Zend_Db_Select($db); $select->from('engine4_core_content')->where('page_id = ?', $page_id)->where('type = ?', 'container')->limit(1); $container_id = $select->query()->fetchObject()->content_id; // tab on profile $db->insert('engine4_core_content', array('page_id' => $page_id, 'type' => 'widget', 'name' => 'branding', 'parent_content_id' => $container_id, 'order' => 3, 'params' => '')); } } // Ok we're done $this->view->status = 1; }