delete() public method

Deletes the current article type field.
public delete ( )
Beispiel #1
0
 /**
  * Delete the article type. This will delete the entire table
  * in the database. Not recommended unless there is no article
  * data in the table.
  */
 public function delete()
 {
     global $g_ado_db;
     $translation = new Translation(null, $this->m_metadata->getPhraseId());
     $translation->deletePhrase();
     foreach ($this->m_dbColumns as $field) {
         $field->delete();
     }
     $this->m_metadata->delete();
     $queryStr = "DROP TABLE `" . $this->m_dbTableName . "`";
     $success = $g_ado_db->Execute($queryStr);
     CampCache::singleton()->clear('user');
 }
Beispiel #2
0
	/**
	 * Delete the article type. This will delete the entire table
	 * in the database. Not recommended unless there is no article
	 * data in the table.
	 */
	public function delete()
	{
		global $g_ado_db;

		$translation = new Translation(null, $this->m_metadata->getPhraseId());
		$translation->deletePhrase();

		foreach ($this->m_dbColumns as $field) {
			$field->delete();
		}
        $this->m_metadata->delete();

		$queryStr = "DROP TABLE `" . $this->m_dbTableName . "`";
		$success = $g_ado_db->Execute($queryStr);
		CampCache::singleton()->clear('user');
		if ($success) {
			if (function_exists("camp_load_translation_strings")) {
				camp_load_translation_strings("api");
			}
			$logtext = getGS('The article type "$1" has been deleted.', $this->m_name);
			Log::Message($logtext, null, 62);
		}
	} // fn delete
Beispiel #3
0
 /**
  * Returns an array of fields from all article types that match
  * the given conditions.
  *
  * @param $p_name
  *         if specified returns fields with the given name
  * @param $p_articleType
  *         if specified returns fields of the given article type
  * @param $p_dataType
  *         if specified returns the fields having the given data type
  *
  * @return array
  */
 public static function FetchFields($p_name = null, $p_articleType = null, $p_dataType = null, $p_negateName = false, $p_negateArticleType = false, $p_negateDataType = false, $p_selectHidden = true, $p_skipCache = false)
 {
     global $g_ado_db;
     if (!$p_skipCache && CampCache::IsEnabled()) {
         $paramsArray['name'] = is_null($p_name) ? 'null' : $p_name;
         $paramsArray['article_type'] = is_null($p_articleType) ? 'null' : $p_articleType;
         $paramsArray['data_type'] = is_null($p_dataType) ? 'null' : $p_dataType;
         $paramsArray['negate_name'] = $p_negateName == false ? 'false' : 'true';
         $paramsArray['negate_article_type'] = $p_negateArticleType == false ? 'false' : 'true';
         $paramsArray['negate_data_type'] = $p_negateDataType == false ? 'false' : 'true';
         $paramsArray['select_hidden'] = $p_selectHidden == false ? 'false' : 'true';
         $cacheListObj = new CampCacheList($paramsArray, __METHOD__);
         $articleTypeFieldsList = $cacheListObj->fetchFromCache();
         if ($articleTypeFieldsList !== false && is_array($articleTypeFieldsList)) {
             return $articleTypeFieldsList;
         }
     }
     $whereClauses = array();
     if (isset($p_name)) {
         $operator = $p_negateName ? '<>' : '=';
         $whereClauses[] = "field_name {$operator} " . $g_ado_db->escape($p_name);
     }
     if (isset($p_articleType)) {
         $operator = $p_negateArticleType ? '<>' : '=';
         $whereClauses[] = "type_name {$operator} " . $g_ado_db->escape($p_articleType);
     }
     if (isset($p_dataType)) {
         $operator = $p_negateDataType ? '<>' : '=';
         $whereClauses[] = "field_type {$operator} " . $g_ado_db->escape($p_dataType);
     }
     if (!$p_selectHidden) {
         $whereClauses[] = 'is_hidden = false';
     }
     $where = count($whereClauses) > 0 ? ' WHERE ' . implode(' and ', $whereClauses) : null;
     $query = "SELECT * FROM `ArticleTypeMetadata` {$where} ORDER BY type_name ASC, field_weight ASC";
     $rows = $g_ado_db->GetAll($query);
     $fields = array();
     foreach ($rows as $row) {
         $field = new ArticleTypeField($row['type_name'], $row['field_name']);
         if ($field->getPrintName() == '') {
             $field->delete();
             continue;
         }
         $fields[] = $field;
     }
     if (!$p_skipCache && CampCache::IsEnabled()) {
         $cacheListObj->storeInCache($fields);
     }
     return $fields;
 }
Beispiel #4
0
<?php

