controller/jobs/src/Controller/Jobs/Catalog/Import/Csv/Standard.php
protected function import( array &$catalogMap, array $data, array $mapping,
		\Aimeos\Controller\Common\Catalog\Import\Csv\Processor\Iface $processor, $strict )
	{
		$errors = 0;
		$context = $this->getContext();
		$manager = \Aimeos\MShop::create( $context, 'catalog' );

		foreach( $data as $code => $list )
		{
			$manager->begin();

			try
			{
				$code = trim( $code );

				if( isset( $catalogMap[$code] ) ) {
					$item = $catalogMap[$code];
				} else {
					$item = $manager->createItem();
				}

				$map = $this->getMappedChunk( $list, $mapping );

				if( isset( $map[0] ) )
				{
					$map = $map[0]; // there can only be one chunk for the base catalog data
					$parentid = $this->getParentId( $catalogMap, $map, $code );
					$item->fromArray( $map, true );

					if( isset( $catalogMap[$code] ) )
					{
						$manager->moveItem( $item->getId(), $item->getParentId(), $parentid );
						$item = $manager->saveItem( $item );
					}
					else
					{
						$item = $manager->insertItem( $item, $parentid );
					}

					$list = $processor->process( $item, $list );
					$catalogMap[$code] = $item;

					$manager->saveItem( $item );
				}

				$manager->commit();
			}
			catch( \Exception $e )
			{
				$manager->rollback();

				$msg = sprintf( 'Unable to import catalog with code "%1$s": %2$s', $code, $e->getMessage() );
				$context->getLogger()->log( $msg );

				$errors++;
			}

			if( $strict && !empty( $list ) ) {
				$context->getLogger()->log( 'Not imported: ' . print_r( $list, true ) );
			}
		}

		return $errors;
	}
protected function import( array &$catalogMap, array $data, array $mapping,
		\Aimeos\Controller\Common\Catalog\Import\Csv\Processor\Iface $processor, $strict )
	{
		$errors = 0;
		$context = $this->getContext();
		$manager = \Aimeos\MShop::create( $context, 'catalog' );

		foreach( $data as $code => $list )
		{
			$manager->begin();

			try
			{
				$code = trim( $code );

				if( isset( $catalogMap[$code] ) ) {
					$item = $catalogMap[$code];
				} else {
					$item = $manager->createItem();
				}

				$map = $this->getMappedChunk( $list, $mapping );

				if( isset( $map[0] ) )
				{
					$map = $map[0]; // there can only be one chunk for the base catalog data
					$parentid = $this->getParentId( $catalogMap, $map, $code );
					$item->fromArray( $map, true );

					if( isset( $catalogMap[$code] ) )
					{
						$manager->moveItem( $item->getId(), $item->getParentId(), $parentid );
						$item = $manager->saveItem( $item );
					}
					else
					{
						$item = $manager->insertItem( $item, $parentid );
					}

					$list = $processor->process( $item, $list );
					$catalogMap[$code] = $item;

					$manager->saveItem( $item );
				}

				$manager->commit();
			}
			catch( \Exception $e )
			{
				$manager->rollback();

				$msg = sprintf( 'Unable to import catalog with code "%1$s": %2$s', $code, $e->getMessage() );
				$context->getLogger()->log( $msg );

				$errors++;
			}

			if( $strict && !empty( $list ) ) {
				$context->getLogger()->log( 'Not imported: ' . print_r( $list, true ) );
			}
		}

		return $errors;
	}
protected function import ( array & $ catalogMap , array $ data , array $ mapping , \ Aimeos \ Controller \ Common \ Catalog \ Import \ Csv \ Processor \ Iface $ processor , $ strict ) { $ errors = 0 ; $ context = $ this -> getContext ( ) ; $ manager = \ Aimeos \ MShop :: create ( $ context , 'catalog' ) ; foreach ( $ data as $ code => $ list ) { $ manager -> begin ( ) ; try { $ code = trim ( $ code ) ; if ( isset ( $ catalogMap [ $ code ] ) ) { $ item = $ catalogMap [ $ code ] ; } else { $ item = $ manager -> createItem ( ) ; } $ map = $ this -> getMappedChunk ( $ list , $ mapping ) ; if ( isset ( $ map [ 0 ] ) ) { $ map = $ map [ 0 ] ; // there can only be one chunk for the base catalog data $ parentid = $ this -> getParentId ( $ catalogMap , $ map , $ code ) ; $ item -> fromArray ( $ map , true ) ; if ( isset ( $ catalogMap [ $ code ] ) ) { $ manager -> moveItem ( $ item -> getId ( ) , $ item -> getParentId ( ) , $ parentid ) ; $ item = $ manager -> saveItem ( $ item ) ; } else { $ item = $ manager -> insertItem ( $ item , $ parentid ) ; } $ list = $ processor -> process ( $ item , $ list ) ; $ catalogMap [ $ code ] = $ item ; $ manager -> saveItem ( $ item ) ; } $ manager -> commit ( ) ; } catch ( \ Exception $ e ) { $ manager -> rollback ( ) ; $ msg = sprintf ( 'Unable to import catalog with code "%1$s": %2$s' , $ code , $ e -> getMessage ( ) ) ; $ context -> getLogger ( ) -> log ( $ msg ) ; $ errors ++ ; } if ( $ strict && ! empty ( $ list ) ) { $ context -> getLogger ( ) -> log ( 'Not imported: ' . print_r ( $ list , true ) ) ; } } return $ errors ; }
Imports the CSV data and creates new categories or updates existing ones

@param array &$catalogMap Associative list of catalog items with codes as keys and items implementing \Aimeos\MShop\Catalog\Item\Iface as values
@param array $data Associative list of import data as index/value pairs
@param array $mapping Associative list of positions and domain item keys
@param \Aimeos\Controller\Common\Catalog\Import\Csv\Processor\Iface $processor Processor object
@param boolean $strict Log columns not mapped or silently ignore them
@return integer Number of catalogs that couldn't be imported
@throws \Aimeos\Controller\Jobs\Exception
Imports the CSV data and creates new categories or updates existing ones