/** * (non-PHPdoc). * * @see Alpha\Model\ActiveRecordProviderInterface::addProperty() */ public function addProperty($propName) { self::$logger->debug('>>addProperty(propName=[' . $propName . '])'); $sqlQuery = 'ALTER TABLE ' . $this->BO->getTableName() . ' ADD '; if ($this->isTableOverloaded() && $propName == 'classname') { $sqlQuery .= 'classname VARCHAR(100)'; } else { if (!in_array($propName, $this->BO->getDefaultAttributes()) && !in_array($propName, $this->BO->getTransientAttributes())) { $reflection = new ReflectionClass($this->BO->getPropObject($propName)); $propClass = $reflection->getShortName(); switch (mb_strtoupper($propClass)) { case 'INTEGER': $sqlQuery .= "{$propName} INT(" . $this->BO->getPropObject($propName)->getSize() . ')'; break; case 'DOUBLE': $sqlQuery .= "{$propName} DOUBLE(" . $this->BO->getPropObject($propName)->getSize(true) . ')'; break; case 'STRING': $sqlQuery .= "{$propName} VARCHAR(" . $this->BO->getPropObject($propName)->getSize() . ')'; break; case 'SEQUENCE': $sqlQuery .= "{$propName} VARCHAR(" . $this->BO->getPropObject($propName)->getSize() . ')'; break; case 'TEXT': $sqlQuery .= "{$propName} TEXT"; break; case 'BOOLEAN': $sqlQuery .= "{$propName} CHAR(1) DEFAULT '0'"; break; case 'DATE': $sqlQuery .= "{$propName} DATE"; break; case 'TIMESTAMP': $sqlQuery .= "{$propName} DATETIME"; break; case 'ENUM': $sqlQuery .= "{$propName} ENUM("; $enumVals = $this->BO->getPropObject($propName)->getOptions(); foreach ($enumVals as $val) { $sqlQuery .= "'" . $val . "',"; } $sqlQuery = rtrim($sqlQuery, ','); $sqlQuery .= ')'; break; case 'DENUM': $tmp = new DEnum(get_class($this->BO) . '::' . $propName); $tmp->save(); $sqlQuery .= "{$propName} INT(11) ZEROFILL"; break; case 'RELATION': $sqlQuery .= "{$propName} INT(11) ZEROFILL UNSIGNED"; break; default: $sqlQuery .= ''; break; } } } $this->BO->setLastQuery($sqlQuery); if (!($result = self::getConnection()->query($sqlQuery))) { throw new AlphaException('Failed to add the new attribute [' . $propName . '] to the table [' . $this->BO->getTableName() . '], query is [' . $this->BO->getLastQuery() . ']'); self::$logger->debug('<<addProperty'); } else { self::$logger->info('Successfully added the [' . $propName . '] column onto the [' . $this->BO->getTableName() . '] table for the class [' . get_class($this->BO) . ']'); } if ($this->BO->getMaintainHistory()) { $sqlQuery = str_replace($this->BO->getTableName(), $this->BO->getTableName() . '_history', $sqlQuery); if (!($result = self::getConnection()->query($sqlQuery))) { throw new AlphaException('Failed to add the new attribute [' . $propName . '] to the table [' . $this->BO->getTableName() . '_history], query is [' . $this->BO->getLastQuery() . ']'); self::$logger->debug('<<addProperty'); } else { self::$logger->info('Successfully added the [' . $propName . '] column onto the [' . $this->BO->getTableName() . '_history] table for the class [' . get_class($this->BO) . ']'); } } self::$logger->debug('<<addProperty'); }