I’m working on a cronjob that will delete products by last date updated.
I’m seeing very strange Magento 2 behavior – the PHP file changes are not showing up until I update the repository and then run composer update.
The store is in Development mode. Running via Docker-compose.
During development on other plugins as soon as I do:
rm -rf var/generation var/view_preprocessed/ pub/static/frontend generated/code
php -dmemory_limit=6G bin/magento setup:di:compile
php -dmemory_limit=6G bin/magento setup:static-content:deploy -f
php -dmemory_limit=6G bin/magento cache:flush
The file changes show up and sometimes even without these commands.
But, with this plugin the changes do not show up until I fully push changes to repository and then run composer update with all the other commands.
Is there some kind of caching for cron job classes that I don’t know about?
FOLDER STRUCTURE
Here is my folder structure:
srcvendorcompanydeleteoldproductsCronDeleteOldProducts.php
srcvendorcompanydeleteoldproductsetcadminhtmlsystem.xml
srcvendorcompanydeleteoldproductsetcconfig.xml
srcvendorcompanydeleteoldproductsetccrontab.xml
srcvendorcompanydeleteoldproductsetcmodule.xml
srcvendorcompanydeleteoldproductscomposer.json
srcvendorcompanydeleteoldproductsregistration.php
The DeleteOldProducts.php is being used by the cron job, but uses an old version of it. I try to make changes to it, re-run the commands mentioned above, but cronjob still uses old version of the file. This is not normal.
Here is the php file:
<?php
namespace CompanyDeleteOldProductsCron;
use MagentoCatalogApiProductRepositoryInterface;
use MagentoCatalogModelResourceModelProductCollectionFactory;
class DeleteOldProducts
{
/**
* @var ProductRepositoryInterface
*/
protected $_productRepositoryInterface;
/**
* @var CollectionFactory
*/
protected $_productCollectionFactory;
public function __construct(
ProductRepositoryInterface $_productRepositoryInterface,
CollectionFactory $_productCollectionFactory
) {
$this->_productRepositoryInterface = $_productRepositoryInterface;
$this->_productCollectionFactory = $_productCollectionFactory;
}
public function execute()
{
$writer = new Zend_Log_Writer_Stream(BP . '/var/log/DELETE-OLD-PRODUCTS.log');
$logger = new Zend_Log();
$logger->addWriter($writer);
$logger->info('---DELETING IS HAPPENING---');
$collection = $this->_productCollectionFactory->create();
$collection->addAttributeToSelect('*');
$collection->setPageSize(10);
$logger->info("COLLECTION?11111111");
foreach($collection as $product)
{
$logger->info('PRODUCT ID' . $product->getId());
}
$logger->info("COLLECTION?222222222");
$logger->info('---DELETING IS HAPPENING---');
$logger->info(' ');
$logger->info(' ');
return $this;
}
}
Why is this happening?
Advertisement
Answer
I found the issue – I had naming conflicts between the the plugin I was developing and the one in the composer
One was “deleteoldproducts” and the one in composer was “module-deleteoldproducts”.
Should have deleted the original folder after I pushed it to repository.