Sugar 7 - Prevent certain records from being deleted

Hi, in sugar 6, I could prevent a record being deleted by doing this in custom/modules/Accounts/controller.php:

<?php

if (!defined('sugarEntry'))
    define('sugarEntry', true);

require_once 'include/MVC/Controller/SugarController.php';

class AccountsController extends SugarController {

    function action_delete() {
        if (empty($this->bean->some_field_c)) {
            parent::action_delete();
        }

        return;
    }
}

So the account would be deleted as long as some_field_c was empty. How can I do the same thing in sugar 7? It looks like custom/modules/Accounts/controller.php is no longer read. I know I can edit the record.js for accounts and catch the delete trigger and stop it there, but this is client side, plus I would need to do it for the recordlist view, massupdate view, etc. It would also mean that other apps accessing the sugar API delete these records.

I also tried the before_delete logic hook which does get called but you can't intercept the delete here.

Thanks.

Parents Reply Children
  • Thanks for that. I overrode the deleteRecord() method from the ModuleAPI class and it works. I guess the only other thing to add would be to make it say an error ("Can't delete this account") or something but at least I can now prevent accounts from being deleted.

    Also I noticed that if a module is ran in backward compatibility mode then it does read custom/modules/<module>/controller.php but not if the module is running in sugar 7 mode.

    Thanks for the help.