Saves texts associated with attributes to catalog_index_text.

@param MShop_Common_Item_Interface[] $items Associative list of product IDs and items implementing MShop_Product_Item_Interface
977290
protected function _saveAttributeTexts( array $items )
	{
		$prodIds = array();

		foreach( $items as $item )
		{
			foreach( $item->getRefItems( 'attribute', null, 'default' ) as $attrItem ) {
				$prodIds[$attrItem->getId()][] = $item->getId();
			}
		}

		if( empty( $prodIds ) ) { return; }


		$attrManager = MShop_Factory::createManager( $this->_getContext(), 'attribute' );
		$search = $attrManager->createSearch(true);
		$expr = array(
			$search->compare( '==', 'attribute.id', array_keys( $prodIds ) ),
			$search->getConditions()
		);
		$search->setConditions( $search->combine( '&&', $expr ) );
		$search->setSlice( 0, 0x7fffffff );

		$attributeItems = $attrManager->searchItems( $search, array( 'text' ) );


		$context = $this->_getContext();
		$locale = $context->getLocale();
		$siteid = $context->getLocale()->getSiteId();
		$editor = $context->getEditor();
		$date = date( 'Y-m-d H:i:s' );


		$dbm = $context->getDatabaseManager();
		$dbname = $this->_getResourceName();
		$conn = $dbm->acquire( $dbname );

		try
		{
			$stmt = $this->_getCachedStatement( $conn, 'mshop/catalog/manager/index/text/default/item/insert' );

			foreach( $attributeItems as $id => $item )
			{
				$listTypes = array();
				foreach( $item->getListItems( 'text', 'default' ) as $listItem ) {
					$listTypes[ $listItem->getRefId() ][] = $listItem->getType();
				}

				foreach( $item->getRefItems( 'text' ) as $refId => $refItem )
				{
					if( !isset( $listTypes[$refId] ) ) {
						$msg = sprintf( 'List type for text item with ID "%1$s" not available', $refId );
						throw new MShop_Catalog_Exception( $msg );
					}

					foreach( $listTypes[$refId] as $listType )
					{
						foreach( $prodIds[$id] as $productId )
						{
							$this->_saveText(
								$stmt, $productId, $siteid, $refId, $refItem->getLanguageId(), $listType,
								$refItem->getType(), 'attribute', $refItem->getContent(), $date, $editor
							);
						}
					}
				}

				$names = $item->getRefItems( 'text', 'name' );

				if( empty( $names ) )
				{
					$this->_saveText(
						$stmt, $prodIds[$id], $siteid, null, $locale->getLanguageId(), 'default',
						'name', 'attribute', $item->getLabel(), $date, $editor
					);
				}
			}

			$dbm->release( $conn, $dbname );
		}
		catch( Exception $e )
		{
			$dbm->release( $conn, $dbname );
			throw $e;
		}
	}
940037
public function rebuildIndex( array $items = array() )
	{
		if( empty( $items ) ) { return; }

		MW_Common_Abstract::checkClassList( 'MShop_Product_Item_Interface', $items );

		$context = $this->_getContext();
		$locale = $context->getLocale();
		$siteid = $context->getLocale()->getSiteId();
		$editor = $context->getEditor();
		$date = date( 'Y-m-d H:i:s' );


		$dbm = $context->getDatabaseManager();
		$dbname = $this->_getResourceName();
		$conn = $dbm->acquire( $dbname );

		try
		{
			foreach( $items as $item )
			{
				$parentId = $item->getId(); // array id != $item->getId() for sub-products

				$listTypes = array();
				foreach( $item->getListItems( 'text' ) as $listItem ) {
					$listTypes[ $listItem->getRefId() ][] = $listItem->getType();
				}

				$stmt = $this->_getCachedStatement( $conn, 'mshop/catalog/manager/index/text/default/item/insert' );

				foreach( $item->getRefItems( 'text' ) as $refId => $refItem )
				{
					if( !isset( $listTypes[$refId] ) ) {
						$msg = sprintf( 'List type for text item with ID "%1$s" not available', $refId );
						throw new MShop_Catalog_Exception( $msg );
					}

					foreach( $listTypes[$refId] as $listType )
					{
						$this->_saveText(
							$stmt, $parentId, $siteid, $refId, $refItem->getLanguageId(), $listType,
							$refItem->getType(), 'product', $refItem->getContent(), $date, $editor
						);
					}
				}

				$names = $item->getRefItems( 'text', 'name' );

				if( empty( $names ) )
				{
					$this->_saveText(
						$stmt, $parentId, $siteid, null, $locale->getLanguageId(), 'default',
						'name', 'product', $item->getLabel(), $date, $editor
					);
				}
			}

			$dbm->release( $conn, $dbname );

		}
		catch( Exception $e )
		{
			$dbm->release( $conn, $dbname );
			throw $e;
		}

		$this->_saveAttributeTexts( $items );

		foreach( $this->_getSubManagers() as $submanager ) {
			$submanager->rebuildIndex( $items );
		}
	}
38545
public function writeItem($item)
    {
        $this->verifyHandle();

        if ($this->autoDetectHeader && !$this->header && is_array($item)) {
            $this->header = array_keys($item);
            $this->writeItem($this->header);
        }

        $this->csv->insertOne($item);
    }
485520
public function setItems($items, $where = '')
    {
        if (empty($items)) {
            return;
        }
        if (empty($where)) {
            $this->putItems($items);
        } elseif ($where === 'last') {
            $this->_items = ArrayHelper::insertLast($this->_items, $items);
        } elseif ($where === 'first') {
            $this->_items = ArrayHelper::insertFirst($this->_items, $items);
        } else {
            $this->_items = ArrayHelper::insertInside($this->_items, $items, $where);
        }
    }
1373760
protected function saveToCache(array $items, string $fileName): void
    {
        $content       = serialize($items);
        $directoryName = dirname($fileName);
        if (!is_dir($directoryName)) {
            mkdir($directoryName, $this->cacheFileMode, true);
        }
        file_put_contents($fileName, $content, LOCK_EX);
        // For cache files we don't want executable bits by default
        chmod($fileName, $this->cacheFileMode & (~0111));
    }
94497
protected function outputFormatTableReview(array $items)
    {
        $header = array(
            $this->text('ID'),
            $this->text('User'),
            $this->text('Product'),
            $this->text('Text'),
            $this->text('Status'),
            $this->text('Created')
        );

        $rows = array();

        foreach ($items as $item) {
            $rows[] = array(
                $item['review_id'],
                $item['user_id'],
                $item['product_id'],
                $this->truncate($item['text'], 50),
                $item['status'],
                $this->date($item['created'])
            );
        }

        $this->outputFormatTable($rows, $header);
    }
87956
protected function processItems(array $items)
    {
        $processedItems = [];

        foreach ($items as $entry) {
            $processedItems[] = ModelFactory::make($entry);
        }

        $this->items = new ModelCollection($processedItems);
    }
1325511
public function addItems(array $items, $append = true)
    {
        $this->_items = $this->mergeItems($this->_items, $items, $append);
    }
608691
protected function processItems(array $items)
    {
        $processedItems = [];

        foreach ($items as $entry) {
            if (isset($entry['metadata']) && is_array($entry['metadata'])) {
                $processedItems[] = new SearchResult($entry);
            }
        }

        $this->items = new ModelCollection($processedItems);
    }
239136
public function rebuildIndex( array $items = array() )
	{
		$context = $this->_getContext();
		$config = $context->getConfig();

		$size = $config->get( 'mshop/catalog/manager/index/default/chunksize', 1000 );
		$mode = $config->get( 'mshop/catalog/manager/index/default/index', 'categorized' );

		$default = array( 'attribute', 'price', 'text', 'product' );
		$domains = $config->get( 'mshop/catalog/manager/index/default/domains', $default );

		$manager = MShop_Factory::createManager( $context, 'product' );
		$search = $manager->createSearch( true );
		$search->setSortations( array( $search->sort( '+', 'product.id' ) ) );
		$defaultConditions = $search->getConditions();

		$paramIds = array();
		foreach( $items as $item ) {
			$paramIds[] = $item->getId();
		}

		if( $mode === 'all' ) // index all product items
		{
			if( !empty( $paramIds ) )
			{
				$expr = array(
					$search->compare( '==', 'product.id', $paramIds ),
					$defaultConditions,
				);
				$search->setConditions( $search->combine( '&&', $expr ) );
			}

			$this->_writeIndex( $search, $domains, $size );
			return;
		}

		// index categorized product items only
		$catalogListManager = MShop_Factory::createManager( $context, 'catalog/list' );
		$catalogSearch = $catalogListManager->createSearch( true );

		$expr = array( $catalogSearch->compare( '==', 'catalog.list.domain', 'product' ) );

		if( !empty( $paramIds ) ) {
			$expr[] = $catalogSearch->compare( '==', 'catalog.list.refid', $paramIds );
		}

		$expr[] = $catalogSearch->getConditions();

		$catalogSearch->setConditions( $catalogSearch->combine( '&&', $expr ) );
		$catalogSearch->setSortations( array( $catalogSearch->sort( '+', 'catalog.list.refid' ) ) );

		$start = 0;

		do
		{
			$catalogSearch->setSlice( $start, $size );
			$result = $catalogListManager->aggregate( $catalogSearch, 'catalog.list.refid' );

			$expr = array(
				$search->compare( '==', 'product.id', array_keys( $result ) ),
				$defaultConditions,
			);
			$search->setConditions( $search->combine( '&&', $expr ) );

			$this->_writeIndex( $search, $domains, $size );

			$start += $size;
		}
		while( count( $result ) > 0 );
	}
1356831
public function putItems(array $items)
    {
        foreach ($items as $k => $v) {
            $this->putItem($k, $v);
        }
    }
1060225
public function saveItem( MShop_Common_Item_Interface $item, $fetch = true )
	{
		$iface = 'MShop_Product_Item_Interface';
		if( !( $item instanceof $iface ) ) {
			throw new MShop_Catalog_Exception( sprintf( 'Object is not of required type "%1$s"', $iface ) );
		}

		if( $item->getId() === null ) {
			throw new MShop_Catalog_Exception( sprintf( 'Item could not be saved using method saveItem(). Item ID not available.' ) );
		}

		$this->rebuildIndex( array( $item ) );
	}
1274119
function saveProfile( array $item ) {

		// Sanitize
		$item = array_intersect_key( $item, $this->profileMetaKeys );

		foreach ( $item as $key => $val ) {

			if ( 'pb_catalog_logo' === $key ) {
				continue; // Skip, dev should use uploadLogo() instead
			}

			if ( 'pb_catalog_url' === $key && $val ) {
				$val = \Pressbooks\Sanitize\canonicalize_url( $val );
			}

			if ( '%d' === $this->profileMetaKeys[ $key ] ) {
				$val = (int) $val;
			} elseif ( '%f' === $this->profileMetaKeys[ $key ] ) {
				$val = (float) $val;
			} else {
				$val = (string) $val;
			}

			update_user_meta( $this->userId, $key, $val );
		}
	}
988088
public function add_item( $item ) {
		if ( is_array( $item ) ) {
			foreach ( $item as $single_item ) {
				$this->add_item( $single_item );
			}
		} else {
			$priority                   = $item->get_priority();
			$this->items[ $priority ][] = $item;
		}
	}
728318
public static function writeArrayItem($item)
    {
        $str = '';
        try {
            $str .= serialize($item);
        } catch (\Exception $e) {
            if (is_object($item)) {
                $str .= get_class($item).'#';
            }
            $str .= spl_object_hash($item);
        }
        return $str;
    }
810404
public function copyFrom( MShop_Attribute_Item_Interface $item )
	{
		$this->setAttributeId( $item->getId() );
		$this->setName( $item->getName() );
		$this->setCode( $item->getType() );
		$this->setValue( $item->getCode() );

		$this->setModified();
	}
1127096
protected function outputFormatTableDatabase(array $items)
    {
        $header = $rows = array();

        if (!empty($items)) {

            $first = reset($items);
            $header = array_keys($first);

            foreach ($items as $item) {
                $rows[] = array_values($item);
            }
        }

        $this->outputFormatTable($rows, $header);
    }