/**
  * Appends (copies) a child $source and all its descendants to $this node
  * @since 1.2.4
  *
  * @param CBSimpleXMLElement  $source
  * @param callback            $callBack to check/transform data or attributes of a node: $destinationData = function ( string|array $sourceData, CBSimpleXMLElement $sourceNode, CBSimpleXMLElement $destinationParentNode );
  */
 function &addChildWithDescendants(&$source, $callBack = null)
 {
     if ($callBack === null) {
         $child = $this->addChildWithAttr($source->name(), $source->data(), null, $source->attributes());
     } else {
         $child = $this->addChildWithAttr($source->name(), call_user_func_array($callBack, array($source->data(), $source, $this)), null, call_user_func_array($callBack, array($source->attributes(), $source, $this)));
     }
     foreach ($source->children() as $sourceChild) {
         $child->addChildWithDescendants($sourceChild, $callBack);
     }
     return $child;
 }
 /**
  * @param string A file path
  * @return object A DOMIT XML document, or null if the file failed to parse
  */
 function &isPackageFile($p_file)
 {
     $null = null;
     if (!file_exists($p_file)) {
         return $null;
     }
     cbimport('cb.xml.simplexml');
     $xmlString = trim(file_get_contents($p_file));
     $element = new CBSimpleXMLElement($xmlString);
     if (count($element->children()) == 0) {
         return $null;
     }
     if ($element->name() != 'cbinstall') {
         //echo "didn't find cbinstall";
         return $null;
     }
     // Set the type
     //echo "<br />element->attributes( 'type' )=".$element->attributes( 'type' );
     $this->installType($element->attributes('type'));
     $this->installFilename($p_file);
     return $element;
 }
Beispiel #3
0
	/**
	 * Returns a unique text id of a xml element depending on name and attribute values
	 * @access private
	 *
	 * @param  CBSimpleXMLElement  $el
	 * @return string
	 */
	function _uniqueTag( &$el ) {
		$add		=	'';
		foreach ( $el->attributes() as $k => $v ) {
			$add	.=	'|**|' . $k . '|==|' . $v;
		}
		return ( $el->name()) . $add;
	}
 /**
  * Checks if all columns of a xml description of all tables of a database matches the database
  *
  * Warning: removes columns tables and columns which would be added by the changes to XML !!!
  * @access private
  *
  * @param  CBSimpleXMLElement  $table
  * @param  string              $colNamePrefix    Prefix to add to all column names
  * @param  string              $change           'drop': uninstalls columns/tables
  * @param  boolean|null        $strictlyColumns  FALSE: allow for other columns, TRUE: doesn't allow for other columns, NULL: checks for attribute 'strict' in table
  * @return boolean             TRUE: matches, FALSE: don't match
  */
 function dropXmlTableDescription(&$table, $colNamePrefix = '', $change = 'drop', $strictlyColumns = false)
 {
     $isMatching = false;
     if ($change == 'drop' && $table->name() == 'table') {
         $tableName = $this->_prefixedName($table, $colNamePrefix);
         $columns =& $table->getElementByPath('columns');
         if ($tableName && $columns !== false) {
             if ($strictlyColumns === null) {
                 $strictlyColumns = $table->attributes('strict') === 'true';
             }
             $neverDropTable = $table->attributes('drop') === 'never';
             $isMatching = true;
             $allColumns = $this->getAllTableColumns($tableName);
             if ($allColumns === false) {
                 // table doesn't exist: do nothing
             } else {
                 if ($strictlyColumns && !$neverDropTable) {
                     if (in_array($tableName, array('#__comprofiler', '#_users', '#__comprofiler_fields'))) {
                         // Safeguard against fatal error in XML file !
                         $errorMsg = sprintf('Fatal error: Trying to delete core CB table %s not allowed.', $tableName);
                         echo $errorMsg;
                         trigger_error($errorMsg, E_USER_ERROR);
                         exit;
                     }
                     $this->dropTable($tableName);
                 } else {
                     // 1) Drop rows:
                     $rows =& $table->getElementByPath('rows');
                     if ($rows !== false) {
                         $neverDropRows = $rows->attributes('drop') === 'never';
                         if (!$neverDropRows) {
                             $strictRows = $rows->attributes('strict') === 'true';
                             foreach ($rows->children() as $row) {
                                 if ($row->name() == 'row') {
                                     $neverDropRow = $row->attributes('drop') === 'never';
                                     if ($strictRows && !$neverDropRow) {
                                         if (!$this->dropRow($tableName, $row, $colNamePrefix)) {
                                             $isMatching = false;
                                         }
                                     }
                                 }
                             }
                         }
                     }
                     // 2) Drop indexes:
                     $indexes =& $table->getElementByPath('indexes');
                     if ($indexes !== false) {
                         $neverDropIndexes = $indexes->attributes('drop') === 'never';
                         if (!$neverDropIndexes) {
                             $allIndexes = $this->getAllTableIndexes($tableName);
                             foreach ($indexes->children() as $index) {
                                 if ($index->name() == 'index') {
                                     $indexName = $this->_prefixedName($index, $colNamePrefix);
                                     if ($indexName == 'PRIMARY') {
                                         $neverDropIndex = $index->attributes('drop') !== 'always';
                                     } else {
                                         $neverDropIndex = $index->attributes('drop') === 'never';
                                     }
                                     if (isset($allIndexes[$indexName]) && !$neverDropIndex) {
                                         if (!$this->dropIndex($tableName, $indexName)) {
                                             $isMatching = false;
                                         }
                                     }
                                 }
                             }
                         }
                     }
                     // 3) Drop columns:
                     $neverDropColumns = $columns->attributes('drop') === 'never';
                     if (!$neverDropColumns) {
                         foreach ($columns->children() as $column) {
                             if ($column->name() == 'column') {
                                 $neverDropColumn = $column->attributes('drop') === 'never';
                                 $colNamePrefixed = $this->_prefixedName($column, $colNamePrefix);
                                 if (isset($allColumns[$colNamePrefixed]) && !$neverDropColumn) {
                                     if (!$this->dropColumn($tableName, $colNamePrefixed)) {
                                         $isMatching = false;
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     return $isMatching;
 }