Activate a Logic Hook

Hi.

I made two modules in SuiteCRM 78.2 (airplane and fligth), with relationship ‘One to Many’ an Airplane have many Flights, a flight is to one airplane.

The airplane have a field of total hours flying, also de flight has a field of hours of flight.

So, i need the field of tottal hours flying changes when a flight is registered; for that i made a logic hook like this:

<instance_suitecrm>/custom/modules/flight/Logic_Hook.php:


<?php
  $hook_version = 1;
  $hook_array = Array();

  $hook_array['after_save'] = Array();
  $hook_array['after_save'][] = Array(
    50,
    'updateHoursComponents',
    'custom/modules/flight/UpdaterHours.php',
    'UpdaterComponentsHours',
    'updateComponentHours'
  );

Then i have the file <instance_suitecrm>/custom/modules/flight/UpdaterHous.php:


<?php
class UpdaterComponentsHours{
  function updateComponentHours($bean, $event, $arguments){
    // Get hours
    $hours = $bean->hours_fly;

    // Get Airplane related
   // The relation with airplane is named flight_airplane
   // The field is name airplane
    $airplanes = $bean->get_linked_beans('flight_airplane', 'airplane');

    $airplane = $airplanes[0]; // Get the first record of the array

    updateAirplaneHours($airplane, $hours);
}

function updateAirplaneHours($airplaneBean, $hours_fligth){
    // Update the hours of operation of an airplane
    $airplaneBean->total_hours_operation = $airplaneBean->total_hours_operation + $hours_fligth;
    $airplaneBean->save(); // update the record in database
  }
}

The problem is when i save the record the Logic_Hooks.php is not activated, but i cannot see where is my problem or am i missing some action.

Hope you can help me.

Thanks.

The file name should be Logic_Hooks.php, not Logic_Hook.php (you’re missing an “s”)

The other file name should be UpdaterHours.php, not UpdaterHous.php (you’re missing an “r”)

good luck

1 Like

Thanks pgr, that works.

My logic hook is cycling after save, what could be happening?