Mass Recalculate Formula

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • talles.amadeu
    Junior Member
    • Jan 2020
    • 27

    Mass Recalculate Formula

    Hey guys.

    I have to recalculate a formula in about 500k records.

    Is there a way to do it via terminal?
  • yuri
    Member
    • Mar 2014
    • 8440

    #2
    You can write a PHP script and run it in CLI.

    PHP Code:
    <?php
    
    include "bootstrap.php";
    
    use Espo\Core\Application;
    
    $container = (new Application())->getContainer();
    
    $entityManager = $container->get('entityManager');
    
    $collection = $entityManager
        ->getRepository('NameOfYourEntityType')
        ->where(['someField' => 'someValue']) // where clause if needed, omit to fetch all records
        ->sth() // makes memory consuming much less
        ->find();
    
    foreach ($collection as $entity) {
        $entityManager->saveEntity($entity); // saving will re-calculate formula
    }
    Last edited by yuri; 02-11-2021, 07:34 PM.
    If you find EspoCRM good, we would greatly appreciate if you could give the project a star on GitHub. We believe our work truly deserves more recognition. Thanks.

    Comment


    • item
      item commented
      Editing a comment
      Yuri, many thanks for this sample

    • talles.amadeu
      talles.amadeu commented
      Editing a comment
      Thanks Yuri. I'm gonna give it a try. Thanks a lot!
Working...