Magento always creates new entriesCron job always “missed”Magento2 2.1.5 Cronjob doesn't get executed. ID always 0Cron status is always missed in Magento 1.9Cron job creates loads of records in databaseCustom cron job status always pendingcataloginventory_stock_status randomly has missing entriesMagento 2.3 Can't view module's front end page output?What creates references? I've been unable to find the source of a broken referenceMagento2: Order summary always expandedCron Job status always missed/ not running Magento 2

Why don’t airliners have temporary liveries?

Company did not petition for visa in a timely manner. Is asking me to work from overseas, but wants me to take a paycut

How do I write "Show, Don't Tell" as a person with Asperger Syndrome?

Argon vs nitrogen for preserving wine

Is it possible to 'live off the sea'

How did students remember what to practise between lessons without any sheet music?

Avoiding cliches when writing gods

Inconsistent behavior of compiler optimization of unused string

Taxi Services at Didcot

Can anyone identify this tank?

Why does the Schrödinger equation work so well for the hydrogen atom despite the relativistic boundary at the nucleus?

Turing patterns

How does an ordinary object become radioactive?

Russian equivalents of "no love lost"

Was the Tamarian language in "Darmok" inspired by Jack Vance's "The Asutra"?

What are the peak hours for public transportation in Paris?

How powerful is a "Breathe Air" spell?

What is the advantage of carrying a tripod and ND-filters when you could use image stacking instead?

Can the poison from Kingsmen be concocted?

Different pedals/effects for low strings/notes than high

Did the ending really happen in Baby Driver?

Where does "0 packages can be updated." come from?

When did Linux kernel become libre software?

How would a aircraft visually signal in distress?



Magento always creates new entries


Cron job always “missed”Magento2 2.1.5 Cronjob doesn't get executed. ID always 0Cron status is always missed in Magento 1.9Cron job creates loads of records in databaseCustom cron job status always pendingcataloginventory_stock_status randomly has missing entriesMagento 2.3 Can't view module's front end page output?What creates references? I've been unable to find the source of a broken referenceMagento2: Order summary always expandedCron Job status always missed/ not running Magento 2






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








1















I have a little problem. I am currently working on an synchronize job for cron.



The sync function just gets the newest elements from an api and updates in the Magento db. The Magento version is: 2.3.1 .



Here is the function:



 public function synchronize()

$writer = new Stream(BP . '/var/log/cron.log');
$logger = new Logger();
$logger->addWriter($writer);

$login = $this->login();

$dateTimestamp = $this->getLatestDate('/tmp/marketsSync.txt');

$items = $this->getNewestItems($dateTimestamp, $login);

foreach ($items as $item)
$srcItem = $this->_marketFactory->create();
$srcItem->setContent($item);

$marketCollection = $this->_marketCollectionFactory->create();
$marketCollection
->addFieldToSelect('*')
->addFieldToFilter('id_location', ['eq' => $srcItem->getData('id_location')])
->load();

$logger->info('found? :'. $marketCollection->getSize());

if ($marketCollection->getSize())
$tgtItem = $marketCollection->getFirstItem();

$srcTime = strtotime($srcItem->getData('date_upd'));
$tgtTime = strtotime($tgtItem->getData('date_upd'));

if ($srcTime > $tgtTime)
$this->updateElement($tgtItem, $srcItem);

else
$logger->info('create');
$this->createElement($srcItem, $marketCollection);



$this->setLatestDate('/tmp/marketsSync.txt', date("Y-m-d H:i:s") );


public function createElement(Synchronizable $obj)

$item = $this->_marketFactory->create();
$item->setContent($obj->getData());
$item = $item->save();


public function updateElement(Synchronizable $tgtObj, Synchronizable $srcObj)

$writer = new Stream(BP . '/var/log/cron.log');
$logger = new Logger();
$logger->addWriter($writer);

$tgtObj->setContent($srcObj->getData());

$logger->info($tgtObj->getData());

$tgtObj->save();



I've got the Object to update from the marketCollection via getFirstItem(). Now in the updateElement() function i use the the api data to update the object with



$tgtObj->setContent($srcObj->getData());


