/** * Persist all the data to the datastore * * @param boolean $actual TRUE when referring to actual ORM, FALSE when referring to ConfigItem (default to TRUE) * @return boolean */ public function persist($actual = true) { if ($actual) { $this->_table = $this->_name; parent::persist(); return true; } $defaultTableName = $this->_defaultFormularyName; if ($defaultTableName == null) { $defaultTableName = self::getDefaultFormularyTable(); } $db = Zend_Registry::get('dbAdapter'); if ($this->_persistMode == WebVista_Model_ORM::DELETE) { $queries = array(); $queries[] = "DROP TABLE {$this->_name}"; $queries[] = "DELETE FROM {$this->_config->_table} WHERE configId='{$this->_name}'"; $db->query(implode(';' . PHP_EOL, $queries)); } else { // create new table based on default table $tableName = $this->_name; if (!self::isTableExists($tableName)) { $sql = 'CREATE TABLE ' . $tableName . ' LIKE ' . $defaultTableName; $sql .= '; INSERT INTO ' . $tableName . ' SELECT * FROM ' . $defaultTableName; trigger_error($sql, E_USER_NOTICE); $db->query($sql); } $this->_config->configId = $this->_name; $this->_config->value = serialize($this); $this->_config->setPersistMode($this->_persistMode); $this->_config->persist(); } if ($this->_isDefaultSet) { // backup configId and value $configId = $this->_config->configId; $value = $this->_config->value; $this->_config->configId = $defaultTableName; $this->_config->populate(); $formularyItem = unserialize($this->_config->value); if ($formularyItem !== false && $formularyItem instanceof self && $formularyItem->getName() != $this->getName()) { // unset the default $formularyItem->unsetDefault(); $formularyItem->persist(false); } // set the default formulary table name to this table name $this->_config->configId = self::DEFAULTFORMULARYID; $this->_config->value = $this->_name; $this->_config->persist(); // restore the previous data for configId and value $this->_config->configId = $configId; $this->_config->value = $value; } // temporarily return true, this might change later if needed return true; }