AnsweredAssumed Answered

Scheduler is Failling in Cron run

Question asked by Giovanni Marazzi on Aug 8, 2018
Latest reply on Aug 10, 2018 by Giovanni Marazzi

Hi,

 

This scheduler works fine until the point that it tries to save a bean. Any help is much appreciated.

 

<?php

    /**
     * Giovanni de Almeida
     */


    array_push($job_strings, 'lftm_it_atualiza_net');

    function lftm_it_atualiza_net() {
       
        $sql = "SELECT T3.id, T5.lftm_net_c FROM pcp01_posconsprincipal T1 ";
          $sql .= "INNER JOIN pcp01_posconsprincipal_contacts_c T2 ON T1.id = T2.pcp01_posconsprincipal_contactspcp01_posconsprincipal_idb ";
          $sql .= "AND T2.deleted = 0 AND T1.deleted = 0 ";
          $sql .= "INNER JOIN contacts T3 ON T3.id = T2.pcp01_posconsprincipal_contactscontacts_ida AND T3.deleted = 0 ";
          $sql .= "INNER JOIN contacts_cstm T4 ON T3.id = T4.id_c ";
          $sql .= "INNER JOIN pcp01_posconsprincipal_cstm T5 ON T5.id_c = T1.id ";
          $sql .= "WHERE T1.deleted = 0 AND DATE(T4.dt_ult_net_c) < DATE(T1.date_entered) ";
          $sql .= "GROUP BY T3.id LIMIT 100";

        $result = $GLOBALS['db'] -> query($sql);

          $GLOBALS['log']->fatal("Iniciando atualização de Net e análise de perfil");
         
        while ($row = $GLOBALS['db'] -> fetchByAssoc($result)) {

            $contact_bean = BeanFactory::retrieveBean('Contacts', $row['id'], array('disable_row_level_security' => true));
            //$user_bean = BeanFactory::retrieveBean('Users', $contact_bean -> assigned_user_id, array('disable_row_level_security' => true));
               $GLOBALS['log']->fatal("Processando contato " . $contact_bean->name);
            if (isset($contact_bean) && isset($contact_bean -> name) && !empty($contact_bean -> name)) {
              
                if ($contact_bean -> lftm_net_c != $row['lftm_net_c']) {

                    if ($row['lftm_net_c'] < 1000)
                         {
                        $contact_bean -> lftm_status_cliente_c = 'Inativo';
                        if ($contact_bean -> lftm_segmentacao_cliente_c != 'Online') {
                            $contact_bean -> lftm_segmentacao_cliente_c = 'Online';
                            $contact_bean -> chk_email_net_c = 1;
                        }
                    }
                    elseif ($row['lftm_net_c'] >= 1000 && $row['lftm_net_c'] < 100000)
                         {
                        $contact_bean -> lftm_status_cliente_c = 'Ativo';
                        if ($contact_bean -> lftm_segmentacao_cliente_c != 'Online') {
                            $contact_bean -> lftm_segmentacao_cliente_c = 'Online';
                            $contact_bean -> chk_email_net_c = 1;
                        }
                    }
                    elseif ($row['lftm_net_c'] >= 100000 && $row['lftm_net_c'] < 300000)
                         {
                        $contact_bean -> lftm_status_cliente_c = 'Ativo';
                        if ($contact_bean -> lftm_segmentacao_cliente_c != 'Plus') {
                            $contact_bean -> lftm_segmentacao_cliente_c = 'Plus';
                            $contact_bean -> chk_email_net_c = 1;
                        }
                    }
                    elseif ($row['lftm_net_c'] >= 300000 && $row['lftm_net_c'] < 1000000)
                         {
                        $contact_bean -> lftm_status_cliente_c = 'Ativo';
                        if ($contact_bean -> lftm_segmentacao_cliente_c != 'Unique') {
                            $contact_bean -> lftm_segmentacao_cliente_c = 'Unique';
                            $contact_bean -> chk_email_net_c = 1;
                        }
                    }
                    elseif ($row['lftm_net_c'] >= 1000000)
                         {
                        $contact_bean -> lftm_status_cliente_c = 'Ativo';
                        if ($contact_bean -> lftm_segmentacao_cliente_c != 'Private') {
                            $contact_bean -> lftm_segmentacao_cliente_c = 'Private';
                            $contact_bean -> chk_email_net_c = 1;
                        }
                    }
                        
                    $contact_bean -> lftm_net_c = $row['lftm_net_c'];
                         $contact_bean -> dt_ult_net_c = date('Y-m-d');
                        
                         $GLOBALS['log']->fatal("Net atualizado");
$contact_bean -> save();
                        
                         $GLOBALS['log']->fatal("Contato atualizado");
                        
                }


            }

        }

        return true;

    }

 

this is the log:

 

Wed Aug  8 20:48:01 2018 [1000][1][FATAL] Processando contato MARTA TISSIANI DE TONI 
Wed Aug  8 20:48:01 2018 [1000][1][FATAL] Processando contato AGENOR DE CARVALHO FILHO
Wed Aug  8 20:48:01 2018 [1000][1][FATAL] Processando contato RODRIGO DA SILVA
Wed Aug  8 20:48:01 2018 [1000][1][FATAL] Processando contato MARIO JOSE ZAMPOLLO
Wed Aug  8 20:48:01 2018 [1000][1][FATAL] Net atualizado
Wed Aug  8 20:48:01 2018 [1000][1][FATAL] Job 9b684b1c-9b4b-11e8-b0b4-02768d5022b5 (Atualiza Net e perfil) failed in CRON run

Best Regards,

Giovanni

Outcomes