require_once $GLOBALS['g_campsiteDir'] . '/classes/Input.php';
require_once $GLOBALS['g_campsiteDir'] . '/classes/Log.php';
require_once $GLOBALS['g_campsiteDir'] . '/classes/ArticleType.php';
$translator = \Zend_Registry::get('container')->getService('translator');
if (!SecurityToken::isValid()) {
    camp_html_display_error($translator->trans('Invalid security token!'));
    exit;
}
// Check permissions
if (!$g_user->hasPermission('DeleteArticleTypes')) {
    camp_html_display_error($translator->trans("You do not have the right to delete article type fields.", array(), 'article_type_fields'));
    exit;
}
$articleTypeName = Input::Get('f_article_type');
$fieldName = Input::Get('f_field_name');
$field = new ArticleTypeField($articleTypeName, $fieldName);
if ($field->exists()) {
    $field->delete();
    $cacheService = \Zend_Registry::get('container')->getService('newscoop.cache');
    $cacheService->clearNamespace('article_type');
}
camp_html_goto_page("/{$ADMIN}/article_types/fields/?f_article_type=" . urlencode($articleTypeName));
Beispiel #5
0
 /**
  * Delete the topic.
  * @return boolean
  */
 public function delete($p_languageId = null)
 {
     global $g_ado_db;
     $g_ado_db->Execute("LOCK TABLE Topics WRITE, TopicNames WRITE, TopicFields READ, ArticleTypeMetadata WRITE");
     $topicId = $this->getTopicId();
     if ($p_languageId > 0 && $this->getNumTranslations() > 1) {
         $deletedName = $this->m_names[$p_languageId];
         $topicName = new TopicName($this->getTopicId(), $p_languageId);
         $deleted = $topicName->delete();
         if ($deleted) {
             unset($this->m_names[$p_languageId]);
         }
     } else {
         $deletedName = implode(",", $this->m_names);
         // Delete the article type field metadata
         $sql = "SELECT * FROM TopicFields WHERE RootTopicId IN " . "(SELECT DISTINCT Id FROM Topics WHERE node_left >= " . $this->m_data['node_left'] . " AND node_right < " . $this->m_data['node_right'] . ")";
         $rows = $g_ado_db->GetAll($sql);
         foreach ($rows as $row) {
             $delATF = new ArticleTypeField($row['ArticleType'], $row['FieldName']);
             $delATF->delete();
         }
         // Delete topic names
         TopicName::DeleteTopicNames($this->getTopicId());
         // Delete children and itself
         $sql = "DELETE FROM Topics WHERE node_left >= " . $this->m_data['node_left'] . ' AND node_right <= ' . $this->m_data['node_right'];
         $deleted = $g_ado_db->Execute($sql);
         if ($deleted) {
             $myWidth = $this->m_data['node_right'] - $this->m_data['node_left'] + 1;
             $sql = "UPDATE Topics SET node_left = node_left - {$myWidth} WHERE node_left > " . $this->m_data['node_left'];
             $g_ado_db->Execute($sql);
             $sql = "UPDATE Topics SET node_right = node_right - {$myWidth} WHERE node_right > " . $this->m_data['node_right'];
             $g_ado_db->Execute($sql);
         }
         $this->m_data = array();
         $this->m_exists = false;
     }
     $g_ado_db->Execute("UNLOCK TABLES");
     CampCache::singleton()->clear('user');
     return $deleted;
 }
 /**
  * Returns an array of fields from all article types that match
  * the given conditions.
  *
  * @param $p_name
  *         if specified returns fields with the given name
  * @param $p_articleType
  *         if specified returns fields of the given article type
  * @param $p_dataType
  *         if specified returns the fields having the given data type
  *
  * @return array
  */
 public static function FetchFields($p_name = null, $p_articleType = null, $p_dataType = null, $p_negateName = false, $p_negateArticleType = false, $p_negateDataType = false, $p_selectHidden = true, $p_skipCache = false)
 {
     global $g_ado_db;
     $cacheService = \Zend_Registry::get('container')->getService('newscoop.cache');
     if (!$p_skipCache) {
         $paramsArray['name'] = is_null($p_name) ? 'null' : $p_name;
         $paramsArray['article_type'] = is_null($p_articleType) ? 'null' : $p_articleType;
         $paramsArray['data_type'] = is_null($p_dataType) ? 'null' : $p_dataType;
         $paramsArray['negate_name'] = $p_negateName == false ? 'false' : 'true';
         $paramsArray['negate_article_type'] = $p_negateArticleType == false ? 'false' : 'true';
         $paramsArray['negate_data_type'] = $p_negateDataType == false ? 'false' : 'true';
         $paramsArray['select_hidden'] = $p_selectHidden == false ? 'false' : 'true';
         $paramsArray['method'] = __METHOD__;
         $cacheKey = $cacheService->getCacheKey($paramsArray, 'article_type');
         if ($cacheService->contains($cacheKey)) {
             $articleTypeFieldsList = $cacheService->fetch($cacheKey);
             if ($articleTypeFieldsList !== false && is_array($articleTypeFieldsList)) {
                 return $articleTypeFieldsList;
             }
         }
     }
     $whereClauses = array();
     if (isset($p_name)) {
         $operator = $p_negateName ? '<>' : '=';
         $whereClauses[] = "field_name {$operator} " . $g_ado_db->escape($p_name);
     }
     if (isset($p_articleType)) {
         $operator = $p_negateArticleType ? '<>' : '=';
         $whereClauses[] = "type_name {$operator} " . $g_ado_db->escape($p_articleType);
     }
     if (isset($p_dataType)) {
         $operator = $p_negateDataType ? '<>' : '=';
         $whereClauses[] = "field_type {$operator} " . $g_ado_db->escape($p_dataType);
     }
     if (!$p_selectHidden) {
         $whereClauses[] = 'is_hidden = false';
     }
     $where = count($whereClauses) > 0 ? ' WHERE ' . implode(' and ', $whereClauses) : null;
     $query = "SELECT * FROM `ArticleTypeMetadata` {$where} ORDER BY type_name ASC, field_weight ASC";
     $rows = $g_ado_db->GetAll($query);
     $fields = array();
     foreach ($rows as $row) {
         $field = new ArticleTypeField($row['type_name'], $row['field_name']);
         if ($field->getPrintName() == '') {
             $field->delete();
             continue;
         }
         $fields[] = $field;
     }
     if (!$p_skipCache) {
         $cacheService->save($cacheKey, $fields);
     }
     return $fields;
 }