src/Resources/contao/classes/Backup.php
/**
	 * This function accesses $this->importActions, parses the collected actions
	 * and prepares some updates to Contao's database which can be done automatically.
	 *
	 * The content of $this->importActions will be reorganised
	 * 		from  $this->importActions = ['collected' => ...]
	 * 		to    $this->importActions = ['supported' => ..., 'unsupported' => ...]
	 */
This function accesses $this->importActions, parses the collected actions
and prepares some updates to Contao's database which can be done automatically.


This function accesses $this - > importActions parses the collected actions and prepares some updates to Contao ' s database which can be done automatically .
protected function importParseActions() {
		if (!array_key_exists('collected', $this->importActions)) {
			return;
		}
		$supported_actions = (array_key_exists('supported', $this->importActions)) ? $this->importActions['supported'] : [];
		$unsupported_actions = (array_key_exists('unsupported', $this->importActions)) ? $this->importActions['unsupported'] : [];
		foreach ($this->importActions['collected'] as $action) {
			$key_parts = explode('|', $action['key']);
			$handled = false;
			switch ($key_parts[0]) {
				case 'price':	
					$min = null;
					for ($i = 1; $i < count($key_parts); $i++) {
						if (substr($key_parts[$i], 0, 4) == 'min:') {
							$min = intval(substr($key_parts[$i], 4));
							break;
						}
					}
					if ($action['type'] == 'update') {
						if (
							$min &&
							array_key_exists('contao-data', $action) &&
							array_key_exists("id-pricetier|min:$min", $action['contao-data'])
						) {
							$member_group = "default";
							$tax_class = "default";
							for ($i = count($action['path']) - 1; $i >= 0; $i--) {
								if (substr($action['path'][$i], 0, 6) == 'group|') {
									foreach (explode('|', $action['path'][$i]) as $s) {
										if (substr($s, 0, 8) == 'members:') {
											$member_group = substr($s, 8);
										}
										if (substr($s, 0, 10) == 'tax-class:') {
											$tax_class = substr($s, 10);
										}
									}
								}
							}
							$supported_actions[] = [
								'group' => 'prices',
								'sql' => [
									'UPDATE tl_iso_product_pricetier SET price = ? WHERE id = ?',
									floatval($action['new']),
									$action['contao-data']["id-pricetier|min:$min"]
								],
								'text' => [
									'Change price from %s to %s (minimum quantitiy: %s, member group: %s, tax class: %s)',
									$action['old'],
									$action['new'],
									$min,
									$member_group,
									$tax_class
								],
								'status'	=> 'prepared',
							];
							$handled = true;
						}
					}
					break;
				case 'name':
				case 'description':
					$id = (array_key_exists('contao-id', $action)) ? intval($action['contao-id']) : null;
					if (!$id && array_key_exists('contao-data', $action) && array_key_exists('id', $action['contao-data'])) {
						$id = intval($action['contao-data']['id']);
					}
					if (!$id || !count($action['path'])) {
						break;
					}
					if ($action['type'] == 'update') {
						$text = null;
						switch ($action['path'][0]) {
							case 'main':
								if (count($action['path']) == 1) {
									$text = [
										'Change %s of product',
										$key_parts[0]
									];
								}
								elseif (
									count($action['path']) == 3 &&
									$action['path'][1] == 'translations' &&
									preg_match('/language:(\w+)/', $action['path'][2], $matches)
								) {
									$text = [
										'Change translated %s of product (language "%s")',
										$key_parts[0],
										$matches[1]
									];
								}
								break;
							case 'variants':
								if (count($action['path']) == 2) {
									$text = [
										'Change %s of product variant (variant-index: %d)',
										$key_parts[0],
										intval($action['path'][1])
									];
								}
								elseif (
									count($action['path']) == 4 &&
									$action['path'][2] == 'translations' &&
									preg_match('/language:(\w+)/', $action['path'][3], $matches)
								) {
									$text = [
										'Change translated %s of product variant (variant-index: %d, language "%s")',
										$key_parts[0],
										intval($action['path'][1]),
										$matches[1]
									];
								}
								break;
						}
						if ($text) {
							$text[0] = "<div><b>{$text[0]}</b></div><div class=\"diff\">%s</div>";
							$text[] = my_htmlStringDiff($action['old'], $action['new']);
							$supported_actions[] = [
								'group'		=> $key_parts[0],
								'sql'		=> ["UPDATE tl_iso_product SET {$key_parts[0]} = ? WHERE id = ?", $action['new'], $id],
								'text'		=> $text,
								'status'	=> 'prepared',
							];
							$handled = true;
						}
					}
					break;
			}
			if (!$handled) {
				$unsupported_actions[] = $action;
			}
		}
		$this->importActions = [];
		if (count($supported_actions)) {
			$this->importActions['supported'] = $supported_actions;
		}
		if (count($unsupported_actions)) {
			$this->importActions['unsupported'] = $unsupported_actions;
		}
	}
