socialengine event for send message - event-handling

I am making module for SocialEngine 4.8.9. Basically I am buildin chat module and I want to sync SocialEngine message with my chat box. So I need an event that is called after sending message so that I can insert into my table.
Or is there any event that is called after inserting values into database.

SocialEngine has many hooks and you can attach your operations to these hooks. One of these hooks is onItemCreateAfter. This event will be called when a model item is created in the database.
If you check the Messages module's manifest file you'll see the messages module have 2 model items named messages_message and messages_conversation so you can use the onItemCreateAfter hook to attach your operations when any of these 2 items are created.
For this example let's say you have created a module via SocialEngine's SDK and your module name is mymodule. You can begin using the hook in 2 steps:
Attaching your operations to the onItemCreateAfter hook in your module's manifest file. You can check manifest files from other modules to get an idea how you should write the following code in the manifest array.
File : application/modules/Mymodule/settings/manifest.php
'hooks' => array(
array(
'event' => 'onItemCreateAfter',
'resource' => 'Mymodule_Plugin_Core',
),
),
Create the plugin file that will be called by the hook. in the following code $payload object will contains the message item.
File : application/modules/Mymodule/Plugin/Core.php
class Mymodule_Plugin_Core
{
public function onItemCreateAfter($event)
{
$payload = $event->getPayload();
if( $payload instanceof Core_Model_Item_Abstract ) {
//Your code here
}
}
}

There is no default hook for composing message.You can create new custom hook for the messages and can call that hook when everytime message is send.
Example:http://social-engine-tutorials.blogspot.in/2012/03/social-engine-4-hook-example.html

Related

How to send email notification after creating lead in sugarcrm through webservice(nusoap)

I have successfully created a lead in sugarcrm 6.5 using nusoap. But now problem is, How to send email notification to assigned user?
Please help me!!
Based on your situation, what I would do is use a after_save logic hook to send your email. Logic Hooks allow you to plug into the SugarCRM logic. The code below allows you to do something after a Lead is saved.
Create a logic_hooks.php or add the following if it already exists in custom/modules/Leads/logic_hooks.php
<?php
$hook_version = 1;
$hook_array = Array();
$hook_array['after_save'] = Array();
$hook_array['after_save'][] = Array(1, 'Send Notification', 'custom/modules/Leads/Leads_custom.php','Leads_custom', 'send_notification');
After any Lead is saved, it'll run the following code in custom/modules/Leads/Leads_custom.php
<?php
class Leads_custom
{
function send_notification($bean, $event, $arguments)
{
// write your code here to send the notification to the head(Manager)
}
}
This will fire anytime Leads are created or edited. If you need to only send notifications on new Leads, you can use this technique: http://developers.sugarcrm.com/wordpress/2013/08/21/doing-beforeafter-field-comparisons-in-after_save-logic-hooks/
If you have the process manager available in your Sugar Version (entrprise+) then you just have to create a process definition that triggers an email when a new lead is created. If not then it's a logic hook.

How to call action in some other controller in Mojolicious?

I have an application that uses the Mojolicious framework. I have a table in the database that has a list of error response and additional details associated with it. I have created corresponding Result and Resultset to work with the DB table. There is also a controller to get details about the Error by interacting with the Resultset.
My idea is to Call an action in this controller that would get the details of the error that is passed to it (by another controller) by querying the database, add-in runtime information about the environment that requested for the resource that resulted in the error, create a response and return to the controller that called it.
I am struggling with the call from one controller to another. How do I do it in Mojolicious? I can pass the controller object ($self) to accomplish this, but is there a better way to do it, so that I separate entirely my error handling response from the calling controller?
In Mojolicious, you would probably want to pass that object around with a helper without creating a Mojolicious::Controller out of it:
In your main class:
sub startup {
my $app = shift;
# ...
my $thing = Thing->new(foo => 42);
$app->helper(thing => sub {$thing});
}
In your controller:
sub cool_action {
my $c = shift;
# ...
my $foo = $c->thing->gimmeh_foo('bar');
# ...
}
However, if you would like to prepare something (e.g. databases) for some actions, maybe under is helpful for you:
To share code with multiple nested routes you can [...]
PS: This feature of Mojolicious was previously named Bridges. Answer updated accordingly.

Firefox Addon sdk : comunication between different contentScripts

