/** * Checks the all data content tables of comprofiler fields and upgrades if needed * Backend-use only. * @access private * * @param boolean $upgrade False: only check table, True: upgrades table (depending on $dryRun) * @param boolean $dryRun True: doesn't do the modifying queries, but lists them, False: does the job * @param boolean $preferredColumnType Enforce preferred column type * @return string Message to display */ public function checkAllCBfieldsDb($upgrade = false, $dryRun = false, $preferredColumnType = false) { $this->_sqlUpgrader = new DatabaseUpgrade($this->_db, $this->_silentWhenOK); $this->_sqlUpgrader->setDryRun($dryRun); $this->_sqlUpgrader->setEnforcePreferredColumnType($preferredColumnType); $this->_db->setQuery("SELECT f.*" . "\n FROM " . $this->_db->NameQuote('#__comprofiler_fields') . ' AS f' . "\n INNER JOIN " . $this->_db->NameQuote('#__comprofiler_tabs') . ' AS t ON ( (f.' . $this->_db->NameQuote('tabid') . ' = t.' . $this->_db->NameQuote('tabid') . ') AND (t.' . $this->_db->NameQuote('fields') . ' = 1) ) ' . "\n LEFT JOIN " . $this->_db->NameQuote('#__comprofiler_plugin') . ' AS p ON p.' . $this->_db->NameQuote('id') . ' = t.' . $this->_db->NameQuote('pluginid') . "\n LEFT JOIN " . $this->_db->NameQuote('#__comprofiler_plugin') . ' AS pf ON pf.' . $this->_db->NameQuote('id') . ' = f.' . $this->_db->NameQuote('pluginid') . "\n ORDER BY t. " . $this->_db->NameQuote('ordering') . ', f.' . $this->_db->NameQuote('ordering')); $rows = $this->_db->loadObjectList('fieldid', '\\CB\\Database\\Table\\FieldTable', array(&$this->_db)); if ($this->_db->getErrorNum()) { echo $this->_db->getErrorMsg(); return false; } $ret = true; foreach ($rows as $field) { $fieldHandler = new cbFieldHandler(); $success = $fieldHandler->checkFixSQL($this->_sqlUpgrader, $field, $upgrade); if (!$success) { $ret = false; // echo $field->_error; } } return $ret; }
/** * Handles SQL XML for the type of the field (backend use only!) * <database version="1"> * <table name="#__comprofilerUser" class="\CB\Database\Table\UserTable"> * <columns> * <column name="_rate" nametype="namesuffix" type="sql:decimal(16,8)" unsigned="true" null="true" default="NULL" auto_increment="100" /> * * TODO: Should be private, but is public because FIeldTable uses it ! * * @param FieldTable $field Field to adapt * @param boolean|string $change FALSE: only check, TRUE: change database to match description (deleting non-matching columns if $strictlyColumns == true), 'drop': uninstalls columns/tables * @param boolean $dryRun FALSE (default): tables are changed, TRUE: Dryrunning * @param boolean $preferredColumnType Enforce preferred column type * @return array of array of array */ public function adaptSQL($field, $change = true, $dryRun = false, $preferredColumnType = false) { $sqlUpgrader = new DatabaseUpgrade(); $sqlUpgrader->setDryRun($dryRun); $old = $sqlUpgrader->setEnforcePreferredColumnType($preferredColumnType); $result = $this->checkFixSQL($sqlUpgrader, $field, $change); $sqlUpgrader->setEnforcePreferredColumnType($old); return $result; }