Announcement

Collapse
No announcement yet.

Mass Recalculate Formula

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Mass Recalculate Formula

    Hey guys.

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

    Is there a way to do it via terminal?

  • #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.

    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...
X