| 1 |
from trac.core import * |
|---|
| 2 |
from trac.env import IEnvironmentSetupParticipant |
|---|
| 3 |
|
|---|
| 4 |
class TracSlimTimerSetupParticipant(Component): |
|---|
| 5 |
""" |
|---|
| 6 |
We need: |
|---|
| 7 |
[ticket-custom] |
|---|
| 8 |
|
|---|
| 9 |
slimtimer_id = text |
|---|
| 10 |
slimtimer_id.value = 0 |
|---|
| 11 |
slimtimer_id.label = SlimTimer ID |
|---|
| 12 |
slimtimer_id.order = 99 |
|---|
| 13 |
""" |
|---|
| 14 |
implements(IEnvironmentSetupParticipant) |
|---|
| 15 |
|
|---|
| 16 |
def environment_created(self): |
|---|
| 17 |
"""Called when a new Trac environment is created.""" |
|---|
| 18 |
if self.environment_needs_upgrade(None): |
|---|
| 19 |
self.upgrade_environment(None) |
|---|
| 20 |
|
|---|
| 21 |
def environment_needs_upgrade(self, db): |
|---|
| 22 |
"""Called when Trac checks whether the environment needs to be |
|---|
| 23 |
upgraded. |
|---|
| 24 |
|
|---|
| 25 |
Should return `True` if this participant needs an upgrade to be |
|---|
| 26 |
performed, `False` otherwise. |
|---|
| 27 |
|
|---|
| 28 |
""" |
|---|
| 29 |
ticket_custom = "ticket-custom" |
|---|
| 30 |
return not (self.config.get( ticket_custom, "slimtimer_id" ) == "text") |
|---|
| 31 |
|
|---|
| 32 |
def upgrade_environment(self, db): |
|---|
| 33 |
"""Actually perform an environment upgrade. |
|---|
| 34 |
|
|---|
| 35 |
Implementations of this method should not commit any database |
|---|
| 36 |
transactions. This is done implicitly after all participants have |
|---|
| 37 |
performed the upgrades they need without an error being raised. |
|---|
| 38 |
""" |
|---|
| 39 |
print "Upgrading TracSlimTimer custom fields" |
|---|
| 40 |
|
|---|
| 41 |
ticket_custom = "ticket-custom" |
|---|
| 42 |
|
|---|
| 43 |
self.config.set(ticket_custom, "slimtimer_id", "text") |
|---|
| 44 |
self.config.set(ticket_custom, "slimtimer_id.value", "0") |
|---|
| 45 |
self.config.set(ticket_custom, "slimtimer_id.label", "SlimTimer ID") |
|---|
| 46 |
self.config.set(ticket_custom, "slimtimer_id.order", "99") |
|---|
| 47 |
self.config.save(); |
|---|
| 48 |
|
|---|
| 49 |
print "Done upgrading TracSlimTimer custom fields" |
|---|