Skip to content

Commit dd964b2

Browse files
authored
Merge pull request #18 from circuscode/feature-deactivate-tweet-load
Feature deactivate tweet load
2 parents 8c541c7 + d6133f4 commit dd964b2

File tree

6 files changed

+81
-3
lines changed

6 files changed

+81
-3
lines changed

mathilda.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ function mathilda_activate () {
9595
add_option('mathilda_import_subprocess_running', "0");
9696
add_option('mathilda_load_process_running',"0");
9797
add_option('mathilda_import_filesize_max',"409600");
98+
add_option('mathilda_cron_status',"0");
9899

99100
/* Create Mathilda Tables */
100101

@@ -208,6 +209,7 @@ function mathilda_delete () {
208209
delete_option('mathilda_import_subprocess_running');
209210
delete_option('mathilda_load_process_running');
210211
delete_option('mathilda_import_filesize_max');
212+
delete_option('mathilda_cron_status');
211213

212214
/* Delete Tables */
213215

mathilda_cron.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,10 @@ function mathilda_cron_script() {
503503
Update Meta
504504
*/
505505

506-
if($initial_load == 0) { update_option('mathilda_initial_load', 1); }
506+
if($initial_load == 0) {
507+
update_option('mathilda_initial_load', 1);
508+
update_option('mathilda_cron_status', 1);
509+
}
507510
$latest_tweet=mathilda_latest_tweet();
508511
$number_of_tweets=mathilda_tweets_count();
509512
$number_of_select=mathilda_select_count();

mathilda_database.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,7 @@ function mathilda_reset_data() {
462462
update_option('mathilda_import_subprocess_running',0);
463463
update_option('mathilda_load_process_running',0);
464464
update_option('mathilda_import_interval', "86400");
465+
update_option('mathilda_cron_status',"0");
465466

466467
global $wpdb;
467468
$table_name=$wpdb->prefix . 'mathilda_tweets';

mathilda_schedule.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,9 @@ function mathilda_import_interval( $schedules ) {
4848
function mathilda_cron_execute_tweetload() {
4949

5050
$initial_load = get_option('mathilda_initial_load');
51-
if($initial_load==1) {
51+
$cron_status=get_option('mathilda_cron_status');
52+
53+
if($initial_load==1 && $cron_status==1) {
5254
mathilda_cron_script();
5355
}
5456
}

mathilda_tools.php

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ function mathilda_tools_controller() {
3434
$handbook_show=false;
3535
$mathilda_reset=false;
3636
$import_break=false;
37+
$cron_status=false;
3738

3839
// Load Tweets
3940
if(isset($_GET['cron'])) {
@@ -42,6 +43,13 @@ function mathilda_tools_controller() {
4243
$run_cron=true;
4344
}
4445
}
46+
// Cron Status
47+
if(isset($_GET['cronstatus'])) {
48+
if($_GET['cronstatus']=='true')
49+
{
50+
$cron_status=true;
51+
}
52+
}
4553
// Scripting
4654
if(isset($_GET['scripting'])) {
4755
if($_GET['scripting']=='true')
@@ -148,6 +156,8 @@ function mathilda_tools_controller() {
148156
function mathilda_tools() {
149157

150158
/* Dynamic Labels */
159+
160+
/* Import Status */
151161
$label_import_botton="";
152162
$label_import_status=get_option('mathilda_import_running');
153163
if($label_import_status==0) {
@@ -156,6 +166,15 @@ function mathilda_tools() {
156166
$label_import_botton="Status!";
157167
}
158168

169+
/* cron Status */
170+
$label_cronstatus_button="";
171+
$label_cronstatus_status=get_option('mathilda_cron_status');
172+
if($label_cronstatus_status==0) {
173+
$label_cronstatus_button="Activate!";
174+
} else {
175+
$label_cronstatus_button="Deactivate!";
176+
}
177+
159178
/* Headline */
160179
echo '<h1 class="mathilda_tools_headline">Tweets</h1>
161180
<p class="mathilda_tools_description">Mathilda Tools</p>';
@@ -193,6 +212,36 @@ function mathilda_tools() {
193212
}
194213
}
195214

215+
// Auto Load
216+
if(isset($_GET['cronstatus'])) {
217+
if($_GET['cronstatus']=='true')
218+
{
219+
$autoload_status=get_option('mathilda_cron_status');
220+
if($autoload_status) {
221+
update_option('mathilda_cron_status','0');
222+
$label_cronstatus_button="Activate!";
223+
echo '<div class="updated fade">
224+
<p><strong>Auto Load has been deactivated.</strong></p>
225+
</div>';
226+
} else {
227+
228+
$initial_load = get_option('mathilda_initial_load');
229+
if($initial_load==1) {
230+
update_option('mathilda_cron_status','1');
231+
$label_cronstatus_button="Deactivate!";
232+
echo '<div class="updated fade">
233+
<p><strong>Auto Load has been activated.</strong></p>
234+
</div>';
235+
} else {
236+
echo '<div class="notice notice-warning is-dismissible">
237+
<p><strong>Auto Load can still not be activated. You have to run an initial load manually first (Load Tweets).</strong></p>
238+
</div>';
239+
}
240+
241+
}
242+
}
243+
}
244+
196245
// Embed Reset
197246
if(isset($_GET['resetisconfirmed'])) {
198247
if($_GET['resetisconfirmed']=='true')
@@ -226,6 +275,16 @@ function mathilda_tools() {
226275
<a class="button" href="'.admin_url().'tools.php?page=mathilda-tools-menu&cron=true" >Run!</a>
227276
</td>
228277
</tr>
278+
279+
<!-- Status Cron -->
280+
<tr valign="top">
281+
<th scope="row">
282+
<label for="cron">Auto Load</label>
283+
</th>
284+
<td>
285+
<a class="button" href="'.admin_url().'tools.php?page=mathilda-tools-menu&cronstatus=true">'.$label_cronstatus_button.'</a>
286+
</td>
287+
</tr>
229288
230289
<!-- Load Twitter Export -->
231290
<tr valign="top">

mathilda_utilities.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,18 @@ function mathilda_healthy_check() {
291291

292292
$output.='<br/>';
293293

294-
// 4. Info
294+
// 4. Info
295+
$cron_status=get_option('mathilda_cron_status');
296+
if($cron_status==0) {
297+
$output.='Auto Load is deactive.';
298+
}
299+
else {
300+
$output.='Auto Load is active.';
301+
}
302+
303+
$output.='<br/>';
304+
305+
// 5. Info
295306
$tweets_loaded=mathilda_tweets_count();
296307
if($tweets_loaded==0) {
297308
$output.='No Tweets are loaded.';

0 commit comments

Comments
 (0)