summaryrefslogtreecommitdiff
path: root/portal/tools/moderation-nag.php
blob: af41a78af8ad1d7c81a8f8555c216ef895861e69 (plain)
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
#! /usr/local/bin/php -c /usr/local/etc/php.ini
<?php

require_once '../system/global/settings.php';

if (file_exists('../system/global/settings.local.php'))
    require_once '../system/global/settings.local.php';

   if (isset($_SERVER['argv'][1]))
       $EMAIL = $_SERVER['argv'][1];
   else
       $EMAIL = "PostgreSQL WWW List <pgsql-www@postgresql.org>";

   $DB = $_SETTINGS['db_portal'];
   $SEND_MAIL = 0;

   $dt = getdate();
   $today = $dt['year'] . "-" . $dt['mon'] . "-" . $dt['mday'];
   $LOG = "PostgreSQL.org moderation report - " . $today . " " . $dt['hours'] . ":" . $dt['minutes'] . ":" . $dt['seconds'] . ".\n\n";

   // connect to database
   $db = @pg_connect($DB);
   if ($php_errormsg != "") {
      $LOG .= "Couldn't connect to the database server: " . $DB . "\n\n" . $php_errormsg;
      mail($EMAIL, "PostgreSQL moderation report: " . $today, $LOG, "From: webmaster@postgresql.org\nReply-To: webmaster@postgresql.org"); 
      exit;
   }

   //
   // Applications
   //

   $sql = "SELECT count(*) FROM comments WHERE processed = FALSE;";
   $rs = @pg_exec($db, $sql);
   if (pg_result_status($rs) != PGSQL_TUPLES_OK && pg_result_status($rs) != PGSQL_COMMAND_OK) {
      $LOG .= "Error: Could not query the comments table!\n\n" . $php_errormsg;
      mail($EMAIL, "PostgreSQL moderation report: " . $today, $LOG, "From: webmaster@postgresql.org\nReply-To: webmaster@postgresql.org"); 
      exit;
   }

   $records = pg_result($rs, 0, 0);
 
   if ($records > 0)
   {
      $LOG .= "There are $records documentation comment(s) requiring moderation.\n";
      $SEND_MAIL = 1;
   }

   //
   // Events
   //

   $sql = "SELECT count(*) FROM events WHERE approved = FALSE;";
   $rs = @pg_exec($db, $sql);
   if (pg_result_status($rs) != PGSQL_TUPLES_OK && pg_result_status($rs) != PGSQL_COMMAND_OK) {
      $LOG .= "Error: Could not query the events table!\n\n" . $php_errormsg;
      mail($EMAIL, "PostgreSQL moderation report: " . $today, $LOG, "From: webmaster@postgresql.org\nReply-To: webmaster@postgresql.org");
      exit;
   }

   $records = pg_result($rs, 0, 0);

   if ($records > 0)
   {
      $LOG .= "There are $records event(s) requiring moderation.\n";
      $SEND_MAIL = 1;
   }

   //
   // News
   //

   $sql = "SELECT count(*) FROM news WHERE approved = FALSE;";
   $rs = @pg_exec($db, $sql);
   if (pg_result_status($rs) != PGSQL_TUPLES_OK && pg_result_status($rs) != PGSQL_COMMAND_OK) {
      $LOG .= "Error: Could not query the news table!\n\n" . $php_errormsg;
      mail($EMAIL, "PostgreSQL moderation report: " . $today, $LOG, "From: webmaster@postgresql.org\nReply-To: webmaster@postgresql.org");
      exit;
   }

   $records = pg_result($rs, 0, 0);

   if ($records > 0)
   {
      $LOG .= "There are $records news item(s) requiring moderation.\n";
      $SEND_MAIL = 1;
   }

   //
   // Organisations
   //

   $sql = "SELECT count(*) FROM organisations WHERE approved = FALSE;";
   $rs = @pg_exec($db, $sql);
   if (pg_result_status($rs) != PGSQL_TUPLES_OK && pg_result_status($rs) != PGSQL_COMMAND_OK) {
      $LOG .= "Error: Could not query the organisations table!\n\n" . $php_errormsg;
      mail($EMAIL, "PostgreSQL moderation report: " . $today, $LOG, "From: webmaster@postgresql.org\nReply-To: webmaster@postgresql.org");
      exit;
   }

   $records = pg_result($rs, 0, 0);

   if ($records > 0)
   {
      $LOG .= "There are $records organisation(s) requiring moderation.\n";
      $SEND_MAIL = 1;
   }

   //
   // Products
   // 
   
   $sql = "SELECT count(*) FROM products WHERE approved = FALSE;";
   $rs = @pg_exec($db, $sql);
   if (pg_result_status($rs) != PGSQL_TUPLES_OK && pg_result_status($rs) != PGSQL_COMMAND_OK) {
      $LOG .= "Error: Could not query the products table!\n\n" . $php_errormsg;
      mail($EMAIL, "PostgreSQL moderation report: " . $today, $LOG, "From: webmaster@postgresql.org\nReply-To: webmaster@postgresql.org");
      exit;
   }

   $records = pg_result($rs, 0, 0);

   if ($records > 0)
   {
      $LOG .= "There are $records product(s) requiring moderation.\n";
      $SEND_MAIL = 1;
   }

   //
   // Professional services
   // 
   
   $sql = "SELECT count(*) FROM profserv WHERE approved = FALSE;";
   $rs = @pg_exec($db, $sql);
   if (pg_result_status($rs) != PGSQL_TUPLES_OK && pg_result_status($rs) != PGSQL_COMMAND_OK) {
      $LOG .= "Error: Could not query the profserv table!\n\n" . $php_errormsg;
      mail($EMAIL, "PostgreSQL moderation report: " . $today, $LOG, "From: webmaster@postgresql.org\nReply-To: webmaster@postgresql.org");
      exit;
   }

   $records = pg_result($rs, 0, 0);

   if ($records > 0)
   {
      $LOG .= "There are $records professional service(s) requiring moderation.\n";
      $SEND_MAIL = 1;
   }

   // 
   // Send the email
   //
   if ($SEND_MAIL)
   {
      $LOG .= "\nModerators; please check and moderate these items as soon as possible!";
      mail($EMAIL, "PostgreSQL moderation report: " . $today, $LOG, "From: webmaster@postgresql.org\nReply-To: webmaster@postgresql.org"); 
   }

   pg_close($db);

?>