protected function importParseActions ( ) { if ( ! array_key_exists ( 'collected' , $ this -> importActions ) ) { return ; } $ supported_actions = ( array_key_exists ( 'supported' , $ this -> importActions ) ) ? $ this -> importActions [ 'supported' ] : [ ] ; $ unsupported_actions = ( array_key_exists ( 'unsupported' , $ this -> importActions ) ) ? $ this -> importActions [ 'unsupported' ] : [ ] ; foreach ( $ this -> importActions [ 'collected' ] as $ action ) { $ key_parts = explode ( '|' , $ action [ 'key' ] ) ; $ handled = false ; switch ( $ key_parts [ 0 ] ) { case 'price' : $ min = null ; for ( $ i = 1 ; $ i < count ( $ key_parts ) ; $ i ++ ) { if ( substr ( $ key_parts [ $ i ] , 0 , 4 ) == 'min:' ) { $ min = intval ( substr ( $ key_parts [ $ i ] , 4 ) ) ; break ; } } if ( $ action [ 'type' ] == 'update' ) { if ( $ min && array_key_exists ( 'contao-data' , $ action ) && array_key_exists ( " id-pricetier|min: $ min " , $ action [ 'contao-data' ] ) ) { $ member_group = " default " ; $ tax_class = " default " ; for ( $ i = count ( $ action [ 'path' ] ) - 1 ; $ i >= 0 ; $ i -- ) { if ( substr ( $ action [ 'path' ] [ $ i ] , 0 , 6 ) == 'group|' ) { foreach ( explode ( '|' , $ action [ 'path' ] [ $ i ] ) as $ s ) { if ( substr ( $ s , 0 , 8 ) == 'members:' ) { $ member_group = substr ( $ s , 8 ) ; } if ( substr ( $ s , 0 , 10 ) == 'tax-class:' ) { $ tax_class = substr ( $ s , 10 ) ; } } } } $ supported_actions [ ] = [ 'group' => 'prices' , 'sql' => [ 'UPDATE tl_iso_product_pricetier SET price = ? WHERE id = ?' , floatval ( $ action [ 'new' ] ) , $ action [ 'contao-data' ] [ " id-pricetier|min: $ min " ] ] , 'text' => [ 'Change price from %s to %s (minimum quantitiy: %s, member group: %s, tax class: %s)' , $ action [ 'old' ] , $ action [ 'new' ] , $ min , $ member_group , $ tax_class ] , 'status' => 'prepared' , ] ; $ handled = true ; } } break ; case 'name' : case 'description' : $ id = ( array_key_exists ( 'contao-id' , $ action ) ) ? intval ( $ action [ 'contao-id' ] ) : null ; if ( ! $ id && array_key_exists ( 'contao-data' , $ action ) && array_key_exists ( 'id' , $ action [ 'contao-data' ] ) ) { $ id = intval ( $ action [ 'contao-data' ] [ 'id' ] ) ; } if ( ! $ id || ! count ( $ action [ 'path' ] ) ) { break ; } if ( $ action [ 'type' ] == 'update' ) { $ text = null ; switch ( $ action [ 'path' ] [ 0 ] ) { case 'main' : if ( count ( $ action [ 'path' ] ) == 1 ) { $ text = [ 'Change %s of product' , $ key_parts [ 0 ] ] ; } elseif ( count ( $ action [ 'path' ] ) == 3 && $ action [ 'path' ] [ 1 ] == 'translations' && preg_match ( '/language:(\w+)/' , $ action [ 'path' ] [ 2 ] , $ matches ) ) { $ text = [ 'Change translated %s of product (language "%s")' , $ key_parts [ 0 ] , $ matches [ 1 ] ] ; } break ; case 'variants' : if ( count ( $ action [ 'path' ] ) == 2 ) { $ text = [ 'Change %s of product variant (variant-index: %d)' , $ key_parts [ 0 ] , intval ( $ action [ 'path' ] [ 1 ] ) ] ; } elseif ( count ( $ action [ 'path' ] ) == 4 && $ action [ 'path' ] [ 2 ] == 'translations' && preg_match ( '/language:(\w+)/' , $ action [ 'path' ] [ 3 ] , $ matches ) ) { $ text = [ 'Change translated %s of product variant (variant-index: %d, language "%s")' , $ key_parts [ 0 ] , intval ( $ action [ 'path' ] [ 1 ] ) , $ matches [ 1 ] ] ; } break ; } if ( $ text ) { $ text [ 0 ] = " <div><b> { $ text [ 0 ] } </b></div><div class= \" diff \" >%s</div> " ; $ text [ ] = my_htmlStringDiff ( $ action [ 'old' ] , $ action [ 'new' ] ) ; $ supported_actions [ ] = [ 'group' => $ key_parts [ 0 ] , 'sql' => [ " UPDATE tl_iso_product SET  { $ key_parts [ 0 ] }  = ? WHERE id = ? " , $ action [ 'new' ] , $ id ] , 'text' => $ text , 'status' => 'prepared' , ] ; $ handled = true ; } } break ; } if ( ! $ handled ) { $ unsupported_actions [ ] = $ action ; } } $ this -> importActions = [ ] ; if ( count ( $ supported_actions ) ) { $ this -> importActions [ 'supported' ] = $ supported_actions ; } if ( count ( $ unsupported_actions ) ) { $ this -> importActions [ 'unsupported' ] = $ unsupported_actions ; } }
This function accesses $this->importActions, parses the collected actions
 and prepares some updates to Contao's database which can be done automatically.
This function accesses $this - > importActions parses the collected actions and prepares some updates to Contao ' s database which can be done automatically .
// e.g. $action['key'] = 'price|min:5' // e.g. $action['path'] == ['main']  or //      $action['path'] == ['main','translations','item|language:de'] // e.g. $action['path'] == ['variants',1]  or //      $action['path'] == ['variants',1,'translations','item|language:de']