0

i have a model that i can be called via controller like this

    protected $_sync;
    public function __construct(\Magento\Framework\App\Action\Context $context, \Lime\Hello\Model\SyncFactory $sync)
    {
        $this->_sync = $sync;
        parent::__construct($context);
    }

but when i try to call it in upgrade data it gives me an error like this :

Upgrading data.. PHP Fatal error: Uncaught Error: Call to undefined method Lime\Courier\Model\SyncFactory::syncAll()

here's my upgrade data:

namespace Lime\Courier\Setup;

use Magento\Framework\Setup\UpgradeDataInterface;
use Magento\Framework\Setup\ModuleContextInterface;
use Magento\Framework\Setup\ModuleDataSetupInterface;

class UpgradeData implements UpgradeDataInterface
{
      protected $_sync;
      public function __construct(\Lime\Courier\Model\SyncFactory $sync)
      {
          $this->_sync = $sync;
      }
    /**
     * {@inheritdoc}
     */
    public function upgrade(
        ModuleDataSetupInterface $setup,
        ModuleContextInterface $context
    ) {
        $setup->startSetup();
        if (version_compare($context->getVersion(), "1.0.0", "<")) {


        }
        if (version_compare($context->getVersion(), '1.0.1') < 0) {
            //code to upgrade to 1.0.1
            $run = $this->_sync;
            $run->syncAll();
        }

        $setup->endSetup();
    }
}

this is the function in the model

public function syncAll(){
    $this->setProvinces();
    $this->setCities();
    $this->setCouriers();
    $this->setCourierservices();
  }
  • 1
    Have you check factory class is exist or not ? have you run setup:di:compile command to generate factory ? – Manthan Dave Jan 19 '17 at 5:04
  • 1
    you can try with $run = $this->_sync->create(); $run->syncAll(); – Rakesh Jesadiya Jan 19 '17 at 5:23
  • @IdhamChoudry I have updated my code. – Rakesh Jesadiya Jan 19 '17 at 7:15
1

You have to try with,

$run = $this->_sync->create(); $run->syncAll();

namespace Lime\Courier\Setup;

use Magento\Framework\Setup\UpgradeDataInterface;
use Magento\Framework\Setup\ModuleContextInterface;
use Magento\Framework\Setup\ModuleDataSetupInterface;

class UpgradeData implements UpgradeDataInterface
{
      protected $_sync;
      public function __construct(\Lime\Courier\Model\SyncFactory $sync)
      {
          $this->_sync = $sync;
      }
    /**
     * {@inheritdoc}
     */
    public function upgrade(
        ModuleDataSetupInterface $setup,
        ModuleContextInterface $context
    ) {
        $setup->startSetup();
        if (version_compare($context->getVersion(), "1.0.0", "<")) {


        }
        if (version_compare($context->getVersion(), '1.0.1') < 0) {
            //code to upgrade to 1.0.1
            $run = $this->_sync->create();
            $run->syncAll();
        }

        $setup->endSetup();
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.