gutterboy Posted September 18, 2014 Report Posted September 18, 2014 I am having problems with triggering the method unless I name the method name run. For example I have this code: public function getEvents() { return array( array( 'event' => "Transactions.add", 'callback' => array("this", "notify") ), array( 'event' => "Transactions.edit", 'callback' => array("this", "notify_edit") ) ); } public function notify($event) { // Get params $params = $event->getParams(); // Set transaction id $transaction_id = $params['transaction_id']; if (!isset($this->Transactions)) { Loader::loadModels($this, array("Transactions")); } // Now get transaction details $transaction_details = $this->Transactions->get($transaction_id); file_put_contents(dirname(__FILE__) . '/output.txt', print_r($transaction_details, true)); } public function notify_edit($event) { // Get params $params = $event->getParams(); // Set transaction id $transaction_id = $params['transaction_id']; if (!isset($this->Transactions)) { Loader::loadModels($this, array("Transactions")); } // Now get transaction details $transaction_details = $this->Transactions->get($transaction_id); file_put_contents(dirname(__FILE__) . '/output_edit.txt', print_r($transaction_details, true)); } This will not trigger the notify method at all; however if i change the method name to run it will trigger it. Another problem is I cannot get the Transactions.edit method to run. I even changed the name of the method to run but it never would trigger. Help! Quote
Tyson Posted September 18, 2014 Report Posted September 18, 2014 public function getEvents() { return array( array( 'event' => "Transactions.add", 'callback' => array("this", "notify") ), array( 'event' => "Transactions.edit", 'callback' => array("this", "notify_edit") ) ); } Your events define a callback array with the string "this". I assume you're using this to register events, in which case the first index should be a reference to the object whose method (second index) is to be called. e.g. array( 'event' => "Transactions.edit", 'callback' => array($this, "notify_edit") ) Quote
gutterboy Posted September 18, 2014 Author Report Posted September 18, 2014 Your events define a callback array with the string "this". I assume you're using this to register events, in which case the first index should be a reference to the object whose method (second index) is to be called. e.g. array( 'event' => "Transactions.edit", 'callback' => array($this, "notify_edit") ) Well from what I understood from the docs was that by doing something like what I am doing it should use the callback of $this->notify or $this->notify_edit as it works when I name the method "run" as that is $this->run no? Quote
Tyson Posted September 18, 2014 Report Posted September 18, 2014 Which docs are you referring to? The callback specifies the "notify" and "notify_edit" methods, but does not specify from which class those would be called. Quote
gutterboy Posted September 18, 2014 Author Report Posted September 18, 2014 It was this one: http://docs.blesta.com/display/dev/Plugin+Events But I just had a look at: http://docs.blesta.com/display/dev/Creating+Events and it seems more clear now. So basically I will need to register the callbacks to that event so they get triggered? As for specifying the class, I thought that what was the "this" referred to, so it was a reference to "$this". Quote
Tyson Posted September 19, 2014 Report Posted September 19, 2014 Looks like you're correct, the string "this" is supposed to automatically trigger an object instance from that class. Are you sure your callback is not being called? How are you evaluating whether the method was called? They will only be called if a transaction was successfully added or edited. Quote
gutterboy Posted September 19, 2014 Author Report Posted September 19, 2014 Looks like you're correct, the string "this" is supposed to automatically trigger an object instance from that class. Are you sure your callback is not being called? How are you evaluating whether the method was called? They will only be called if a transaction was successfully added or edited. So I don't need to register it first? Yes I'm sure they aren't being triggered. What I'm doing is I'm recording a payment for a client via admin which adds it to the transactions - if I call the method "run" then it will trigger it (which I can tell as it updates the output.txt file; if I change the name of the method and run that scenario again, the file isn't updated. Same goes for editing a transaction via admin - no creation of output_edit.txt. Quote
gutterboy Posted September 20, 2014 Author Report Posted September 20, 2014 Ok, figured the problem out. If you make any changes to the plugin AFTER you install it, you need to first UNINSTALL it and then INSTALL it again. Quote
Blesta Addons Posted September 20, 2014 Report Posted September 20, 2014 Ok, figured the problem out. If you make any changes to the plugin AFTER you install it, you need to first UNINSTALL it and then INSTALL it again. or you should make the change in your upgrade function and upgrade the plugin from plugins tab . Quote
gutterboy Posted September 20, 2014 Author Report Posted September 20, 2014 or you should make the change in your upgrade function and upgrade the plugin from plugins tab . I'm not sure how that would work? Isn't that more for database changes etc? Quote
Blesta Addons Posted September 20, 2014 Report Posted September 20, 2014 I'm not sure how that would work? Isn't that more for database changes etc? with upgrade function , you shoukd register the new event and delete the old event . look at support manager plugin to insipre the how the upgrade work . Quote
gutterboy Posted September 21, 2014 Author Report Posted September 21, 2014 with upgrade function , you shoukd register the new event and delete the old event . look at support manager plugin to insipre the how the upgrade work . Ok thanks! Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.