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!
Tyson Posted September 18, 2014 Report Posted September 18, 2014 On 9/18/2014 at 9:47 AM, gutterboy said: 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") )
gutterboy Posted September 18, 2014 Author Report Posted September 18, 2014 On 9/18/2014 at 4:48 PM, Tyson said: 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?
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.
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".
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.
gutterboy Posted September 19, 2014 Author Report Posted September 19, 2014 On 9/19/2014 at 12:02 AM, Tyson said: 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.
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.
Blesta Addons Posted September 20, 2014 Report Posted September 20, 2014 On 9/20/2014 at 9:36 AM, gutterboy said: 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 .
gutterboy Posted September 20, 2014 Author Report Posted September 20, 2014 On 9/20/2014 at 10:10 AM, naja7host said: 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?
Blesta Addons Posted September 20, 2014 Report Posted September 20, 2014 On 9/20/2014 at 10:25 AM, gutterboy said: 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 .
gutterboy Posted September 21, 2014 Author Report Posted September 21, 2014 On 9/20/2014 at 9:41 PM, naja7host said: 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!
Recommended Posts
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now