This function is just a foreach loop:



 public function setContent($content)

foreach ($content AS $key => $value)
$this->setData($key, $value);




I know that this method is already deprecated, but why does save allways create a new entry? (it creates the same data but with a new id)










share|improve this question
























  • At ` $this->updateElement($tgtItem, $srcItem);` , $srcItem is an single field valuepublic function updateElement(Synchronizable $tgtObj, Synchronizable $srcObj) but here object

    – Amit Bera
    May 29 at 10:31

















1















I have a little problem. I am currently working on an synchronize job for cron.



The sync function just gets the newest elements from an api and updates in the Magento db. The Magento version is: 2.3.1 .



Here is the function:



 public function synchronize()

$writer = new Stream(BP . '/var/log/cron.log');
$logger = new Logger();
$logger->addWriter($writer);

$login = $this->login();

$dateTimestamp = $this->getLatestDate('/tmp/marketsSync.txt');

$items = $this->getNewestItems($dateTimestamp, $login);

foreach ($items as $item)
$srcItem = $this->_marketFactory->create();
$srcItem->setContent($item);

$marketCollection = $this->_marketCollectionFactory->create();
$marketCollection
->addFieldToSelect('*')
->addFieldToFilter('id_location', ['eq' => $srcItem->getData('id_location')])
->load();

$logger->info('found? :'. $marketCollection->getSize());

if ($marketCollection->getSize())
$tgtItem = $marketCollection->getFirstItem();

$srcTime = strtotime($srcItem->getData('date_upd'));
$tgtTime = strtotime($tgtItem->getData('date_upd'));

if ($srcTime > $tgtTime)
$this->updateElement($tgtItem, $srcItem);

else
$logger->info('create');
$this->createElement($srcItem, $marketCollection);



$this->setLatestDate('/tmp/marketsSync.txt', date("Y-m-d H:i:s") );


public function createElement(Synchronizable $obj)

$item = $this->_marketFactory->create();
$item->setContent($obj->getData());
$item = $item->save();


public function updateElement(Synchronizable $tgtObj, Synchronizable $srcObj)

$writer = new Stream(BP . '/var/log/cron.log');
$logger = new Logger();
$logger->addWriter($writer);

$tgtObj->setContent($srcObj->getData());

$logger->info($tgtObj->getData());

$tgtObj->save();



I've got the Object to update from the marketCollection via getFirstItem(). Now in the updateElement() function i use the the api data to update the object with



$tgtObj->setContent($srcObj->getData());


This function is just a foreach loop:



 public function setContent($content)

foreach ($content AS $key => $value)
$this->setData($key, $value);




I know that this method is already deprecated, but why does save allways create a new entry? (it creates the same data but with a new id)










share|improve this question
























  • At ` $this->updateElement($tgtItem, $srcItem);` , $srcItem is an single field valuepublic function updateElement(Synchronizable $tgtObj, Synchronizable $srcObj) but here object

    – Amit Bera
    May 29 at 10:31













1












1








1








I have a little problem. I am currently working on an synchronize job for cron.



The sync function just gets the newest elements from an api and updates in the Magento db. The Magento version is: 2.3.1 .



Here is the function:



 public function synchronize()

$writer = new Stream(BP . '/var/log/cron.log');
$logger = new Logger();
$logger->addWriter($writer);

$login = $this->login();

$dateTimestamp = $this->getLatestDate('/tmp/marketsSync.txt');

$items = $this->getNewestItems($dateTimestamp, $login);

foreach ($items as $item)
$srcItem = $this->_marketFactory->create();
$srcItem->setContent($item);

$marketCollection = $this->_marketCollectionFactory->create();
$marketCollection
->addFieldToSelect('*')
->addFieldToFilter('id_location', ['eq' => $srcItem->getData('id_location')])
->load();

$logger->info('found? :'. $marketCollection->getSize());

if ($marketCollection->getSize())
$tgtItem = $marketCollection->getFirstItem();

$srcTime = strtotime($srcItem->getData('date_upd'));
$tgtTime = strtotime($tgtItem->getData('date_upd'));

