1

Help, built new extension, form displays, accepts input, but never updates the database

The returns I get from all functions do not show errors.

What the heck am I doing wrong????

It's going to be flipping obvious when its pointed out, but I've been pulling my hair out with this.

So this:

W:\bluline\drupal\sites\all\modules\civicrm\ext\net.ssl-uk.sslext\CRM\Sslext\Form\System.php

<?php
use CRM_sslext_ExtensionUtil as E;

/** Form controller class */
class CRM_sslext_Form_System extends CRM_Core_Form {

public function postProcess() 
{
    $result = civicrm_api3('Sslsystem', 'create', [ 'id' => 1,  'sysKey' => "abc", 'sysValue' => '123']);
}
}

Calls this:

W:\bluline\drupal\sites\all\modules\civicrm\ext\net.ssl-uk.sslext\api\v3\Sslsystem\Create.php

<?php
use CRM_sslext_ExtensionUtil as E;

function civicrm_api3_sslsystem_create($params) {
    $result = _civicrm_api3_basic_create(_civicrm_api3_get_BAO(__FUNCTION__), $params);
    return $result;
}

Which calls this:

W:\bluline\drupal\sites\all\modules\civicrm\ext\net.ssl-uk.sslext\api\v3\Sslsystem\Create.php

<?php
use CRM_sslext_ExtensionUtil as E;

class CRM_sslext_BAO_sslsystem extends CRM_sslext_DAO_sslsystem {
  public static function create($params) {
    $className = 'CRM_sslext_DAO_sslsystem';
    $entityName = 'Sslsystem';
    $hook = empty($params['id']) ? 'create' : 'edit';

    CRM_Utils_Hook::pre($hook, $entityName, CRM_Utils_Array::value('id', $params), $params);
    $instance = new $className();
    $instance->copyValues($params);
    $instance->save();
    CRM_Utils_Hook::post($hook, $entityName, $instance->id, $instance);
    return $instance;
  } 
}
  • There's nothing wrong with this on first glance. If you use the API Explorer (Support menu » Developer » API Explorer v3), and you make the same API call, does it work? – Jon G - Megaphone Tech Nov 28 '19 at 16:32
  • Nope. Exactly the same, no errors, just no database update. – Simon Walden Nov 28 '19 at 20:46
  • 2
    Answering my own question: The issue was with the 'id' => 1. As ID 1 did not exist in database it did not create. Removing the 'id' parameter so it was empty correctly creates the record. Said it would be blindingly obvious once I spotted it. – Simon Walden Nov 29 '19 at 8:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.