I have two content Scripts in main.js of Firefox Addon :
contentScript A is inside 'panel' module (module A)
contentScript B is inside 'page-mod' module (module B)
How can they communicate or exchange messages ?
I tried to do this by using the following steps : 1. sending message from contentScript A to AddonScript A 2. sending message from AddonScript A to AddonScript B by including module B in A 3. sending message from AddonScript B to contentScript B.
However , it doesn't work (rather it does work intermittently , may be due to some errors in code).
.
Is this method ok ?
Can any one please comment on any better method ?
.
Thanx
Due to how the SDK's security model, any communication between your panel and your page-mod need to be routed through the main add-on code itself. Here is an example that takes data from a form implemented in a Panel and sends it through the main script into a page-mod:
https://builder.addons.mozilla.org/addon/1035008/latest/
The key piece of code is this one:
var pagemod = require("page-mod").PageMod({
include: [target],
contentScriptFile: [data.url('jquery-1.7.1.min.js'), data.url('page-mod.js')],
onAttach: function(worker) {
// console.log('attached...');
// when we get a panel-message event from the panel
panel.port.on('panel-message', function(data) {
// we emit the same message through to the page-mod
worker.port.emit('panel-message', data);
});
}
});
You'll notice that, when the page-mod is attached, I set up the panel instance to catch the 'panel-message' event and then emit it directly into the current page-mod worker.

Custom mail spool in symfony 1.4

Can anyone give me a rough idea or link to instructions on how to create custom symfony swift mailer spool? I currently have the basic Doctrine spool which sends messages and deletes queue item.
I would like to do following:
Have a field with status (Sent, Unsent, Failed, Email does not exist, etc)
Update status field instead of deleting queue item on send
I've never done such functionality myself, but it seems like you can create your own spool class:
<?php
class Swift_MySpool extends Swift_DoctrineSpool {}
Have a field with status (Sent, Unsent, Failed, Email does not exist, etc)
The Swift_DoctrineSpool class supports an option called model, where you can pass a name of class to store your mail at. So, just creating your custom model will take effect.
Update status field instead of deleting queue item on send
Override queueMessage() and flushQueue() methods in your class and refer to Swift_DoctrineSpool at symfony API.
Hope this will help.

What is the best way to log errors in Zend Framework 1?

We built an app in Zend Framework (v1) and have not worked a lot in setting up error reporting and logging. Is there any way we could get some level or error reporting without too much change in the code? Is there a ErrorHandler plugin available?
The basic requirement is to log errors that happens within the controller, missing controllers, malformed URLs, etc.
I also want to be able to log errors within my controllers. Will using error controller here, help me identify and log errors within my controllers? How best to do this with minimal changes?
I would use Zend_Log and use the following strategy.
If you are using Zend_Application in your app, there is a resource for logging. You can read more about the resource here
My advice would be to choose between writing to a db or log file stream. Write your log to a db if you plan on having some sort of web interface to it, if not a flat file will do just fine.
You can setup the logging to a file with this simple example
resources.log.stream.writerName = "Stream"
resources.log.stream.writerParams.stream = APPLICATION_PATH "/../data/logs/application.log"
resources.log.stream.writerParams.mode = "a"
resources.log.stream.filterName = "Priority"
resources.log.stream.filterParams.priority = 4
Also, I would suggest sending Critical errors to an email account that is checked regularly by your development team. The company I work for sends them to errors#companyname.com and that forwards to all of the developers from production sites.
From what I understand, you can't setup a Mail writer via a factory, so the resource won't do you any good, but you can probably set it up in your ErrorController or Bootstrap.
$mail = new Zend_Mail();
$mail->setFrom('errors#example.org')
->addTo('project_developers#example.org');
$writer = new Zend_Log_Writer_Mail($mail);
// Set subject text for use; summary of number of errors is appended to the
// subject line before sending the message.
$writer->setSubjectPrependText('Errors with script foo.php');
// Only email warning level entries and higher.
$writer->addFilter(Zend_Log::WARN);
$log = new Zend_Log();
$log->addWriter($writer);
// Something bad happened!
$log->error('unable to connect to database');
// On writer shutdown, Zend_Mail::send() is triggered to send an email with
// all log entries at or above the Zend_Log filter level.
You will need to do a little work to the above example but the optimal solution would be to grab the log resource in your bootstrap file, and add the email writer to it, instead of creating a second log instance.
You can use Zend_Controller_Plugin_ErrorHandler . As you can see on the documentation page there is an example that checks for missing controller/action and shows you how to set the appropriate headers.
You can then use Zend_Log to log your error messages to disk/db/mail.