On Monday, February 1, 2016 at 12:29:28 PM UTC-8, Avijit Pathania wrote:
>
>
>
> On Monday, February 1, 2016 at 3:19:09 PM UTC-5, RjOllos wrote:
>>
>>
>> Good find. That wasn't obvious from the [components] section of your 
>> trac.ini because Components in the environment "plugins" directory are 
>> enabled unless explicitly disabled in the [components] section. This is the 
>> opposite of plugin in your site-packages directory, which are disabled 
>> unless explicitly enabled in the [components] section of trac.ini. I've 
>> considered the behavior to be confusing and thought about suggesting a 
>> change.
>>
>> Is that the entire plugin, or just a snippet of the plugin code? If 
>> that's the entire plugin, then it does nothing and you can just remove it. 
>> If there's more code, I'd need to see the entire plugin to suggest 
>> modifications, but in short you need to adapt to the new database API. An 
>> outline of database API changes can be found here:
>> http://trac.edgewall.org/wiki/TracDev/DatabaseApi#Trac1.0API
>>
>
>  That was a snippet. Here is the entire code with my edits for version 
> 1.0. Have not had a chance to test it though.
> from trac.ticket.api import ITicketActionController, TicketSystem
> from trac.ticket.default_workflow import ConfigurableTicketWorkflow
> from trac.env import Environment
> import trac.ticket.notification as note
>
> def notify(self, ticket, newticket=True, modtime=None):
>   env = Environment('/mnt/trac/it') <---
>   with env.db_query as db:           <---
>     cursor = db.cursor()                 <---
>     #self.env.log.critical(ticket.id)
>     cursor.execute("SELECT cc,reporter,owner,status FROM ticket WHERE 
> id=%s", (t
> icket.id))
>     row = cursor.fetchone()
>     if row:
>         self.reporter = row[1]
>         self.owner = row[2]
>         self.status = row[3]
>
>     if (self.status == 'new'):
>         #self.env.log.critical("sending email")
>         self._notify(ticket, newticket, modtime)
>     #else:
>         #self.env.log.critical("not sending email")
>
> note.TicketNotifyEmail.notify = notify
>

Makes sense now, the single-file plugin is monkey-patching the notification 
module. Looks like you only want the notifications sent when ticket status 
is "new". You can drastically simplify your plugin. Here are untested 
changes:

def notify(self, ticket, newticket=True, modtime=None):
    if ticket['status'] == 'new':
        self._notify(ticket, newticket, modtime)

note.TicketNotifyEmail.notify = notify


At the very least, use "self.env" rather than instantiating an Environment 
object.

Your plugin shouldn't be needed in Trac 1.2 and later due to the new 
notification subscriber capabilities. In fact, your plugin almost certainly 
won't work in Trac 1.2, so you'll want to be sure to remove it when 
upgrading.

- Ryan
 

-- 
You received this message because you are subscribed to the Google Groups "Trac 
Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/trac-users.
For more options, visit https://groups.google.com/d/optout.

Reply via email to