ArticleTypeField::rename PHP Method

rename() public method

Rename the article type field.
public rename ( $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));
            }
        }
    }

Usage Example

コード例 #1
0
ファイル: do_rename.php プロジェクト: nistormihai/Newscoop
		if ($articleTypeField->exists()) {
			$correct = false;
			$errorMsgs[] = getGS('The field $1 already exists.', '<B>'. htmlspecialchars($f_name). '</B>');
		}
	}

	if ($correct) {
		$article = new MetaArticle();
		if ($article->has_property($f_name) || method_exists($article, $f_name)) {
			$correct = false;
			$errorMsgs[] = getGS("The property '$1' is already in use.", $f_name);
		}
	}

    if ($correct) {
    	$old_articleTypeField->rename($f_name);
    	camp_html_goto_page("/$ADMIN/article_types/fields/?f_article_type=". urlencode($articleTypeName));
	}
}

$crumbs = array();
$crumbs[] = array(getGS("Configure"), "");
$crumbs[] = array(getGS("Article Types"), "/$ADMIN/article_types/");
$crumbs[] = array($articleTypeName, '');
$crumbs[] = array(getGS("Article type fields"), "/$ADMIN/article_types/fields/?f_article_type=".urlencode($articleTypeName));
$crumbs[] = array(getGS("Renaming article type field"), "");

echo camp_html_breadcrumbs($crumbs);

?>
<P>