Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
3503964
Add Public Export and OAI form metadata options
MichaelRBond Dec 11, 2016
13d8941
Typo corrections
MichaelRBond Dec 11, 2016
31be9be
Merge pull request #254 from wvulibraries/master
Dec 18, 2016
e73f130
Merge pull request #250 from wvulibraries/OAIPublicFormOptions
Dec 18, 2016
c663de3
Merge pull request #252 from wvulibraries/TypoCorrections
Dec 18, 2016
d9a4991
Fix variable typo
MichaelRBond Dec 23, 2016
b64b06c
nagios check
MichaelRBond Jan 8, 2017
7333016
nagios check
MichaelRBond Jan 8, 2017
2ebeba3
Merge pull request #256 from wvulibraries/RemoveSpacesAroundMetadataS…
MichaelRBond Jan 28, 2017
2bef711
Change the temporary location where the download all is built
MichaelRBond Feb 14, 2017
731ce78
syntax
MichaelRBond Feb 14, 2017
63770c9
Merge pull request #261 from wvulibraries/DownloadAll
Feb 23, 2017
e0739b5
Add objects::getByIDNO()
MichaelRBond Feb 25, 2017
9001dcb
Update ACL includes for the API
MichaelRBond Feb 25, 2017
fcd1a65
API for adding a URL to an Object
MichaelRBond Feb 25, 2017
2c197c1
Switched all methods in Objects class to use standard $engine call
MichaelRBond Feb 26, 2017
112343e
Added todo and place-holder file
MichaelRBond Feb 26, 2017
b0b5ef9
Updated securityConcerns with clarifying information.
MichaelRBond Feb 26, 2017
80b4f8a
Changed objects::getObjects() to honor ignoreCache
MichaelRBond Feb 26, 2017
c24ab96
Add method to count all objects in the system.
MichaelRBond Feb 26, 2017
5d821e1
Add column to objects table for publicRelease of objects
MichaelRBond Feb 26, 2017
b21d690
CLI Script to convert from previous way of defining publicRelease object
MichaelRBond Feb 26, 2017
66ef257
Add Release to Public to Object forms
MichaelRBond Mar 5, 2017
bd0b034
Ad OAI Release to individual fields.
MichaelRBond Mar 5, 2017
a684672
Display Public URLs on the object page, in a new tab.
MichaelRBond Mar 5, 2017
6aeffa4
Merge pull request #263 from wvulibraries/OAIUpdates
Mar 10, 2017
2050d08
Starting unit testing framework. Update for public release.
MichaelRBond Mar 12, 2017
d0d22d5
readme file for put url API.
MichaelRBond Mar 14, 2017
e0053ae
Only display the Public Release select on object forms
MichaelRBond Mar 31, 2017
82fb25d
Fix typo
MichaelRBond Mar 31, 2017
6f427a7
Add API Endpoint for getting a URL for an oobject
MichaelRBond Apr 2, 2017
3c2fb5a
Increase the length of the objectUrl tables
MichaelRBond Apr 2, 2017
16a7c55
Max length of varchar in version of mysql on servers is 767
MichaelRBond Apr 2, 2017
8e02de6
Switch from utf8 (2 bytes per character) to latin1
MichaelRBond Apr 2, 2017
36369ab
Fix path typo
MichaelRBond Apr 3, 2017
e9dbdb9
Fix for drive usage on dashboard.
MichaelRBond Apr 4, 2017
6770f92
Projects api endpoint (#264)
MichaelRBond Apr 18, 2017
1e87dc5
Projects api endpoint (#266)
MichaelRBond Apr 29, 2017
e4c691b
Changing JavaScript to reveal fields. (#265)
Apr 29, 2017
5ce400d
Add OAI options to the public url tab in Editing
MichaelRBond Apr 30, 2017
15f3992
Merge remote-tracking branch 'origin/develop' into develop
MichaelRBond Apr 30, 2017
21782cc
Merge branch 'master' into develop
ddavisgraphics May 16, 2017
15667dd
wip (scheduler)
trmccormick Jun 5, 2017
40666f8
working version
trmccormick Jun 6, 2017
f50e24b
scheduler
trmccormick Jul 10, 2017
8dd273e
updated nav
trmccormick Jul 10, 2017
806f654
removed crons path
trmccormick Jul 10, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions SQLFiles/migrations/2017.05.31.0942.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
DROP TABLE IF EXISTS `scheduler`;
CREATE TABLE `scheduler` (
`ID` int(10) unsigned NOT NULL AUTO_INCREMENT,
`name` varchar(50) DEFAULT NULL,
`minute` varchar(2) NOT NULL DEFAULT '*', -- 0-59
`hour` varchar(2) NOT NULL DEFAULT '*', -- 0-23
`dayofmonth` varchar(2) NOT NULL DEFAULT '*', -- 1-31
`month` varchar(2) NOT NULL DEFAULT '*', -- 1-12
`dayofweek` varchar(1) NOT NULL DEFAULT '*', -- 0-7 (0 or 7 is Sunday, or use names)
`runnow` tinyint(1) NOT NULL DEFAULT '0',
`active` tinyint(1) NOT NULL DEFAULT '0',
`lastrun` int(11) DEFAULT NULL,
PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=45 DEFAULT CHARSET=latin1;
55 changes: 50 additions & 5 deletions bootstrap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,23 @@ mysql -u root EngineAPI < /tmp/git/engineAPI/sql/EngineAPI.sql
# application Post Setup

mysql -u root < /vagrant/SQLFiles/setup.sql

mysql -u root mfcs < /vagrant/SQLFiles/baseSnapshot.sql

for f in $SQLFILES
do
echo "Processing $f ..."
mysql -u root mfcs < "$f"
done
# for f in $SQLFILES
# do
# echo "Processing $f ..."
# mysql -u root mfcs < "$f"
# done

#first value is size in megabytes to load main database
mysql -u root -Bse "set global max_allowed_packet=1024*1024*1024"; #first value is size in megabytes
mysql -u root mfcs < /vagrant/SQLFiles/mfcs.sql
mysql -u root mfcs < /vagrant/SQLFiles/migrations/2016.07.26.0945.sql
mysql -u root mfcs < /vagrant/SQLFiles/migrations/2017.02.25.0808.sql
mysql -u root mfcs < /vagrant/SQLFiles/migrations/2017.02.25.0905.sql
mysql -u root mfcs < /vagrant/SQLFiles/migrations/2017.02.27.1852.sql
mysql -u root mfcs < /vagrant/SQLFiles/migrations/2017.05.31.0942.sql

# Daves Migration Script
# sh /vagrant/SQLFiles/runMigrations.sh
Expand Down Expand Up @@ -163,3 +173,38 @@ yum -y install clamav clamav-db clamav-devel

/sbin/service httpd restart

touch /vagrant/serverConfiguration/serverlogs/cron_log
# ln -s /var/log/cron /vagrant/serverConfiguration/serverlogs/cron_log

# Adds a crontab entry to "php runcrons.php" then runs every 5 minutes

# Cron expression
# cron="*/5 * * * * /usr/bin/php /vagrant/public_html/crons/runcrons.php"
cron="* * * * * cd /vagrant/public_html/crons && /usr/bin/php runcrons.php >> /vagrant/serverConfiguration/serverlogs/cron_log 2>&1"
# │ │ │ │ │
# │ │ │ │ │
# │ │ │ │ └───── day of week (0 - 6) (0 to 6 are Sunday to Saturday, or use names; 7 is Sunday, the same as 0)
# │ │ │ └────────── month (1 - 12)
# │ │ └─────────────── day of month (1 - 31)
# │ └──────────────────── hour (0 - 23)
# └───────────────────────── min (0 - 59)

# Escape all the asterisks so we can grep for it
cron_escaped=$(echo "$cron" | sed s/\*/\\\\*/g)

# Check if cron job already in crontab
crontab -l | grep "${cronescaped}"
if [[ $? -eq 0 ]] ;
then
echo "Crontab already exists. Exiting..."
exit
else
# Write out current crontab into temp file
crontab -l > mycron
# Append new cron into cron file
echo "$cron" >> mycron
# Install new cron file
crontab mycron
# Remove temp file
rm mycron
fi
76 changes: 76 additions & 0 deletions public_html/admin/scheduler/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<?php

include("../../header.php");
include("../../includes/classes/scheduler.php");

//Permissions Access
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this logic be redacted to an include file so that it is not intermixed with the view? If not then it is fine, but thinking about maintainability and future thought we want to keep logic separate from views as much as possible.

if(!mfcsPerms::evaluatePageAccess(3)){
header('Location: /index.php?permissionFalse');
}

$tableName = "scheduler";
$scheduler = new scheduler("../../crons");

include("../../includes/formDefinitions/form_scheduler.php");

if (isset($engine->cleanPost['MYSQL'][$tableName."_submit"])) {

log::insert("Admin: Insert New Cron Job");

$list = defineList($scheduler, $tableName);
$list->insert();
}

if (isset($engine->cleanPost['MYSQL'][$tableName."_update"])) {

log::insert("Admin: Update Cron Job");

$list = defineList($scheduler, $tableName);
$list->update();
}

$list = defineList($scheduler, $tableName);

localVars::add("results",displayMessages());

log::insert("Admin: View Scheduler Page");

$engine->eTemplate("include","header");
?>

<section>
<header class="page-header">
<h1>Manage Cron Jobs</h1>
</header>

<ul class="breadcrumbs">
<li><a href="{local var="siteRoot"}">Home</a></li>
<li><a href="{local var="siteRoot"}/admin/">Admin</a></li>
<li class="pull-right noDivider"><a href="https://github.com/wvulibraries/mfcs/wiki/Scheduler" target="_blank"> <span class="fa fa-book"></span> Documentation</a></li>
</ul>

{local var="results"}

<section>
<header>
<h2>Add New Job</h2>
</header>
{listObject display="insertForm"}
</section>

<hr />

<section>
<header>
<h2>Edit Scheduled Jobs</h2>
</header>
<div class="table-responsive editUsersTable">
{listObject display="editTable"}
</div>
</section>

</section>

<?php
$engine->eTemplate("include","footer");
?>
51 changes: 51 additions & 0 deletions public_html/crons/runcrons.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

// this file should be scheduled to run every 5 minutes.

session_save_path('/tmp');
ini_set('memory_limit',-1);
set_time_limit(0);

require("../header.php");
include("../includes/classes/scheduler.php");

$scheduler = new scheduler(".");

if (!isCLI()) {
print "Must be run from the command line.";
exit;
}

// Turn off EngineAPI template engine
$engine->obCallback = FALSE;

$sql = sprintf("SELECT * FROM `scheduler` WHERE `active` = 1 ");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this being sprintf? Your not formatting anything and your not putting any new statements in. A single string should suffice.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed sprintf.

$sqlResult = $engine->openDB->query($sql);

if (!$sqlResult['result']) {
errorHandle::newError(__METHOD__."() - : ".$sqlResult['error'], errorHandle::DEBUG);
return FALSE;
}

if ($sqlResult['numrows'] == "0") die(date("Y-m-d h:i:sa") . " Nothing to do.\n");

while($row = mysql_fetch_array($sqlResult['result'], MYSQL_ASSOC)) {

// verify scheduled job exists
if (!file_exists($row['name'])) {
notification::notifyAdmins("MFCS Scheduler Run Failure", $row['name'] , "Scheduled Cron Job is missing");
}
elseif ($row['active'] == '1') {
if ($row['runnow'] == '1') {
$scheduler->runjob($row);
print date("Y-m-d h:i:sa") . " Job " . $row['name'] . "\n";
}
elseif ($scheduler->timetorun($row)) {
$scheduler->runjob($row);
print date("Y-m-d h:i:sa") . " Job " . $row['name'] . "\n";
}
}

}

?>
102 changes: 102 additions & 0 deletions public_html/includes/classes/scheduler.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
<?php

class scheduler {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are none of the SQL things namespaced in the scheduler class. Even though they may be done using the command line the classes are still available.


private $availablecrons = array();

public function __construct($dir) {

if (!is_readable($dir)) {
return FALSE;
}

$dir = opendir($dir); // open the cwd..also do an err check.
while(false != ($file = readdir($dir))) {
if(($file != ".") && ($file != "..") && ($file != "runcrons.php")) {
$this->availablecrons[] = array('value' => $file, 'label' => str_replace('_',' ',basename($file,'.php')));
}
}

closedir($dir);

}

public function getCronsArray() {
return $this->availablecrons;
}

public function createSelect($start, $end) {
$selectarray = array();
$selectarray[] = array('value' => '*', 'label' => '*', 'selected' => TRUE);
for ($currentpos = $start; $currentpos <= $end; $currentpos++) {
$selectarray[] = array('value' => (string) $currentpos, 'label' => (string) $currentpos);
}

return $selectarray;

}

public function minuteSelect() {
$minutearray = array();
$minutearray[] = array('value' => '*', 'label' => '*', 'selected' => TRUE);
$minutearray[] = array('value' => '0', 'label' => '0');
$minutearray[] = array('value' => '15', 'label' => '15');
$minutearray[] = array('value' => '30', 'label' => '30');
$minutearray[] = array('value' => '45', 'label' => '45');

return $minutearray;

}

public function monthSelect() {
$month_names = array('January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December');
$montharray = array();
$montharray[] = array('value' => '*', 'label' => '*', 'selected' => TRUE);
for ($currentpos = 1; $currentpos <= 12; $currentpos++) {
$montharray[] = array('value' => (string) $currentpos, 'label' => $month_names[$currentpos-1]);
}

return $montharray;

}

public function weekdaySelect() {
$weekday_names = array('Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday');
$daysarray = array();
$daysarray[] = array('value' => '*', 'label' => '*', 'selected' => TRUE);
for ($currentpos = 0; $currentpos <= 6; $currentpos++) {
$daysarray[] = array('value' => (string) $currentpos, 'label' => $weekday_names[$currentpos]);
}

return $daysarray;

}

public function timetorun($job){
$minuteset = ( ($job['minute'] == date("i")) || ($job['minute'] == '*') );
$hourset = ( ($job['hour'] == date("G")) || ($job['hour'] == '*') );
$dayofmonthset = ( ($job['dayofmonth'] == date("n")) || ($job['dayofmonth'] == '*') );
$monthset = ( ($job['month'] == date("n")) || ($job['month'] == '*') );
$dayofweekset = ( ($job['dayofweek'] == date("w")) || ($job['dayofweek'] == '*') );
return ($minuteset && $hourset && $dayofmonthset && $monthset && $dayofweekset);
}

public function runjob($job){
shell_exec("/usr/bin/php " . $job['name']);

// update last run
$sql = sprintf("UPDATE `scheduler` set `runnow`='%s', `lastrun`='%s' WHERE `ID`='%s' LIMIT 1",
0,
time(),
$job['ID']
);
$sqlResult_insert = mfcs::$engine->openDB->query($sql);

if (!$sqlResult_insert['result']) {
notification::notifyAdmins("MFCS Database Update Failure", "Failed to set runnow to 0 and lastrun to current time", $job['name']);
}
}

}

?>
9 changes: 3 additions & 6 deletions public_html/includes/classes/stats.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

class mfcsStats {

private $statFiles = array();

public function __construct($dir) {
Expand All @@ -14,14 +14,11 @@ public function __construct($dir) {
while(false != ($file = readdir($dir))) {
if(($file != ".") && ($file != "..") && ($file != "index.php")) {
$this->statFiles[] = array('file' => $file, 'name' => str_replace("_"," ",basename($file,".php")));
}
}
}
closedir($dir);


}


public function showStatFiles() {

$output = "<ul>";
Expand All @@ -33,4 +30,4 @@ public function showStatFiles() {
return $output;
}
}
?>
?>
Loading