django-orchestra-test/orchestra/contrib/websites/backends/wordpress.py

38 lines
1.2 KiB
Python
Raw Normal View History

2015-09-28 10:51:03 +00:00
import textwrap
from orchestra.contrib.orchestration import ServiceController
2016-03-08 10:16:49 +00:00
class WordPressURLController(ServiceController):
2015-09-28 10:51:03 +00:00
"""
Configures WordPress site URL with associated website domain.
"""
2015-09-29 08:45:47 +00:00
verbose_name = "WordPress URL"
2015-09-28 10:51:03 +00:00
model = 'websites.Content'
default_route_match = "content.webapp.type == 'wordpress-php'"
def save(self, content):
context = self.get_context(content)
if context['url']:
self.append(textwrap.dedent("""\
mysql %(db_name)s -e 'UPDATE wp_options
SET option_value="%(url)s"
WHERE option_id IN (1, 2) AND option_value="http:";'
""") % context
)
def delete(self, content):
context = self.get_context(content)
self.append(textwrap.dedent("""\
mysql %(db_name)s -e 'UPDATE wp_options
SET option_value="http:"
WHERE option_id IN (1, 2);'
""") % context
)
def get_context(self, content):
return {
'url': content.get_absolute_url(),
'db_name': content.webapp.data.get('db_name'),
}