Mysidia Adoptables Support Forum

Mysidia Adoptables Support Forum (http://www.mysidiaadoptables.com/forum/index.php)
-   Mys v1.3.x Mods (http://www.mysidiaadoptables.com/forum/forumdisplay.php?f=42)
-   -   Mys v1.3.4 Health and mood system + progress bars (http://www.mysidiaadoptables.com/forum/showthread.php?t=5263)

Dinocanid 12-19-2016 08:24 PM

How would I do scheduled tasks? I don't know how to make a script run whenever someone just visits the site, unless it goes in index.php or something.

Hall of Famer 12-20-2016 08:24 AM

First of all, you need to create a database table called adopts_tasks(assuming your database prefix is adopts_, change to whatever it is if not). This table should contain some useful data field such as task id, name, description, action to execute, last execution time, next execution time, time interval between each execution, etc.

Second, create a script file for each of your tasks, and find a way to link it to the data field 'action to execute' in your new database table(ie. mooddrop.php). A simple way is to just use include/require and the file being a procedural file. Or even better, write Task classes that will make it easier to inherit some parent properties/variables. Mysidia Adoptables v1.4.0 will use the latter approach, but if you just barely get a hang of programming the former procedural approach may be more feasible.

Next, add some code to index.php file, this way this code always runs whenever someone visits your site, even a search bot. The code will need to pull all the scheduled tasks ready to run from your new database table(current time is greater than or equal to the next execution time), and execute the script file each task links to. After the script is executed, increment the next execution time by the wait time, and update your database table so the tasks will not run again until it should.

For instance, if you have a scheduled task linking to file mooddrop.php, its next execution time is today at 8am and wait time is 3 hours. When you visit your site at 9am, it will load the scheduled task from database, execute the script inside mooddrop.php, and update the next execution time from 8am to 11am(3 hours interval). Then the task will not run again until someone visits your site again after 11am.

Now you see, it is a simple trick that will work well given you have an active site with visitors at least once per 3-5 minutes. If you are on a virtual machine/devbox, it will not function properly since you are the sole visitor. In fact, this is exactly how our forum software's scheduled task system works. It uses pseudo-cronjobs, and you dont have to manually set up all cronjobs from cpanel.

Of course, you may face some challenges such as how to write task files/classes, how to compare date, and how to store data values in database. Lemme know if you have any questions, I will try to explain and help you with this.

Dinocanid 12-22-2016 07:12 PM

Finally on break so I can work on this. Would this be the correct setup for the table?
http://www.clipular.com/c/6039837629...RzoNyxYyla8rhI
This is also what I have so far for my lowermood.php:
PHP Code:

<?php

use Resource\Native\String;
use 
Resource\Collection\LinkedList;
class 
LowermoodController extends AppController{
    
    public function 
index(){
    
$mysidia Registry::get("mysidia");
    
$mysidia->db->insert("Table", array("Column" => $somevalue"Column" => 'somevalue')); //not yet used
    
$lower $mysidia->db->select("owned_adoptables", array("mood"))->fetchColumn();
    
$lower 10;
        }
    }              
?>


Silver_Brick 12-25-2016 07:09 AM

While i was trying it i got error
Fatal error: Uncaught exception 'Exception' with message 'Database error 1054 - Unknown column 'aid' in 'field list'' in /home/dacankey/public_html/classes/class_database.php:213 Stack trace: #0 /home/dacankey/public_html/classes/class_database.php(142): Database->_query('owned_adoptable...', Array, 'select', '1 ORDER BY RAND...') #1 /home/dacankey/public_html/view/indexview.php(10): Database->select('owned_adoptable...', Array, '1 ORDER BY RAND...') #2 /home/dacankey/public_html/classes/class_frontcontroller.php(100): IndexView->index() #3 /home/dacankey/public_html/index.php(74): FrontController->render() #4 /home/dacankey/public_html/index.php(78): IndexController::main() #5 {main} thrown in /home/dacankey/public_html/classes/class_database.php on line 213

Dinocanid 12-25-2016 07:21 AM

What does your code look like?

Silver_Brick 12-25-2016 08:46 AM

which code

Dinocanid 12-25-2016 09:12 AM

The one that's giving you the error.

Silver_Brick 12-25-2016 11:11 AM

Can you show me your owned adopt table phpmyadmin screenshot of structure

Dinocanid 12-25-2016 11:23 AM

http://www.clipular.com/c/5091632934...EQwoQX95S6dYac

Silver_Brick 12-25-2016 11:41 AM

I think its other problem which hall of fame can solve :( and merry christmas


All times are GMT -5. The time now is 10:23 AM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.