if ($srcTime > $tgtTime)
$this->updateElement($tgtItem, $srcItem);

else
$logger->info('create');
$this->createElement($srcItem, $marketCollection);



$this->setLatestDate('/tmp/marketsSync.txt', date("Y-m-d H:i:s") );


public function createElement(Synchronizable $obj)

$item = $this->_marketFactory->create();
$item->setContent($obj->getData());
$item = $item->save();


public function updateElement(Synchronizable $tgtObj, Synchronizable $srcObj)

$writer = new Stream(BP . '/var/log/cron.log');
$logger = new Logger();
$logger->addWriter($writer);

$tgtObj->setContent($srcObj->getData());

$logger->info($tgtObj->getData());

$tgtObj->save();



I've got the Object to update from the marketCollection via getFirstItem(). Now in the updateElement() function i use the the api data to update the object with



$tgtObj->setContent($srcObj->getData());


This function is just a foreach loop:



 public function setContent($content)

foreach ($content AS $key => $value)
$this->setData($key, $value);




I know that this method is already deprecated, but why does save allways create a new entry? (it creates the same data but with a new id)










share|improve this question
















I have a little problem. I am currently working on an synchronize job for cron.



The sync function just gets the newest elements from an api and updates in the Magento db. The Magento version is: 2.3.1 .



Here is the function:



 public function synchronize()

$writer = new Stream(BP . '/var/log/cron.log');
$logger = new Logger();
$logger->addWriter($writer);

$login = $this->login();

$dateTimestamp = $this->getLatestDate('/tmp/marketsSync.txt');

$items = $this->getNewestItems($dateTimestamp, $login);

foreach ($items as $item)
$srcItem = $this->_marketFactory->create();
$srcItem->setContent($item);

$marketCollection = $this->_marketCollectionFactory->create();
$marketCollection
->addFieldToSelect('*')
->addFieldToFilter('id_location', ['eq' => $srcItem->getData('id_location')])
->load();

$logger->info('found? :'. $marketCollection->getSize());

if ($marketCollection->getSize())
$tgtItem = $marketCollection->getFirstItem();

$srcTime = strtotime($srcItem->getData('date_upd'));
$tgtTime = strtotime($tgtItem->getData('date_upd'));

if ($srcTime > $tgtTime)
$this->updateElement($tgtItem, $srcItem);

else
$logger->info('create');
$this->createElement($srcItem, $marketCollection);



$this->setLatestDate('/tmp/marketsSync.txt', date("Y-m-d H:i:s") );


public function createElement(Synchronizable $obj)

$item = $this->_marketFactory->create();
$item->setContent($obj->getData());
$item = $item->save();


public function updateElement(Synchronizable $tgtObj, Synchronizable $srcObj)

$writer = new Stream(BP . '/var/log/cron.log');
$logger = new Logger();
$logger->addWriter($writer);

$tgtObj->setContent($srcObj->getData());

$logger->info($tgtObj->getData());

$tgtObj->save();



I've got the Object to update from the marketCollection via getFirstItem(). Now in the updateElement() function i use the the api data to update the object with



$tgtObj->setContent($srcObj->getData());


This function is just a foreach loop:



 public function setContent($content)

foreach ($content AS $key => $value)
$this->setData($key, $value);




I know that this method is already deprecated, but why does save allways create a new entry? (it creates the same data but with a new id)







magento2.3 cron






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited May 29 at 10:23









Amit Bera

60.8k1682181




60.8k1682181










asked May 29 at 9:00









user3541236user3541236

133




133












  • At ` $this->updateElement($tgtItem, $srcItem);` , $srcItem is an single field valuepublic function updateElement(Synchronizable $tgtObj, Synchronizable $srcObj) but here object

    – Amit Bera
    May 29 at 10:31

















  • At ` $this->updateElement($tgtItem, $srcItem);` , $srcItem is an single field valuepublic function updateElement(Synchronizable $tgtObj, Synchronizable $srcObj) but here object

    – Amit Bera
    May 29 at 10:31
















At ` $this->updateElement($tgtItem, $srcItem);` , $srcItem is an single field valuepublic function updateElement(Synchronizable $tgtObj, Synchronizable $srcObj) but here object

