Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--bin/update-hashes.php72
-rw-r--r--site/app/controllers/admin_controller.php2
-rw-r--r--site/app/controllers/components/developers.php2
3 files changed, 37 insertions, 39 deletions
diff --git a/bin/update-hashes.php b/bin/update-hashes.php
index 1e5612a..5d05833 100644
--- a/bin/update-hashes.php
+++ b/bin/update-hashes.php
@@ -22,6 +22,7 @@
* Contributor(s):
* Mike Morgan <morgamic@mozilla.com>
* Justin Scott <fligtar@gmail.com>
+ * Reed Loden <reed@reedloden.com>
*
*
*
@@ -61,55 +62,49 @@ if (isset($_SERVER['HTTP_HOST'])) {
exit;
}
-// If we get here, we're on the command line, which means we can continue.
-// Include config file
-require_once('../site/app/config/config.php');
-require_once('../site/app/config/constants.php');
+require_once('database.class.php');
+
+// New database class
+$db = new Database();
$versions = array();
$hashes = array();
-// Connect to our read-only database.
-$read = mysql_connect(SHADOW_DB_HOST, SHADOW_DB_USER, SHADOW_DB_PASS) or die('Could not connect: ' . mysql_error());
-mysql_select_db(SHADOW_DB_NAME, $read) or die('Could not select database '.SHADOW_DB_NAME);
-
-// Connect to our writable database.
-$write = mysql_connect(DB_HOST, DB_USER, DB_PASS) or die('Could not connect: ' . mysql_error());
-mysql_select_db(DB_NAME, $write) or die('Could not select database '.DB_NAME);
-
-$fileQry = mysql_query("SELECT
- addons.id as addon_id,
- translations.localized_string as name,
- versions.version,
- files.id as file_id,
- files.filename,
- files.hash,
- files.size
- FROM files
- INNER JOIN versions ON files.version_id=versions.id
- INNER JOIN addons ON versions.addon_id=addons.id
- INNER JOIN translations ON addons.name=translations.id
- WHERE
- translations.locale='en-US'"
- , $read);
-
-while ($fileInfo = mysql_fetch_array($fileQry)) {
+$fileQry_sql = "SELECT
+ addons.id as addon_id,
+ translations.localized_string as name,
+ versions.version,
+ files.id as file_id,
+ files.filename,
+ files.hash,
+ files.size
+ FROM files
+ INNER JOIN versions ON files.version_id=versions.id
+ INNER JOIN addons ON versions.addon_id=addons.id
+ INNER JOIN translations ON addons.name=translations.id
+ WHERE
+ translations.locale='en-US'";
+
+$fileQry_result = $db->query($fileQry_sql);
+
+while ($fileInfo = mysql_fetch_array($fileQry_result)) {
$file = REPO_PATH."/{$fileInfo['addon_id']}/{$fileInfo['filename']}";
// If the file exists, get its sum and update its record.
if (file_exists($file) && is_file($file)) {
- $hash = sha1_file($file);
+ $hash = hash_file("sha256", $file);
$size = round((filesize($file) / 1024), 0); //in KB
-
+
echo "{$fileInfo['name']} {$fileInfo['version']} (file {$fileInfo['file_id']}): ";
- if ('sha1:'.$hash != $fileInfo['hash'] || $size != $fileInfo['size']) {
- mysql_query("UPDATE files SET hash='sha1:{$hash}', size='{$size}' WHERE id={$fileInfo['file_id']}", $write);
-
- if ('sha1:'.$hash != $fileInfo['hash']) {
- echo "HASH - new: sha1:{$hash}; old: {$fileInfo['hash']}";
+ if ('sha256:'.$hash != $fileInfo['hash'] || $size != $fileInfo['size']) {
+ $hash_update_sql = "UPDATE files SET hash='sha256:{$hash}', size='{$size}' WHERE id={$fileInfo['file_id']}";
+ $hash_update_result = $db->query($hash_update_sql, true);
+
+ if ('sha256:'.$hash != $fileInfo['hash']) {
+ echo "HASH - new: sha256:{$hash}; old: {$fileInfo['hash']}";
}
-
+
if ($size != $fileInfo['size']) {
echo "SIZE - new: {$size} KB; old: {$fileInfo['size']} KB";
}
@@ -121,5 +116,8 @@ while ($fileInfo = mysql_fetch_array($fileQry)) {
}
}
+// Close our db connection
+$db->close();
+
exit;
?>
diff --git a/site/app/controllers/admin_controller.php b/site/app/controllers/admin_controller.php
index 1d2352a..ccc4614 100644
--- a/site/app/controllers/admin_controller.php
+++ b/site/app/controllers/admin_controller.php
@@ -294,7 +294,7 @@ class AdminController extends AppController
$file = REPO_PATH.'/'.$id.'/'.$file['File']['filename'];
if (file_exists($file)) {
$size = round(filesize($file)/1024, 0); //in KB
- $hash = 'sha1:'.sha1_file($file);
+ $hash = 'sha256:'.hash_file("sha256", $file);
$this->File->save(array('size' => $size, 'hash' => $hash));
diff --git a/site/app/controllers/components/developers.php b/site/app/controllers/components/developers.php
index 0eea256..bb6f93a 100644
--- a/site/app/controllers/components/developers.php
+++ b/site/app/controllers/components/developers.php
@@ -348,7 +348,7 @@ class DevelopersComponent extends Object {
$fileInfo['filename'] = $file['name'];
$fileInfo['size'] = round($file['size']/1024, 0); // in KB
$fileInfo['extension'] = substr($file['name'], strrpos($file['name'], '.'));
- $fileInfo['hash'] = 'sha1:'.sha1_file($file['tmp_name']);
+ $fileInfo['hash'] = 'sha256:'.hash_file("sha256", $file['tmp_name']);
// Check for file extension match
if (!in_array(strtolower($fileInfo['extension']), $allowedExtensions)) {