Mysidia Adoptables Support Forum  

Home Community Mys-Script Creative Off-Topic
Go Back   Mysidia Adoptables Support Forum > Mysidia Adoptables > Addons and Modifications > Mys v1.3.x Mods

Notices

Reply
 
Thread Tools Display Modes
  #11  
Old 12-19-2016, 09:24 PM
Dinocanid's Avatar
Dinocanid Dinocanid is offline
Member
 
Join Date: Aug 2016
Location: Maryland, USA
Posts: 516
Gender: Unknown/Other
Credits: 78,974
Dinocanid is on a distinguished road
Default

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.
__________________
Reply With Quote
  #12  
Old 12-20-2016, 09:24 AM
Hall of Famer's Avatar
Hall of Famer Hall of Famer is offline
Administrator, Lead Coder
 
Join Date: Dec 2008
Location: South Brunswick
Posts: 4,448
Gender: Male
Credits: 488,286
Hall of Famer is on a distinguished road
Default

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.
__________________


Mysidia Adoptables, a free and ever-improving script for aspiring adoptables/pets site.
Reply With Quote
  #13  
Old 12-22-2016, 08:12 PM
Dinocanid's Avatar
Dinocanid Dinocanid is offline
Member
 
Join Date: Aug 2016
Location: Maryland, USA
Posts: 516
Gender: Unknown/Other
Credits: 78,974
Dinocanid is on a distinguished road
Default

Finally on break so I can work on this. Would this be the correct setup for the table?

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;
        }
    }              
?>
__________________
Reply With Quote
  #14  
Old 12-25-2016, 08:09 AM
Silver_Brick Silver_Brick is offline
Designer || Coder
 
Join Date: Oct 2016
Location: In Earth
Posts: 205
Gender: Male
Credits: 31,259
Silver_Brick is on a distinguished road
Default

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
Reply With Quote
  #15  
Old 12-25-2016, 08:21 AM
Dinocanid's Avatar
Dinocanid Dinocanid is offline
Member
 
Join Date: Aug 2016
Location: Maryland, USA
Posts: 516
Gender: Unknown/Other
Credits: 78,974
Dinocanid is on a distinguished road
Default

What does your code look like?
__________________
Reply With Quote
  #16  
Old 12-25-2016, 09:46 AM
Silver_Brick Silver_Brick is offline
Designer || Coder
 
Join Date: Oct 2016
Location: In Earth
Posts: 205
Gender: Male
Credits: 31,259
Silver_Brick is on a distinguished road
Default

which code
Reply With Quote
  #17  
Old 12-25-2016, 10:12 AM
Dinocanid's Avatar
Dinocanid Dinocanid is offline
Member
 
Join Date: Aug 2016
Location: Maryland, USA
Posts: 516
Gender: Unknown/Other
Credits: 78,974
Dinocanid is on a distinguished road
Default

The one that's giving you the error.
__________________
Reply With Quote
  #18  
Old 12-25-2016, 12:11 PM
Silver_Brick Silver_Brick is offline
Designer || Coder
 
Join Date: Oct 2016
Location: In Earth
Posts: 205
Gender: Male
Credits: 31,259
Silver_Brick is on a distinguished road
Default

Can you show me your owned adopt table phpmyadmin screenshot of structure
Reply With Quote
  #19  
Old 12-25-2016, 12:23 PM
Dinocanid's Avatar
Dinocanid Dinocanid is offline
Member
 
Join Date: Aug 2016
Location: Maryland, USA
Posts: 516
Gender: Unknown/Other
Credits: 78,974
Dinocanid is on a distinguished road
Default

__________________
Reply With Quote
  #20  
Old 12-25-2016, 12:41 PM
Silver_Brick Silver_Brick is offline
Designer || Coder
 
Join Date: Oct 2016
Location: In Earth
Posts: 205
Gender: Male
Credits: 31,259
Silver_Brick is on a distinguished road
Default

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


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


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

Currently Active Users: 693 (0 members and 693 guests)
Threads: 4,081, Posts: 32,031, Members: 2,016
Welcome to our newest members, jolob.
BETA





What's New?

What's Hot?

What's Popular?


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
vBCommerce I v2.0.0 Gold ©2010, PixelFX Studios
vBCredits I v2.0.0 Gold ©2010, PixelFX Studios
Emoticons by darkmoon3636