protected function _runCustomQueries()
 {
     $i = 0;
     // Hack to add 4.0.0rc1 -> 4.0.0rc2 during 4.0.0rc2 -> 4.0.0
     $db = $this->getDb();
     $data = $db->query('SELECT * FROM `engine4_core_menuitems` WHERE `name` = \'authorization_admin_main_manage\'')->fetch();
     if (empty($data) || empty($data['name'])) {
         $contents = file_get_contents(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'my-upgrade-4.0.0rc1-4.0.0rc2.sql');
         foreach (Engine_Package_Utilities::sqlSplit($contents) as $sqlFragment) {
             //try {
             $db->query($sqlFragment);
             $i++;
             //} catch( Exception $e ) {
             //  return $this->_error('Query failed with error: ' . $e->getMessage());
             //}
         }
     }
     return $i;
 }
示例#2
0
文件: install.php 项目: robeendey/ce
 protected function _runCustomQueries()
 {
     $i = 0;
     // Hack to add 4.0.0rc1 -> 4.0.0rc2 during 4.0.0rc2 -> 4.0.0
     $db = $this->getDb();
     $cols = $db->query('SHOW COLUMNS FROM `engine4_core_tasks` LIKE \'success_last\'')->fetch();
     if (empty($cols) || empty($cols['Field'])) {
         $contents = file_get_contents(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'my-upgrade-4.0.0rc1-4.0.0rc2.sql');
         foreach (Engine_Package_Utilities::sqlSplit($contents) as $sqlFragment) {
             //try {
             $db->query($sqlFragment);
             $i++;
             //} catch( Exception $e ) {
             //  return $this->_error('Query failed with error: ' . $e->getMessage());
             //}
         }
     }
     return $i;
 }
示例#3
0
 public function restoreAction()
 {
     // Require
     require_once 'PEAR.php';
     require_once 'Archive/Tar.php';
     // Param
     $backup = $this->_getParam('backup');
     // Verify backup
     $archiveFilename = $this->_outputPath . DIRECTORY_SEPARATOR . $backup;
     if ('' == $backup || !is_file($archiveFilename)) {
         return $this->_helper->redirector->gotoRoute(array('action' => 'index'));
     }
     // Check for vfs instance
     if (!$this->_vfs instanceof Engine_Vfs_Adapter_Abstract) {
         $this->_session->return = $_SERVER['REQUEST_URI'];
         return $this->_helper->redirector->gotoRoute(array('controller' => 'vfs', 'action' => 'index'));
     }
     // Check for database instance
     if (!($db = Zend_Registry::get('Zend_Db')) instanceof Zend_Db_Adapter_Abstract) {
         throw new Engine_Exception('No database instance');
     }
     // Confirm/Options
     $this->view->form = $form = new Install_Form_Backup_Restore();
     if (!$this->getRequest()->isPost()) {
         return;
     }
     if (!$form->isValid($this->getRequest()->getPost())) {
         return;
     }
     // !!IMPORTANT!!
     set_time_limit(0);
     ignore_user_abort(true);
     // Errors
     $errors = array();
     // Make temporary folder
     $archiveOutputPath = substr($archiveFilename, 0, strrpos($archiveFilename, '.'));
     if (is_dir($archiveOutputPath)) {
         Engine_Package_Utilities::fsRmdirRecursive($archiveOutputPath, true);
     }
     if (!mkdir($archiveOutputPath, 0777, true)) {
         throw new Engine_Exception(sprintf('Unable to make path %s', $archiveOutputPath));
     }
     // Extract
     $archive = new Archive_Tar($archiveFilename);
     $archive->extract($archiveOutputPath);
     // Upload
     $path = APPLICATION_PATH;
     $it = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path), RecursiveIteratorIterator::SELF_FIRST);
     foreach ($it as $file) {
         $fullPath = $file->getPathname();
         $partialPath = ltrim(str_replace($path, '', $fullPath), '/\\');
         if (is_dir($fullPath)) {
             try {
                 $this->_vfs->makeDirectory($directory, true);
             } catch (Exception $e) {
                 $errors[] = $e->__toString();
             }
         } else {
             try {
                 $this->_vfs->put($partialPath, $fullPath);
             } catch (Exception $e) {
                 $errors[] = $e->__toString();
             }
         }
     }
     // Database
     //$db = new Zend_Db_Adapter_Mysqli();
     $queries = Engine_Package_Utilities::sqlSplit(file_get_contents($archiveOutputPath . '/database.sql'));
     foreach ($queries as $query) {
         try {
             $db->query($query);
         } catch (Exception $e) {
             $errors[] = $e->__toString();
         }
     }
     var_dump($errors);
     die('DONE!');
 }
 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;
 }
示例#5
0
 protected function _runScript($filename)
 {
     $db = Zend_Db_Table_Abstract::getDefaultAdapter();
     $successCount = 0;
     $contents = file_get_contents($filename);
     foreach (Engine_Package_Utilities::sqlSplit($contents) as $sqlFragment) {
         try {
             $db->query($sqlFragment);
             $successCount++;
         } catch (Exception $e) {
             return $this->_error('Query failed with error: ' . $e->getMessage());
             exit;
         }
     }
 }
示例#6
0
文件: Module.php 项目: robeendey/ce
 public function onInstall()
 {
     $package = $this->_operation->getPrimaryPackage();
     $db = $this->getDb();
     $successCount = 0;
     $errors = array();
     $currentDbVersion = $this->_currentVersion;
     // Run selected scripts
     if (!empty($this->_selectedScripts)) {
         foreach ($this->_selectedScripts as $selectedScript) {
             $contents = file_get_contents($selectedScript['path']);
             foreach (Engine_Package_Utilities::sqlSplit($contents) as $sqlFragment) {
                 try {
                     $db->query($sqlFragment);
                     $successCount++;
                 } catch (Exception $e) {
                     return $this->_error('Query failed with error: ' . $e->getMessage());
                 }
             }
             // Update version for this upgrade
             $currentDbVersion = isset($selectedScript['version2']) ? $selectedScript['version2'] : (isset($selectedScript['version']) ? $selectedScript['version'] : null);
             if ($currentDbVersion) {
                 try {
                     $count = $db->update('engine4_core_modules', array('version' => $currentDbVersion), array('name = ?' => $package->getName()));
                     if ($count <= 0) {
                         try {
                             $db->insert('engine4_core_modules', array('name' => $package->getName(), 'version' => $currentDbVersion, 'title' => $package->getTitle(), 'description' => $package->getDescription(), 'enabled' => 1));
                         } catch (Exception $e) {
                         }
                     }
                 } catch (Exception $e) {
                     // Silence?
                 }
             }
         }
     }
     // Run custom
     if (method_exists($this, '_runCustomQueries')) {
         try {
             $r = $this->_runCustomQueries();
             if (is_int($r)) {
                 $successCount += $r;
             } else {
                 $successCount++;
             }
         } catch (Exception $e) {
             return $this->_error('Query failed with error: ' . $e->getMessage());
         }
     }
     // Update version
     if (!$this->hasError()) {
         if (!$package) {
             $package = $this->getOperation()->getPrimaryPackage();
         }
         if ($package) {
             $updateData = array('version' => $this->_targetVersion, 'title' => $package->getTitle(), 'description' => $package->getDescription());
         } else {
             $updateData = array('version' => $this->_targetVersion);
         }
         $count = $this->getDb()->update('engine4_core_modules', $updateData, array('name = ?' => $package->getName()));
         if ($count <= 0) {
             try {
                 $db->insert('engine4_core_modules', array('name' => $package->getName(), 'version' => $package->getVersion(), 'title' => $package->getTitle(), 'description' => $package->getDescription(), 'enabled' => 1));
             } catch (Exception $e) {
             }
         }
     }
     // Log success messages
     $this->_message(sprintf('%1$d queries succeeded.', $successCount));
     if (!$this->_currentVersion) {
         $this->_message(sprintf('%1$s installed.', $this->_targetVersion));
     } else {
         if (!$this->_targetVersion) {
             $this->_message(sprintf('%1$s removed.', $this->_currentVersion));
         } else {
             $this->_message(sprintf('%1$s to %2$s applied.', $this->_currentVersion, $this->_targetVersion));
         }
     }
     return $this;
 }
示例#7
0
 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;
     }
     // 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');
     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();
     // Certain stuff goes here (DO NOT REMOVE THIS LINE!)
     // Ok we're done
     $this->view->status = 1;
 }