summaryrefslogtreecommitdiff
path: root/modules/gallery
diff options
context:
space:
mode:
authorBharat Mediratta <bharat@menalto.com>2010-12-15 12:48:56 -0800
committerBharat Mediratta <bharat@menalto.com>2010-12-15 12:48:56 -0800
commit45c63f4d118bfc99924edb8685442035349af6db (patch)
tree995e248347743f905d7c8fc29343e88d74b31441 /modules/gallery
parent6fb0eb4e97e3bbfa50029f0b4249c10bd22abe09 (diff)
Use mt_rand() instead of rand() since it provides better portability.
Fixes #1527.
Diffstat (limited to 'modules/gallery')
-rw-r--r--modules/gallery/controllers/upgrader.php2
-rw-r--r--modules/gallery/helpers/access.php2
-rw-r--r--modules/gallery/helpers/block_manager.php2
-rw-r--r--modules/gallery/helpers/gallery_installer.php4
-rw-r--r--modules/gallery/models/item.php4
-rw-r--r--modules/gallery/tests/Albums_Controller_Test.php2
-rw-r--r--modules/gallery/tests/Cache_Test.php30
-rw-r--r--modules/gallery/tests/Item_Helper_Test.php2
-rw-r--r--modules/gallery/tests/Item_Model_Test.php4
9 files changed, 26 insertions, 26 deletions
diff --git a/modules/gallery/controllers/upgrader.php b/modules/gallery/controllers/upgrader.php
index b2646874..50f6b8f0 100644
--- a/modules/gallery/controllers/upgrader.php
+++ b/modules/gallery/controllers/upgrader.php
@@ -23,7 +23,7 @@ class Upgrader_Controller extends Controller {
// Make sure we have an upgrade token
if (!($upgrade_token = $session->get("upgrade_token", null))) {
- $session->set("upgrade_token", $upgrade_token = md5(rand()));
+ $session->set("upgrade_token", $upgrade_token = md5(time() . mt_rand()));
}
// If the upgrade token exists, then bless this session
diff --git a/modules/gallery/helpers/access.php b/modules/gallery/helpers/access.php
index 0b0dcbc1..6a948999 100644
--- a/modules/gallery/helpers/access.php
+++ b/modules/gallery/helpers/access.php
@@ -426,7 +426,7 @@ class access_Core {
$session = Session::instance();
$csrf = $session->get("csrf");
if (empty($csrf)) {
- $csrf = md5(rand());
+ $csrf = md5(time() . mt_rand());
$session->set("csrf", $csrf);
}
return $csrf;
diff --git a/modules/gallery/helpers/block_manager.php b/modules/gallery/helpers/block_manager.php
index 2237b702..e7247edc 100644
--- a/modules/gallery/helpers/block_manager.php
+++ b/modules/gallery/helpers/block_manager.php
@@ -28,7 +28,7 @@ class block_manager_Core {
static function add($location, $module_name, $block_id) {
$blocks = block_manager::get_active($location);
- $blocks[rand()] = array($module_name, $block_id);
+ $blocks[mt_rand()] = array($module_name, $block_id);
block_manager::set_active($location, $blocks);
}
diff --git a/modules/gallery/helpers/gallery_installer.php b/modules/gallery/helpers/gallery_installer.php
index 3d82bc69..9c42caad 100644
--- a/modules/gallery/helpers/gallery_installer.php
+++ b/modules/gallery/helpers/gallery_installer.php
@@ -459,7 +459,7 @@ class gallery_installer {
$blocks = block_manager::get_active($location);
$new_blocks = array();
foreach ($blocks as $block) {
- $new_blocks[rand()] = $block;
+ $new_blocks[mt_rand()] = $block;
}
block_manager::set_active($location, $new_blocks);
}
@@ -507,7 +507,7 @@ class gallery_installer {
->execute() as $row) {
$new_slug = item::convert_filename_to_slug($row->slug);
if (empty($new_slug)) {
- $new_slug = rand();
+ $new_slug = mt_rand();
}
db::build()
->update("items")
diff --git a/modules/gallery/models/item.php b/modules/gallery/models/item.php
index a4d24b8f..b6713fc3 100644
--- a/modules/gallery/models/item.php
+++ b/modules/gallery/models/item.php
@@ -390,7 +390,7 @@ class Item_Model_Core extends ORM_MPTT {
if (file_exists($this->resize_path()) ||
file_exists($this->thumb_path())) {
$pi = pathinfo($this->name);
- $this->name = $pi["filename"] . "-" . rand() . "." . $pi["extension"];
+ $this->name = $pi["filename"] . "-" . mt_rand() . "." . $pi["extension"];
parent::save();
}
@@ -512,7 +512,7 @@ class Item_Model_Core extends ORM_MPTT {
->or_where("slug", "=", $this->slug)
->close()
->find()->id) {
- $rand = rand();
+ $rand = mt_rand();
if ($base_ext) {
$this->name = "$base_name-$rand.$base_ext";
} else {
diff --git a/modules/gallery/tests/Albums_Controller_Test.php b/modules/gallery/tests/Albums_Controller_Test.php
index 6c64394d..86c74890 100644
--- a/modules/gallery/tests/Albums_Controller_Test.php
+++ b/modules/gallery/tests/Albums_Controller_Test.php
@@ -31,7 +31,7 @@ class Albums_Controller_Test extends Gallery_Unit_Test_Case {
$album = test::random_album();
// Randomize to avoid conflicts.
- $new_name = "new_name_" . rand();
+ $new_name = "new_name_" . mt_rand();
$_POST["name"] = $new_name;
$_POST["title"] = "new title";
diff --git a/modules/gallery/tests/Cache_Test.php b/modules/gallery/tests/Cache_Test.php
index e8d8b6f4..6cee2862 100644
--- a/modules/gallery/tests/Cache_Test.php
+++ b/modules/gallery/tests/Cache_Test.php
@@ -27,7 +27,7 @@ class Cache_Test extends Gallery_Unit_Test_Case {
public function cache_exists_test() {
$this->assert_false($this->_driver->exists("test_key"), "test_key should not be defined");
- $id = md5(rand());
+ $id = md5(mt_rand());
db::build()
->insert("caches")
->columns("key", "tags", "expiration", "cache")
@@ -38,7 +38,7 @@ class Cache_Test extends Gallery_Unit_Test_Case {
}
public function cache_get_test() {
- $id = md5(rand());
+ $id = md5(mt_rand());
db::build()
->insert("caches")
@@ -54,7 +54,7 @@ class Cache_Test extends Gallery_Unit_Test_Case {
}
public function cache_set_test() {
- $id = md5(rand());
+ $id = md5(mt_rand());
$original_data = array("field1" => "value1", "field2" => "value2");
$this->_driver->set(array($id => $original_data), array("tag1", "tag2"), 84600);
@@ -63,15 +63,15 @@ class Cache_Test extends Gallery_Unit_Test_Case {
}
public function cache_get_tag_test() {
- $id1 = md5(rand());
+ $id1 = md5(mt_rand());
$value1 = array("field1" => "value1", "field2" => "value2");
$this->_driver->set(array($id1 => $value1), array("tag1", "tag2"), 84600);
- $id2 = md5(rand());
+ $id2 = md5(mt_rand());
$value2 = array("field3" => "value3", "field4" => "value4");
$this->_driver->set(array($id2 => $value2), array("tag2", "tag3"), 84600);
- $id3 = md5(rand());
+ $id3 = md5(mt_rand());
$value3 = array("field5" => "value5", "field6" => "value6");
$this->_driver->set(array($id3 => $value3), array("tag3", "tag4"), 84600);
@@ -86,15 +86,15 @@ class Cache_Test extends Gallery_Unit_Test_Case {
}
public function cache_delete_id_test() {
- $id1 = md5(rand());
+ $id1 = md5(mt_rand());
$value1 = array("field1" => "value1", "field2" => "value2");
$this->_driver->set(array($id1 => $value1), array("tag1", "tag2"), 84600);
- $id2 = md5(rand());
+ $id2 = md5(mt_rand());
$value2 = array("field3" => "value3", "field4" => "value4");
$this->_driver->set(array($id2 => $value2), array("tag2", "tag3"), 846000);
- $id3 = md5(rand());
+ $id3 = md5(mt_rand());
$value3 = array("field5" => "value5", "field6" => "value6");
$this->_driver->set(array($id3 => $value3), array("tag3", "tag4"), 84600);
@@ -106,15 +106,15 @@ class Cache_Test extends Gallery_Unit_Test_Case {
}
public function cache_delete_tag_test() {
- $id1 = md5(rand());
+ $id1 = md5(mt_rand());
$value1 = array("field1" => "value1", "field2" => "value2");
$this->_driver->set(array($id1 => $value1), array("tag1", "tag2"), 84600);
- $id2 = md5(rand());
+ $id2 = md5(mt_rand());
$value2 = array("field3" => "value3", "field4" => "value4");
$this->_driver->set(array($id2 => $value2), array("tag2", "tag3"), 846000);
- $id3 = md5(rand());
+ $id3 = md5(mt_rand());
$value3 = array("field5" => "value5", "field6" => "value6");
$this->_driver->set(array($id3 => $value3), array("tag3", "tag4"), 84600);
@@ -126,15 +126,15 @@ class Cache_Test extends Gallery_Unit_Test_Case {
}
public function cache_delete_all_test() {
- $id1 = md5(rand());
+ $id1 = md5(mt_rand());
$value1 = array("field1" => "value1", "field2" => "value2");
$this->_driver->set(array($id1 => $value1), array("tag1", "tag2"), 84600);
- $id2 = md5(rand());
+ $id2 = md5(mt_rand());
$value2 = array("field3" => "value3", "field4" => "value4");
$this->_driver->set(array($id2 => $value2), array("tag2", "tag3"), 846000);
- $id3 = md5(rand());
+ $id3 = md5(mt_rand());
$value3 = array("field5" => "value5", "field6" => "value6");
$this->_driver->set(array($id3 => $value3), array("tag3", "tag4"), 84600);
diff --git a/modules/gallery/tests/Item_Helper_Test.php b/modules/gallery/tests/Item_Helper_Test.php
index eb2458cb..c93cc239 100644
--- a/modules/gallery/tests/Item_Helper_Test.php
+++ b/modules/gallery/tests/Item_Helper_Test.php
@@ -92,7 +92,7 @@ class Item_Helper_Test extends Gallery_Unit_Test_Case {
}
public function move_conflicts_result_in_a_rename_test() {
- $rand = rand();
+ $rand = mt_rand();
$photo1 = test::random_photo_unsaved(item::root());
$photo1->name = "{$rand}.jpg";
$photo1->slug = (string)$rand;
diff --git a/modules/gallery/tests/Item_Model_Test.php b/modules/gallery/tests/Item_Model_Test.php
index 1e6d54d0..0d6d10af 100644
--- a/modules/gallery/tests/Item_Model_Test.php
+++ b/modules/gallery/tests/Item_Model_Test.php
@@ -278,10 +278,10 @@ class Item_Model_Test extends Gallery_Unit_Test_Case {
public function basic_validation_test() {
$item = ORM::factory("item");
- $item->album_cover_item_id = rand(); // invalid
+ $item->album_cover_item_id = mt_rand(); // invalid
$item->description = str_repeat("x", 70000); // invalid
$item->name = null;
- $item->parent_id = rand();
+ $item->parent_id = mt_rand();
$item->slug = null;
$item->sort_column = "bogus";
$item->sort_order = "bogus";