/** * Rename the article type field. * * @param string p_newName * */ public function rename($p_newName) { global $g_ado_db; if (!$this->exists() || !ArticleType::isValidFieldName($p_newName)) { return 0; } $types = self::DatabaseTypes(null, $this->m_precision); $queryStr = "ALTER TABLE `X". $this->m_data['type_name']."` CHANGE COLUMN `" . $this->getName() ."` `F$p_newName` ". $types[$this->getType()]; $success = $g_ado_db->Execute($queryStr); if ($success) { if ($this->getType() == self::TYPE_TOPIC) { $query = "UPDATE TopicFields SET FieldName = '" . $g_ado_db->escape($p_newName) . "' WHERE RootTopicId = " . $this->getTopicTypeRootElement(); $g_ado_db->Execute($query); } $fieldName = $this->m_data['field_name']; $this->setProperty('field_name', $p_newName); if (function_exists("camp_load_translation_strings")) { camp_load_translation_strings("api"); } $logText = getGS('The article type field "$1" has been renamed to "$2".', $fieldName, $p_newName); Log::Message($logText, null, 62); } } // fn rename
/** * Rename the article type field. * * @param string p_newName * */ public function rename($p_newName) { global $g_ado_db; if (!$this->exists() || !ArticleType::isValidFieldName($p_newName)) { return 0; } $types = self::DatabaseTypes(null, $this->m_precision); $oldFieldName = $this->m_data['field_name']; $queryStr = "ALTER TABLE `X" . $this->m_data['type_name'] . "` CHANGE COLUMN `" . $this->getName() . "` `F{$p_newName}` " . $types[$this->getType()]; $success = $g_ado_db->Execute($queryStr); if ($success) { if ($this->getType() == self::TYPE_TOPIC) { $query = "UPDATE TopicFields SET FieldName = " . $g_ado_db->escape($p_newName) . " WHERE RootTopicId = " . $this->getTopicTypeRootElement(); $g_ado_db->Execute($query); } $fieldName = $this->m_data['field_name']; $this->setProperty('field_name', $p_newName); if ($this->getType() == self::TYPE_COMPLEX_DATE) { $em = Zend_Registry::get('container')->getService('em'); $repo = $em->getRepository('Newscoop\\Entity\\ArticleDatetime'); $repo->renameField($this->m_data['type_name'], array('old' => $oldFieldName, 'new' => $p_newName)); } } }
/** * Rename the article type. This will move the entire table in the * database and update ArticleTypeMetadata. Usually, one wants to * just rename the Display Name, which is done via SetDisplayName * * @param $p_newName */ public function rename($p_newName) { global $g_ado_db; if (!ArticleType::isValidFieldName($p_newName)) { return false; } $metadata = new ArticleTypeField($p_newName, 'NULL'); if ($metadata->exists()) { return false; } $oldName = $this->m_name; $oldNameEsc = $g_ado_db->escape($this->m_name); $newNameEsc = $g_ado_db->escape($p_newName); $queryStr = "RENAME TABLE `" . $this->m_dbTableName . "` TO `X{$p_newName}`"; $success = $g_ado_db->Execute($queryStr); if ($success) { $queryStr = "UPDATE ArticleTypeMetadata SET type_name = {$newNameEsc} " . "WHERE type_name = {$oldNameEsc}"; $success = $g_ado_db->Execute($queryStr); } if ($success) { $queryStr = "UPDATE Articles SET Type = {$newNameEsc} WHERE Type = {$oldNameEsc}"; $success = $g_ado_db->Execute($queryStr); } if ($success) { $this->m_name = $p_newName; $this->m_dbTableName = 'X' . $p_newName; } else { $queryStr = "RENAME TABLE `X{$p_newName}` TO `" . $this->m_dbTableName . "`"; $g_ado_db->Execute($queryStr); $queryStr = "UPDATE ArticleTypeMetadata SET type_name = '{$oldName}' " . "WHERE type_name = {$newNameEsc}"; $g_ado_db->Execute($queryStr); $queryStr = "UPDATE Articles SET Type = '{$oldName}' WHERE Type = {$newNameEsc}"; $g_ado_db->Execute($queryStr); } return $success; }
/** * Rename the article type. This will move the entire table in the * database and update ArticleTypeMetadata. Usually, one wants to * just rename the Display Name, which is done via SetDisplayName * * @param $p_newName */ public function rename($p_newName) { global $g_ado_db; if (!ArticleType::isValidFieldName($p_newName)) { return false; } $metadata = new ArticleTypeField($p_newName, 'NULL'); if ($metadata->exists()) { return false; } $oldName = $this->m_name; $oldNameEsc = $g_ado_db->escape($this->m_name); $newNameEsc = $g_ado_db->escape($p_newName); $queryStr = "RENAME TABLE `" . $this->m_dbTableName . "` TO `X$p_newName`"; $success = $g_ado_db->Execute($queryStr); if ($success) { $queryStr = "UPDATE ArticleTypeMetadata SET type_name = '$newNameEsc' " . "WHERE type_name = '$oldNameEsc'"; $success = $g_ado_db->Execute($queryStr); } if ($success) { $queryStr = "UPDATE Articles SET Type = '$newNameEsc' WHERE Type = '$oldNameEsc'"; $success = $g_ado_db->Execute($queryStr); } if ($success) { $this->m_name = $p_newName; $this->m_dbTableName = 'X'. $p_newName; if (function_exists("camp_load_translation_strings")) { camp_load_translation_strings("api"); } $logText = getGS('The article type "$1" has been renamed to "$2".', $oldName, $p_newName); Log::Message($logText, null, 62); } else { $queryStr = "RENAME TABLE `X$p_newName` TO `" . $this->m_dbTableName . "`"; $g_ado_db->Execute($queryStr); $queryStr = "UPDATE ArticleTypeMetadata SET type_name = '$oldName' " . "WHERE type_name = '$newNameEsc'"; $g_ado_db->Execute($queryStr); $queryStr = "UPDATE Articles SET Type = '$oldName' WHERE Type = '$newNameEsc'"; $g_ado_db->Execute($queryStr); } return $success; } // fn rename