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();
}
setup:di:compile
command to generate factory ?