Skip to content

Commit

Permalink
v1.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Maikuolan committed Sep 9, 2018
1 parent b40372c commit a860541
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 21 deletions.
11 changes: 10 additions & 1 deletion Changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,16 @@ Versioning guidelines for SemVer can be found at: http://www.semver.org/

=== Changes made since last versioned release ===

- [2018.09.05; Maikuolan]: Implemented some rudimentary optional debugging.
(none)

=== Version/Release 1.2.0 ===
MINOR RELEASE.

- [2018.09.05/10; Maikuolan; Minor code change]: Implemented some rudimentary
optional debugging. Errors can now be logged accordingly.

Caleb M (Maikuolan),
Sep 10, 2018.

=== Version/Release 1.1.0 ===
MINOR RELEASE.
Expand Down
37 changes: 17 additions & 20 deletions src/Cronable.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
namespace Maikuolan\Cronable;

/**
* Cronable v1.2.0 (last modified: 2018.09.05).
* Cronable v1.2.0 (last modified: 2018.09.10).
*
* Description: Cronable is a simple script that allows auto-updating CIDRAM
* and phpMussel via cronjobs.
Expand Down Expand Up @@ -31,6 +31,18 @@ class Cronable
/** Determines whether to display debugging information when relevant. */
public $Debugging = false;

/** Generate error logs when debugging is enabled. */
private function cronableError($Identifier, $Method, $Task, $Results = 'Results are empty')
{
$Data = sprintf("Debugging (%1\$s):\n- Method: `%2\$s`.\n- Task: `%3\$s`.\n- %4\$s.\n\n", $Identifier, $Method, $Task, $Results);
$File = __DIR__ . '/error.log';
if ($Handle = fopen($File, 'a')) {
fwrite($Handle, $Data);
fclose($Handle);
}
$this->Output .= $Data;
}

/**
* Used to send cURL requests.
*
Expand Down Expand Up @@ -136,7 +148,7 @@ private function update($Arr)
/** Build identifier. */
private function buildIdentifier($Package, $Location)
{
$Location = preg_replace('~^(?:https?\:\/\/)?(?:www[0-9]{0,3}\.)?~i', '', $Location);
$Location = preg_replace('~^(?:https?\:\/\/)?(?:www\d{0,3}\.)?~i', '', $Location);
return '[' . $Package . '@' . $Location . ']';
}

Expand All @@ -159,12 +171,7 @@ public function execute()
} elseif ($Results === false) {
$this->Output .= 'An error occurred while attempting to update at ' . $Identifier . ". :-(\n\n";
if ($this->Debugging) {
$this->Output .= sprintf(
"Debugging (%1\$s):\n- Method: `%2\$s`.\n- Task: `%3\$s`.\n- Results === `false`.\n\n",
$Identifier,
'execute()',
$Task
);
$this->cronableError($Identifier, 'execute()', $Task, 'Results === `false`');
}
} else {
$this->Output .= 'Status for ' . $Identifier . " is as follows:\n" . $Results . "\n\n";
Expand Down Expand Up @@ -215,12 +222,7 @@ public function localUpdate($Package, $Username, $Password, $Location)
if (empty($Results)) {
$this->Output .= 'An error occurred while attempting to update at ' . $Identifier . ". :-(\n\n";
if ($this->Debugging) {
$this->Output .= sprintf(
"Debugging (%1\$s):\n- Method: `%2\$s`.\n- Task: `%3\$s`.\n- Results are empty.\n\n",
$Identifier,
'localUpdate()',
$Location
);
$this->cronableError($Identifier, 'localUpdate()', $Location);
}
} elseif (empty($Results['state_msg'])) {
$this->Output .= 'Everything already up-to-date at ' . $Identifier . ". :-)\n\n";
Expand All @@ -230,12 +232,7 @@ public function localUpdate($Package, $Username, $Password, $Location)
} else {
$this->Output .= 'An error occurred while attempting to update at ' . $Identifier . ". :-(\n\n";
if ($this->Debugging) {
$this->Output .= sprintf(
"Debugging (%1\$s):\n- Method: `%2\$s`.\n- Task: `%3\$s`.\n- Package not known or location unreadable.\n\n",
$Identifier,
'localUpdate()',
$Location
);
$this->cronableError($Identifier, 'localUpdate()', $Location, 'Package not known or location unreadable');
}
}
$this->Output .= "===\n\nTime: " . date('r') . "\n\n\n";
Expand Down

0 comments on commit a860541

Please sign in to comment.