public function createAction() { $data = $this->_getJsonData('data'); if (!is_array($data)) { // if post one record $data = array($data); } $returnData = array(); foreach ($data as $record) { $row = $this->_table->createRow(); $this->_onRowCreate($row, $record); $row->save(); $returnData[] = $row->toArray(); } $this->view->data = $returnData; }
/** * Stores information about trusted/untrusted site for given user * * @param string $id user identity URL * @param string $site site URL * @param mixed $trusted trust data from extensions or just a boolean value * @return bool */ public function addSite($id, $site, $trusted) { if (is_null($trusted)) { $this->_sitesTable->select()->where('site = ?', $site); $this->_sitesTable->delete($where); return true; } $row = $this->_sitesTable->createRow(); $row->openid = $id; $row->site = $site; $row->time = date('Y-m-d H:i:s O'); $row->trusted = serialize($trusted); $row->save(); return true; }
/** * Create super user for fresh toaster * @param array $data */ private function _createSuperUser($data) { $db = Zend_Db::factory(new Zend_Config($this->_session->dbinfo)); Zend_Db_Table_Abstract::setDefaultAdapter($db); $user = array('email' => $data['adminEmail'], 'password' => md5($data['adminPassword']), 'role_id' => 'superadmin', 'full_name' => $data['adminName'], 'reg_date' => date('Y-m-d h:i:s')); $userTable = new Zend_Db_Table('user'); $user = $userTable->createRow($user); if (!$user->save()) { error_log('Cannot create superadmin'); return false; } else { //saving superadmin email to 'config' table $settingsTable = new Zend_Db_Table('config'); $rowset = $settingsTable->find('adminEmail'); if (null === ($email = $rowset->current())) { $email = $settingsTable->createRow(); $email->name = 'adminEmail'; } $email->value = $user['email']; if (!$email->save()) { error_log('Cannot save adminEmail to config table.'); } if (isset($data['sambaToken']) && !empty($data['sambaToken'])) { $settingsTable->insert(array('name' => 'sambaToken', 'value' => $data['sambaToken'])); } } return true; }
/** * @group ZF-5674 */ public function testTableAndIdentityWithVeryLongName() { Zend_Db_Table::setDefaultAdapter($this->_db); // create test table using no identifier quoting $this->_util->createTable('thisisaveryverylongtablename', array('thisisalongtablenameidentity' => 'IDENTITY', 'stuff' => 'VARCHAR(32)')); $tableName = $this->_util->getTableName('thisisaveryverylongtablename'); $table = new Zend_Db_Table('thisisaveryverylongtablename'); $row = $table->createRow($this->_getRowForTableAndIdentityWithVeryLongName()); $row->save(); $rowset = $table->find(1); $this->assertEquals(1, count($rowset)); $this->_util->dropTable('thisisaveryverylongtablename'); }
public function accountAction() { // Leave if not ready if (empty($this->_session->mysql)) { return $this->_helper->redirector->gotoRoute(array('action' => 'db-info')); } $this->view->form = $form = new Install_Form_Account(); if (!$this->getRequest()->isPost()) { return; } if (!$form->isValid($this->getRequest()->getPost())) { return; } // Check passwords match $values = $form->getValues(); if ($values['password'] != $values['password_conf']) { $form->addError('Passwords must match.'); return; } // Create account // Connect again try { $config = $this->dbFormToConfig($this->_session->mysql); // Connect! $adapter = Zend_Db::factory($config['adapter'], $config['params']); $adapter->getServerVersion(); } catch (Exception $e) { $form->addError('Adapter Error: ' . $e->getMessage()); //$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) { } try { // Preprocess $settingsTable = new Zend_Db_Table(array('db' => $adapter, 'name' => 'engine4_core_settings')); $usersTable = new Zend_Db_Table(array('db' => $adapter, 'name' => 'engine4_users')); $levelTable = new Zend_Db_Table(array('db' => $adapter, 'name' => 'engine4_authorization_levels')); // Get static salt $staticSalt = $settingsTable->find('core.secret')->current(); if (is_object($staticSalt)) { $staticSalt = $staticSalt->value; } else { if (!is_string($staticSalt)) { $staticSalt = ''; } } // Get superadmin level $superAdminLevel = $levelTable->fetchRow($levelTable->select()->where('flag = ?', 'superadmin')); if (is_object($superAdminLevel)) { $superAdminLevel = $superAdminLevel->level_id; } else { $superAdminLevel = 1; } // Temporarily save pw $originalPassword = $values['password']; // Adjust values $values['salt'] = (string) rand(1000000, 9999999); $values['password'] = md5($staticSalt . $values['password'] . $values['salt']); $values['level_id'] = $superAdminLevel; $values['enabled'] = 1; $values['verified'] = 1; $values['creation_date'] = date('Y-m-d H:i:s'); $values['creation_ip'] = ip2long($_SERVER['REMOTE_ADDR']); $values['displayname'] = $values['username']; // Try to write info to config/auth.php if (!$this->_writeAuthToFile($values['email'], 'seiran', $originalPassword)) { throw new Exception('Unable to write Auth to File'); } // Insert $row = $usersTable->createRow(); $row->setFromArray($values); $row->save(); // First Signup Increment // Engine_Api::_()->getDbtable('statistics', 'core')->increment('user.creations'); // Validate password if ($row->password != md5($staticSalt . $originalPassword . $row->salt)) { throw new Engine_Exception('Error creating password'); } // Log the user into the intaller $auth = Zend_Registry::get('Zend_Auth'); $auth->getStorage()->write($row->user_id); // Try to log the user into socialengine // Note: nasty hack try { $mainSessionName = 'PHPSESSID'; if (empty($_COOKIE[$mainSessionName])) { $mainSessionId = md5(mt_rand(0, time()) . serialize($_SERVER)); setcookie($mainSessionName, $mainSessionId, null, dirname($this->view->baseUrl()), $_SERVER['HTTP_HOST'], false, false); } else { $mainSessionId = $_COOKIE[$mainSessionName]; } $adapter->insert('engine4_core_session', array('id' => $mainSessionId, 'modified' => time(), 'lifetime' => 86400, 'data' => 'Zend_Auth|' . serialize(array('storage' => $row->user_id)))); } catch (Exception $e) { // Silence if (APPLICATION_ENV == 'development') { echo $e->__toString(); } } // Update some other stuff $settingsTable = new Zend_Db_Table(array('db' => $adapter, 'name' => 'engine4_core_settings')); // Save site name $row = $settingsTable->find('core.general.site.title')->current(); if (null === $row) { $row = $settingsTable->createRow(); $row->name = 'core.general.site.title'; } $row->value = $values['site_title']; $row->save(); // Save email $row = $settingsTable->find('core.license.email')->current(); if (null === $row) { $row = $settingsTable->createRow(); $row->name = 'core.license.email'; } if ($row->value != '*****@*****.**') { $row->value = $values['email']; $row->save(); } // Update profile fields try { $fieldValuesTable = new Zend_Db_Table(array('db' => $adapter, 'name' => 'engine4_user_fields_values')); $fieldValuesTable->insert(array('item_id' => 1, 'field_id' => 1, 'index' => 0, 'value' => 1)); } catch (Exception $e) { } } catch (Exception $e) { $form->addError('Error: ' . $e->getMessage()); return; } // Redirect if successful return $this->_helper->redirector->gotoRoute(array('action' => 'complete')); }
/** * Action save * * @return void */ public function saveAction() { $form = new Admin_Form_Course(); $table = new Tri_Db_Table('course'); $data = $this->_getAllParams(); if ($form->isValid($data)) { if (!$form->image->receive()) { $this->_helper->_flashMessenger->addMessage('Image fail'); } $data = $form->getValues(); if (!$form->image->getValue()) { unset($data['image']); } if (!$data['responsible']) { unset($data['responsible']); } $data['user_id'] = Zend_Auth::getInstance()->getIdentity()->id; if (isset($data['id']) && $data['id']) { $row = $table->find($data['id'])->current(); $row->setFromArray($data); $id = $row->save(); } else { unset($data['id']); $classroom = new Zend_Db_Table('classroom'); $row = $table->createRow($data); $id = $row->save(); $responsible = null; if (isset($data['responsible'])) { $responsible = $data['responsible']; } $data = array('course_id' => $id, 'responsible' => $responsible, 'name' => 'Open ' . $data['name'], 'begin' => date('Y-m-d')); $row = $classroom->createRow($data); $row->save(); } $this->_helper->_flashMessenger->addMessage('Success'); $this->_redirect('admin/course/form/id/' . $id); } $this->_helper->_flashMessenger->addMessage('Error'); $this->view->form = $form; $this->render('form'); }
public function createRow(array $data = array(), $defaultSource = null) { $this->_db = CrFramework_Db_Control::getAdapter('write'); $this->setDefaultAdapter($this->_db); logStd(get_class($this) . '->createRow()', 'Write to MASTER'); return parent::createRow($data); }