Skip to content

Commit

Permalink
Updater Tool
Browse files Browse the repository at this point in the history
  • Loading branch information
Jon Belelieu authored and Jon Belelieu committed Mar 8, 2016
1 parent d5a715b commit 072ab27
Show file tree
Hide file tree
Showing 6 changed files with 182 additions and 4 deletions.
3 changes: 2 additions & 1 deletion .gitignore
@@ -1,2 +1,3 @@
.idea .idea
.DS_Store .DS_Store
custom/errors.txt
1 change: 1 addition & 0 deletions admin/sd-system/loader.php
Expand Up @@ -12,6 +12,7 @@
ini_set("log_errors", "1"); ini_set("log_errors", "1");
ini_set("error_log", PP_PATH . "/custom/errors.txt"); ini_set("error_log", PP_PATH . "/custom/errors.txt");
error_reporting(0); error_reporting(0);
ini_set('display_errors', 0);
//error_reporting(1); //error_reporting(1);
//error_reporting(E_ALL); //error_reporting(E_ALL);


Expand Down
6 changes: 4 additions & 2 deletions custom/admin_extensions/.gitignore
@@ -1,3 +1,5 @@
/* # Ignore everything
*


!.gitignore # But not these files...
!route.php
66 changes: 66 additions & 0 deletions custom/admin_extensions/route.php
@@ -0,0 +1,66 @@
<?php

require "../../admin/sd-system/config.php";

$admin = new admin;

/* -- Admin Session -- */
$employee = $admin->check_employee('', '0');

if (empty($_POST['ext'])) {
echo "0+++No extension received.";
exit;
}
else {

$ext = htmlentities($_POST['ext']);

$path = PP_PATH . '/custom/admin_extensions/' . $ext . '/package.php';

if (! file_exists($path)) {
echo "0+++Could not find package.";
exit;
}
else {

$action = (! empty($_POST['edit'])) ? 'edit' : 'add';

$check = PP_PATH . '/custom/admin_extensions/' . $ext . '/ExtensionObject.php';

if (! file_exists($check)) {
echo "0+++Extension class doesn't exist.";
exit;
}
else {

require $check;
$extObj = new ExtensionObject();

if (! method_exists($extObj, $action)) {
echo "0+++Method does not exist.";
}
else {

$run = $extObj->$action($_POST);

if ($run['error']) {
$msg = "0+++";
} else {
$msg = "1+++";
}

$return = array(
'close_popup' => '1',
'show_saved' => $run['message'],
);

echo $msg . json_encode($return);
exit;

}

}

}

}
108 changes: 108 additions & 0 deletions custom/updates/updater.php
@@ -0,0 +1,108 @@
<?php

/**
* This file allow you to run updates and keep your database in sync.
*
* Zenbership Membership Software
* Copyright (C) 2013-2016 Castlamp, LLC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @author Castlamp
* @link http://www.castlamp.com/
* @license GNU General Public License v3.0
* @link http://www.gnu.org/licenses/gpl.html
* @date 2/25/13 2:55 PM
* @version v1.0
*/


echo "<html><head><title>Zenbership Database Updater</title><style>";
echo <<<qq
body {
padding: 42px 25%;
font-family: arial;
font-size: 0.9em;
line-height: 1.5em;
color: #555;
}
qq;
echo "</style></head><body>";



require dirname(dirname(dirname(__FILE__))) . "/admin/sd-system/config.php";
$db = new db();

$current_version = $db->get_option('current_version');
$current_version = str_replace('.', '', $current_version);

$commands = array();

$updating_to = $current_version;

$dir = scandir('.');
foreach ($dir as $file) {
if ($file == '.' || $file == '..' || $file == 'updater.php') {
continue;
} else {
$version = str_replace('.php', '', $file);

if ($current_version < $version) {
$these = include($file);
$commands = array_merge($commands, $these);

if ($version > $updating_to) {
$updating_to = $version;
}
}

}
}

if ($updating_to == $current_version) {
echo "<h1>You're good!</h1>";
echo "<p>You have the latest version. Way to be responsible!</p>";
echo "</body></html>";
exit;
}

echo "<h1>Updating you from $current_version to v$updating_to</h1>";

$total = sizeof($commands);
$up = 0;
foreach ($commands as $item) {
$up++;
echo "<li>Running update $up of $total...";

$result = @$db->run_query($item);

echo " complete!</li>";
}

$db->update_option('current_version', $updating_to);

echo <<<qq
<p>Your database update is complete.</p>
<p>We recommend that you delete all files in this directory except updater.php.</p>
<p>Remember that this only updated your database. <b>Be sure to download the newest files from
Github, and upload them over your existing files to complete the update!</b>. When updating files,
make sure you don't replace your templates, custom, or sd-system folders!</p>
</body></html>
qq;
exit;
2 changes: 1 addition & 1 deletion setup/assets/functions.php
Expand Up @@ -2,7 +2,7 @@


function installed_version() function installed_version()
{ {
return '1.0.5'; return '107';
} }


function current_url() function current_url()
Expand Down

0 comments on commit 072ab27

Please sign in to comment.