Finally There - Resetting Demo Site

I hope this is an easy one.

We have finally finished our long and interesting project (Yippee). Now, we have created a demo site for users to try and see if it is what they would be interested in using. So, I would like to duplicate what Boonex has for their demo site in regards to resetting our demo site back to "factory" after a specific period of time. Does anyone know how I can accomplish this?

caredesign.net
Quote · 15 Sep 2013

with a cron job and a few bash commands in the cron job you fire off

https://dolphin-techs.com - Skype: Dolphin Techs
Quote · 15 Sep 2013

Feel free to play around with the file I attached. Here's what I did back when I had a demo site:

 

1. Once you get the site like you like it dump the database into a file called dolphindemo.sql and put that file in the /periodic directory. Make sure when you dump it you use the "DROP TABLE IF EXISTS" commands.

 

2. Put the restore.php file I attached in the /periodic directory (change the line in the file that has your account name). 

 

3. Set a cron to run the restore.php file however often you want to reset. 

 

I haven't used it in a long time but it always worked for me. It just loops through that SQL file and runs all the commands which drop each table and reinsert it from the file. 

restore.php · 696B · 185 downloads
BoonEx Certified Host: Zarconia.net - Fully Supported Shared and Dedicated for Dolphin
Quote · 15 Sep 2013

thank you mscott for your response. Unfortunately, I have done something wrong. I changed the sql file name in the restore.php file and uploaded both the sql file and the restore.php file to the periodic directory. I have added a cron to run every minute with the following command:

cd /home/mytherap/public_html/mtsdemo/periodic; /usr/local/bin/php -q restore.php

I do get emails each minute, but they are blank. But looking in the database itself, i see changes that were made and not being reset.

caredesign.net
Quote · 17 Sep 2013

OK, I got it to work. Again, thank you mscott for yout advice. Ultimately, I had to use a different method to get it to work. Dumped the Database into an sql file and placed in the periodic folder. Then used the following command in my cron:

mysql -uMYSQLUSERNAME -pMYSQLPASSWORD MYSQLDATABASE < /home/mytherap/public_html/mtsdemo/periodic/demo.sql

 

Now, if anyone can help me setup the timer to display how much time remaining before database reset, I would be greatly appreciative.

caredesign.net
Quote · 17 Sep 2013

OK, I have found a code for a timer and it seems to be working. Now, my next issue is: How do I clear the cache and any cookies or sessions when doing the reset.

caredesign.net
Quote · 17 Sep 2013

Cookies are kept in the browser, so you do it in the timer when it runs out. I am guessing you have a javascript timer, so in javascript to clear both the cookies.

document.cookie = 'memberID=; expires=Thu, 01-Jan-70 00:00:01 GMT;';
document.cookie = 'memberPassword=; expires=Thu, 01-Jan-70 00:00:01 GMT;';


The rest is part of your cron script. You just delete the files in the cache. Surely you know how to delete files with a shell command.

I did all of this weeks ago for my demo site. Been so long i don't even remember how i set it all up. http://demo.deanbassett.com/

Just haven't finished install all of my mods yet.



I do get emails each minute, but they are blank. But looking in the database itself, i see changes that were made and not being reset.
And i hope you not clearing every minute. That is way to often. Every 1 hour or so maximum. And on occasion, database errors will occur on the demo site from dolphin while cron is restoring the database. That's why you do not want to do it to frequently.

https://www.deanbassett.com
Quote · 17 Sep 2013

 Thanks Deanos

OK, I have found a code for a timer and it seems to be working. Now, my next issue is: How do I clear the cache and any cookies or sessions when doing the reset.

 

 i set it for once each minute so that  I can make sure it is working. The actual time period will probably be 15 minutes. Due to the nature of the site, we dont want to make it too much longer than that as the demoer could use certain features and print the results out without paying for the actual service. So trying to avoid that as much as possible.

Also - before I read your post, this is what I managed to come up with, testing now to see if it actually works:

 

session_start();
$timestamp = time();
$diff = 900; //<-Time of countdown in seconds.  ie. 3600 = 1 hr. or 86400 = 1 day.

//MODIFICATION BELOW THIS LINE IS NOT REQUIRED.
$hld_diff = $diff;
if(isset($_SESSION['ts'])) {
    $slice = ($timestamp - $_SESSION['ts']);   
    $diff = $diff - $slice;
}

if(!isset($_SESSION['ts']) || $diff > $hld_diff || $diff < 0) {
    $diff = $hld_diff;
    $_SESSION['ts'] = $timestamp;
}

//Below is demonstration of output.  Seconds could be passed to Javascript.
$diff; //$diff holds seconds less than 3600 (1 hour);

$hours = floor($diff / 3600) . ' : ';
$diff = $diff % 3600;
$minutes = floor($diff / 60) . ' : ';
$diff = $diff % 60;
$seconds = $diff;


?>
<div id="strclock">Clock Here!</div>
<script type="text/javascript">
 var hour = <?php echo floor($hours); ?>;
 var min = <?php echo floor($minutes); ?>;
 var sec = <?php echo floor($seconds); ?>

function countdown() {
 if(sec <= 0 && min > 0) {
  sec = 59;
  min -= 1;
 }
 else if(min <= 0 && sec <= 0) {
  min = 0;
  sec = 0;
   unset($_SESSION['ts'];
   setcookie('memberID','',time()-3600);
   setcookie('memberPassword','',time()-3600);
 }
 else {
  sec -= 1;
 }
 
 if(min <= 0 && hour > 0) {
  min = 59;
  hour -= 1;
 }
 
 var pat = /^[0-9]{1}$/;
 sec = (pat.test(sec) == true) ? '0'+sec : sec;
 min = (pat.test(min) == true) ? '0'+min : min;
 hour = (pat.test(hour) == true) ? '0'+hour : hour;
 
 document.getElementById('strclock').innerHTML = hour+":"+min+":"+sec;
 setTimeout("countdown()",1000);
 }
 countdown();
</script>

<?php { }

caredesign.net
Quote · 17 Sep 2013

OK, the one i originally had wasnt working exactly like i wanted to, so after checking out yours deanos, I have gotten one that somewhat works. But, Deanos, how do you sync the cron with your timer and get the ending time in the timer to change?

caredesign.net
Quote · 17 Sep 2013
 
 
Below is the legacy version of the Boonex site, maintained for Dolphin.Pro 7.x support.
The new Dolphin solution is powered by UNA Community Management System.