Results 1 to 8 of 8

Thread: post_install script mysteriouly not working

  1. #1
    metaphys Guest

    Default post_install script mysteriouly not working

    hello

    I'm trying to launch some code in a post_install.php script for an extension. The code get started and executed ok (I've been able to test this by echoing diverses variables during the process that get correctly displayed. The main function called is quited trivial:
    Code:
      public function resetContactsField() {
             require_once('modules/Contacts/Contact.php');
             $contactObj = new Contact();
             $result = $contactObj->get_full_list();
             foreach($result as $contact) {
                 $contact->saints_days_c = $this->get_saints_days($contact->first_name);
                 echo $contact->saints_days_c;       <-----THIS VARIABLE VALUES APPEARS CORRECTLY ON THE INSTALLER PAGE PROVING THE FUNCTION GET LAUNCHED AND WORKS CORRECTLY
                 $contact->save();
             }
      }
    The purpose is to update the custom saints_days_c field with a function generated value. However those field remains desperately blank after the installation of the package...
    this is the content of post_install.php
    Code:
    function post_install() {
    	//we set the saints days values for all user
        require_once('custom/Extension/modules/Contacts/Ext/saints_days.class.php');
         $saintObj = new saintsDays();
         $saintObj->resetContactsField();
    }
    The very same code added to a custom page after installation of the module generate the field correctly. So my question would be square down to be very specific: why is the $contact->save(); instruction not working in the post_install context?
    Should I load some extra file to have mysql access perhaps?

    thanks in advance

  2. #2
    metaphys Guest

    Default Re: post_install script mysteriouly not working

    After slow and painful debug I notice I had a logic hook calling a function like that
    static public function onSaveFunction(&$bean, $event, $arguments)
    So I had to had a
    if(isset($bean, $event, $arguments)) {
    around it to avoid the case of the installer where those variable do not get defined.

    So now I can set nomal field through save(). Still my custom don't get defined and it definitively comes frome the save(). Are there some protection mechanism that could explain why the save() doesn't works?

  3. #3
    metaphys Guest

    Default Re: post_install script mysteriouly not working

    Ok so I've made a very simplified package to cut off all possible interaction. Custom field do not get modified by save() and any operation to assign or save a value to it from a post_install script ends up with the apache server saying:
    Code:
    PHP Notice:  Undefined property: Contact::$new_field_c in [...]cache/upgrades/temp/fwmlnx/scripts/post_install.php on line 16, referer: http://localhost/SugarCE/index.php?module=Administration&view=module&action=UpgradeWizard_prepare
    I think that it's related to the fact that the field get added to the database structure but does not get added to a contact's table until an actual value get set to it. This is why save() won't work.
    For custom admin setting the function saveSettings allow to turnaround that. Is there an equivalent for records?

  4. #4
    kir
    kir is offline Sugar Community Member
    Join Date
    Nov 2011
    Posts
    702

    Default Re: post_install script mysteriouly not working

    Quote Originally Posted by metaphys View Post
    hello

    I'm trying to launch some code in a post_install.php script for an extension. The code get started and executed ok (I've been able to test this by echoing diverses variables during the process that get correctly displayed. The main function called is quited trivial:
    Code:
      public function resetContactsField() {
             require_once('modules/Contacts/Contact.php');
             $contactObj = new Contact();
             $result = $contactObj->get_full_list();
             foreach($result as $contact) {
                 $contact->saints_days_c = $this->get_saints_days($contact->first_name);
                 echo $contact->saints_days_c;       <-----THIS VARIABLE VALUES APPEARS CORRECTLY ON THE INSTALLER PAGE PROVING THE FUNCTION GET LAUNCHED AND WORKS CORRECTLY
                 $contact->save();
             }
      }
    The purpose is to update the custom saints_days_c field with a function generated value. However those field remains desperately blank after the installation of the package...
    this is the content of post_install.php
    Code:
    function post_install() {
        //we set the saints days values for all user
        require_once('custom/Extension/modules/Contacts/Ext/saints_days.class.php');
         $saintObj = new saintsDays();
         $saintObj->resetContactsField();
    }
    The very same code added to a custom page after installation of the module generate the field correctly. So my question would be square down to be very specific: why is the $contact->save(); instruction not working in the post_install context?
    Should I load some extra file to have mysql access perhaps?

    thanks in advance
    i think that $contact in foreach is not the Contact bean, so use next code:

    PHP Code:
    public function resetContactsField() {
             require_once(
    'modules/Contacts/Contact.php');
             
    $contactObj = new Contact();
             
    $result $contactObj->get_full_list();
             foreach(
    $result as $contact) {
    $renewContact = new Contact();
    $renewContact->retrieve($contact->id);
                 
    $renewContact->saints_days_c $this->get_saints_days($contact->first_name);
                 echo 
    $renewContact->saints_days_c;       <-----THIS  VARIABLE VALUES APPEARS CORRECTLY ON THE INSTALLER PAGE PROVING THE  FUNCTION GET LAUNCHED AND WORKS CORRECTLY
                 $renewContact
    ->save();
             }
      } 
    Last edited by kir; 2013-03-31 at 07:17 PM.

  5. #5
    metaphys Guest

    Default Re: post_install script mysteriouly not working

    Quote Originally Posted by kir View Post
    i think that $contact in foreach is not the Contact bean, so use next code:

    PHP Code:
    public function resetContactsField() {
             require_once(
    'modules/Contacts/Contact.php');
             
    $contactObj = new Contact();
             
    $result $contactObj->get_full_list();
             foreach(
    $result as $contact) {
    $renewContact = new Contact();
    $renewContact->retrieve($contact->id);
                 
    $renewContact->saints_days_c $this->get_saints_days($contact->first_name);
                 echo 
    $renewContact->saints_days_c;       <-----THIS  VARIABLE VALUES APPEARS CORRECTLY ON THE INSTALLER PAGE PROVING THE  FUNCTION GET LAUNCHED AND WORKS CORRECTLY
                 $renewContact
    ->save();
             }
      } 
    Thank you for the answer!
    I also wondered that and tested something close to your proposal. Still no luck.
    However, as I wrote before the code is working if launched outside the installer (Waiting for a better solution I've added a message after install that point to a admin page that launch the very same function with success).
    I'm a bit surprise because setting some custom field from a post_install script seems quite a classic task to perform for a package. I wonder if I shouldn't post a bug report... (using 6.5.8)

  6. #6
    metaphys Guest

    Default Re: post_install script mysteriouly not working

    Ok so to prove my point I've made a minimal package, I'd be curious to know if the test_field_c get populated on anyone else install. On mine it won't.

    again should this be reported as a bug?
    Attached Files Attached Files

  7. #7
    kir
    kir is offline Sugar Community Member
    Join Date
    Nov 2011
    Posts
    702

    Default Re: post_install script mysteriouly not working

    Quote Originally Posted by metaphys View Post
    Ok so to prove my point I've made a minimal package, I'd be curious to know if the test_field_c get populated on anyone else install. On mine it won't.

    again should this be reported as a bug?
    hi

    i tortured my sugar and found out what is the problem
    The problem is when you start to populate just created custom field the database is not rebuilded yet
    so to make you post_install work you need to rebuild DB first
    PHP Code:
        require_once('modules/Administration/QuickRepairAndRebuild.php');
        
    $randc = new RepairAndClear();
        
    $randc->repairAndClearAll(array('clearAll'),array(translate('LBL_ALL_MODULES')), falsefalse); 
    working module is attached
    Attached Files Attached Files

  8. #8
    metaphys Guest

    Default Re: post_install script mysteriouly not working

    Oh my god thank you so much! I've been stuck on this one for two weeks now!!!
    Still: is it the expected behaviour? shouldn't the post_install script get fire after the db rebuild? Shouldn't I report this as a bug?

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Ajax script not working if a db script is run
    By atulnbd in forum Developer Help
    Replies: 1
    Last Post: 2011-10-08, 02:38 PM
  2. pre_install.php and post_install.php
    By jim.thornton in forum Developer Help
    Replies: 0
    Last Post: 2009-03-19, 11:07 PM
  3. How to run sql file from post_install?
    By gsadmin in forum Developer Help
    Replies: 4
    Last Post: 2008-10-08, 03:31 PM
  4. Mouler Loader run post_install script on uninstall
    By gacevedo in forum Developer Help
    Replies: 7
    Last Post: 2008-01-07, 08:11 PM
  5. Java Script not working after translation
    By jacekskowron in forum Help
    Replies: 0
    Last Post: 2007-12-19, 10:31 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •