Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
ark-manager
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
CI / CD
CI / CD
Pipelines
Schedules
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Commits
Open sidebar
snac
ark-manager
Commits
bca9a47c
Commit
bca9a47c
authored
Sep 15, 2016
by
Robbie Hott
1
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added real ark minting from the postgres ark cache
parent
de7d41d4
Pipeline
#695
passed with stage
in 2 minutes 58 seconds
Changes
2
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
35 additions
and
4 deletions
+35
-4
ArkManager.php
src/ark/ArkManager.php
+27
-4
ArkManagerTest.php
test/ark/ArkManagerTest.php
+8
-0
No files found.
src/ark/ArkManager.php
View file @
bca9a47c
...
...
@@ -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
=
''
;
...
...
test/ark/ArkManagerTest.php
View file @
bca9a47c
...
...
@@ -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);
}
**/
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment