<?php
/**
 * Mageplaza
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Mageplaza.com license that is
 * available through the world-wide-web at this URL:
 * https://www.mageplaza.com/LICENSE.txt
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade this extension to newer
 * version in the future.
 *
 * @category    Mageplaza
 * @package     Mageplaza_Faqs
 * @copyright   Copyright (c) Mageplaza (https://www.mageplaza.com/)
 * @license     https://www.mageplaza.com/LICENSE.txt
 */

namespace Mageplaza\Faqs\Setup;

use Magento\Framework\Setup\ModuleContextInterface;
use Magento\Framework\Setup\ModuleDataSetupInterface;
use Magento\Framework\Setup\UpgradeDataInterface;
use Mageplaza\Faqs\Model\ArticleFactory;

/**
 * Class UpgradeData
 * @package Mageplaza\Faqs\Setup
 */
class UpgradeData implements UpgradeDataInterface
{
    /**
     * @var ArticleFactory
     */
    protected $articleFactory;

    /**
     * UpgradeData constructor.
     *
     * @param ArticleFactory $articleFactory
     */
    public function __construct(
        ArticleFactory $articleFactory
    ) {
        $this->articleFactory = $articleFactory;
    }

    /**
     * @param ModuleDataSetupInterface $setup
     * @param ModuleContextInterface $context
     */
    public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
    {
        if (version_compare($context->getVersion(), '2.1.0', '<')) {
            $articleCollections = $this->articleFactory->create()->getCollection();
            foreach ($articleCollections as $article) {
                $article->setIcon('far fa-file-alt');
            }

            $articleCollections->save();
        }
    }
}
