-
Notifications
You must be signed in to change notification settings - Fork 0
/
custom_field
executable file
·48 lines (38 loc) · 1.37 KB
/
custom_field
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/usr/bin/env python
from civicrm import civicrm_api
from helpers import get_config
from notifications import notify
from pprint import pprint
from itertools import chain
import yaml
from sh import ssh
config = get_config('custom_field')
def check_custom_fields():
passed = list()
failed = list()
for field_name, field in config['fields'].iteritems():
for contact_id in field['contacts']:
test = civicrm_api('Contact', 'get', id=contact_id, _return='display_name,' + field_name)
params = (field_name, field['label'], test['values'][str(contact_id)]['display_name'])
if field_name in test['values'][str(contact_id)]:
passed.append("%s (%s) is present for %s" % params)
else:
failed.append("%s (%s) is missing for %s" % params)
for s in chain(passed, failed):
print s
if len(failed) > 0:
server = get_config('server')
actions = list()
live = ssh.bake(server['user'] + '@' + server['host'], 'cd', server['sites']['live'], '&&')
live.drush('civicrm-cache-clear')
actions.append("CiviCRM's caches were cleared")
args = {
'title':'Custom Fields',
'subject': 'Custom Fields are not working',
'passed': passed,
'failed': failed,
'actions': actions,
}
notify('custom_field', 'Custom Fields are not working', app='civicrm', **args)
if __name__ == "__main__":
check_custom_fields()