– Amit Bera
May 29 at 10:31





At ` $this->updateElement($tgtItem, $srcItem);` , $srcItem is an single field valuepublic function updateElement(Synchronizable $tgtObj, Synchronizable $srcObj) but here object

– Amit Bera
May 29 at 10:31










1 Answer
1






active

oldest

votes


















0














I found out what the problem was. I had overridden getIdentities but the name was not right.



In the Model now:



 /**
* Get ID
*
* @return int|null
*/
public function getId()

return $this->getData('location_id');


/**
* Return identities
* @return string[]
*/
public function getIdentities()

return [self::CACHE_TAG . '_' . $this->getId()];



And now it works.






share|improve this answer























    Your Answer








    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "479"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: false,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f276541%2fmagento-always-creates-new-entries%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    I found out what the problem was. I had overridden getIdentities but the name was not right.



    In the Model now:



     /**
    * Get ID
    *
    * @return int|null
    */
    public function getId()

    return $this->getData('location_id');


    /**
    * Return identities
    * @return string[]
    */
    public function getIdentities()

    return [self::CACHE_TAG . '_' . $this->getId()];



    And now it works.






    share|improve this answer



























      0














      I found out what the problem was. I had overridden getIdentities but the name was not right.



      In the Model now:



       /**
      * Get ID
      *
      * @return int|null
      */
      public function getId()

      return $this->getData('location_id');


      /**
      * Return identities
      * @return string[]
      */
      public function getIdentities()

      return [self::CACHE_TAG . '_' . $this->getId()];



      And now it works.






      share|improve this answer

























        0












        0








        0







        I found out what the problem was. I had overridden getIdentities but the name was not right.



        In the Model now:



         /**
        * Get ID
        *
        * @return int|null
        */
        public function getId()

        return $this->getData('location_id');


        /**
        * Return identities
        * @return string[]
        */
        public function getIdentities()

        return [self::CACHE_TAG . '_' . $this->getId()];



        And now it works.






        share|improve this answer













        I found out what the problem was. I had overridden getIdentities but the name was not right.



        In the Model now:



         /**
        * Get ID
        *
        * @return int|null
        */
        public function getId()

        return $this->getData('location_id');


        /**
        * Return identities
        * @return string[]
        */
        public function getIdentities()

        return [self::CACHE_TAG . '_' . $this->getId()];



        And now it works.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered May 29 at 13:52









        user3541236user3541236

        133




        133



























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Magento Stack Exchange!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f276541%2fmagento-always-creates-new-entries%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Grendel Contents Story Scholarship Depictions Notes References Navigation menu10.1093/notesj/gjn112Berserkeree

            Area configuration aggregation error after install Porto themeMagento 2.1 CE Installed but front/backend not loading/workingCSS not loading on page within Magento 2 pageCannot install module in Magento 2no commands defined in the “setup” namespace. in Magento2Magento 2: Static files are present but shows 404Why do i have to always run the commands to clean cache in Magento 2.1.8?Failure reason: 'Unable to unserialize value.'Error 500 after magento migrationIn production mode the site does not loadMagento 2 : Error 500 after installing

            Middle Expansion Olielle Resaix Definition: Uttering songs of triumph shouting with joy triumphant exulting Sejunction Journal 붙다 달 고급 품목 외출 The stretch trades the screeching tin. Definition: The act of speaking with a drawl a drawl Cough Sand Definition: An uproar a quarrel a noisy outbreak Shake Iron Publicize Horse House Baby 사과 Resaix Flaggy Jelly Temporary Unequaled Puppet A drop in the bucket Shrew 성격 회원 성질 미팅 The burn frames the tacky quality. Materialistic The smoke reduces the way. Yammoe Nondescript Cheek 얼굴 배 약하다 날리다 타다 The illegal country shows the iron. Help Rule Drearien Smoke Teaching Meaty Wasp Abraham Lincoln Jaws 진심 수리하다 Size Cork Idea Convert Think Lark John Lennon 거울 청소 군 추천하다 아이스크림