Commit bca9a47c by Robbie Hott

Added real ark minting from the postgres ark cache

parent de7d41d4
Pipeline #695 passed with stage
in 2 minutes 58 seconds
......@@ -33,7 +33,7 @@ class ArkManager {
* Sets up the ArkManager
*/
public function __construct() {
$db = new \ark\database\DatabaseConnector();
$this->db = new \ark\database\DatabaseConnector();
}
/**
......@@ -71,14 +71,37 @@ class ArkManager {
* Mint a real, unique, permanent, resolvable ark. Once an ark is minted using this method, it will never be reassigned. This
* process is irreversible, so use with caution. Because of this, only one may be requested at a time.
*
* @return string A new permanent arkID
* @return string|boolean A new permanent arkID or false if an ark could not be minted
*/
public function mintArk() {
try {
// get the first ark in the list while deleting it (returning *) so that it is atomic
$resource = $this->db->query("delete from unassigned_arks
where id = (select min(id) from unassigned_arks)
returning *;", array());
$result = $this->db->fetchRow($resource);
// If the result exists, is not false, and has an ark, then return the ark
if ($result !== false && is_array($result) && isset($result['ark']))
return $result['ark'];
} catch (\Exception $e) {
// Something went wrong, so no ark can be returned
return false;
}
return false;
}
private function generateRandomString() {
$length = 7;
/**
* Generate a random string
*
* Generate a random ASCII string of a given length. The default length is 7 for temporary ARK URL generation.
*
* @param integer $length optional The length of string to generate
* @param string A random ASCII string
*/
private function generateRandomString($length=7) {
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$cLength = strlen($characters);
$string = '';
......
......@@ -63,4 +63,12 @@ class ArkManagerTest extends \PHPUnit_Framework_TestCase {
$this->assertNotContains($ark, $arks, "Ark was found to repeat: " . $ark);
}
}
/**
* Minting a real ark cannot be tested in production
public function testMintRealArk() {
$ark = $this->am->mintArk();
$this->assertNotFalse($ark);
}
**/
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment