Skip to content

Commit c22792e

Browse files
committed
reset branch, node versions, projects, branches, releases functions, some fixes, tests
1 parent 14e4122 commit c22792e

16 files changed

+398
-17
lines changed

src/AbstractPlatformDocument.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
namespace CloudCMS;
4+
5+
abstract class AbstractPlatformDocument extends AbstractDocument
6+
{
7+
public $platform;
8+
public $platformId;
9+
10+
public function __construct($platform, $obj)
11+
{
12+
parent::__construct($platform->client, $obj);
13+
14+
$this->platform = $platform;
15+
$this->platformId = $platform->id;
16+
}
17+
}

src/AbstractRepositoryDocument.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,16 @@
22

33
namespace CloudCMS;
44

5-
abstract class AbstractRepositoryDocument extends AbstractDocument
5+
abstract class AbstractRepositoryDocument extends AbstractPlatformDocument
66
{
77
protected $repository;
88
public $repositoryId;
9-
public $platformId;
109

1110
public function __construct($repository, $data)
1211
{
13-
parent::__construct($repository->client, $data);
12+
parent::__construct($repository->platform, $data);
1413

1514
$this->repository = $repository;
1615
$this->repositoryId = $repository->id;
17-
$this->platformId = $repository->platformId;
1816
}
1917
}

src/BaseNode.php

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,33 @@ public function changeQName($newQName)
9090
$params = array();
9191
$params["qname"] = $newQName;
9292

93-
return $this->client->post($uri, $params, array());
93+
$res = $this->client->post($uri, $params, array());
94+
return BaseNode::buildNode($this->branch, $res);
95+
}
96+
97+
public function readVersion($changesetId, $options = array())
98+
{
99+
$uri = $this->uri() . "/versions/" . $changesetId;
100+
$res = $this->client->get($uri, $options);
101+
102+
return BaseNode::buildNode($this->branch, $res);
103+
}
104+
105+
public function listVersions($options = array(), $pagination = array())
106+
{
107+
$uri = $this->uri() . "/versions";
108+
$params = array_merge($options, $pagination);
109+
110+
$res = $this->client->get($uri, $params);
111+
return BaseNode::nodeList($this->branch, $res["rows"]);
112+
}
113+
114+
public function restoreVersion($changesetId)
115+
{
116+
$uri = $this->uri() . "/versions/" . $changesetId . "/restore";
117+
$res = $this->client->post($uri, array(), array());
118+
119+
return BaseNode::buildNode($this->branch, $res);
94120
}
95121

96122
// Static

src/Branch.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace CloudCMS;
44

5+
use CloudCMS\Platform;
6+
57
class Branch extends AbstractRepositoryDocument
68
{
79
public $platformId;
@@ -111,7 +113,7 @@ public function createNode($obj = array(), $options = array())
111113
public function deleteNodes($nodeIds)
112114
{
113115
$uri = $this->uri() . "/nodes/delete";
114-
$this->client->post(uri, $nodeIds);
116+
$this->client->post($uri, $nodeIds);
115117
}
116118

117119
public function graphqlQuery($query, $operationName = null, $variables = array())
@@ -139,4 +141,15 @@ public function graphqlSchema()
139141
$uri = $this->uri() . "/graphql/schema";
140142
return $this->client->request("GET", $uri, array(), array(), false);
141143
}
144+
145+
public function startReset($changesetId)
146+
{
147+
$uri = $this->uri() . "/reset/start";
148+
$params = array("id" => $changesetId);
149+
150+
$res = $this->client->post($uri, $params, array());
151+
$jobId = $res["_doc"];
152+
153+
return $this->platform->readJob($jobId);
154+
}
142155
}

src/CloudCMSException.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
3+
namespace CloudCMS;
4+
5+
class CloudCMSException extends \Exception
6+
{
7+
8+
}

src/Job.php

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
3+
namespace CloudCMS;
4+
5+
class Job extends AbstractDocument
6+
{
7+
public function __construct($client, $data)
8+
{
9+
parent::__construct($client, $data);
10+
}
11+
12+
public function uri()
13+
{
14+
return "/jobs/" . $this->id;
15+
}
16+
17+
public function kill()
18+
{
19+
$uri = $this->uri() . "/kill";
20+
$this->client->post($uri);
21+
}
22+
23+
public function waitForCompletion()
24+
{
25+
while (true)
26+
{
27+
$this->reload();
28+
if (strcmp($this->data["state"], "FINISHED") == 0)
29+
{
30+
return;
31+
}
32+
else if (strcmp($this->data["state"], "ERROR") == 0)
33+
{
34+
throw new CloudCMSException("Job Failed: " . $this->id);
35+
}
36+
else
37+
{
38+
sleep(1);
39+
}
40+
}
41+
}
42+
43+
}

src/Node.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ public function fileFolderTree($basePath = null, $leafPaths = array(), $depth =
119119

120120
if ($containersOnly)
121121
{
122-
$params["containers"] = $containers;
122+
$params["containers"] = $containersOnly;
123123
}
124124

125125
return $this->client->post($uri, $params);

src/Platform.php

Lines changed: 71 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public function listRepositories()
2424
$repositories = array();
2525
foreach($res["rows"] as $row)
2626
{
27-
$repository = new Repository($this->client, $row);
27+
$repository = new Repository($this, $row);
2828
array_push($repositories, $repository);
2929
}
3030

@@ -38,7 +38,7 @@ public function readRepository($repositoryId)
3838
try
3939
{
4040
$res = $this->client->get($uri);
41-
$repository = new Repository($this->client, $res);
41+
$repository = new Repository($this, $res);
4242
}
4343
catch (\GuzzleHttp\Exception\ClientException $ex)
4444
{
@@ -56,4 +56,73 @@ public function createRepository($obj = array())
5656
$repositoryId = $res["_doc"];
5757
return $this->readRepository($repositoryId);
5858
}
59+
60+
public function readJob($jobId)
61+
{
62+
$uri = $this->uri() . "/jobs/" . $jobId;
63+
$res = $this->client->get($uri);
64+
65+
return new Job($this->client, $res);
66+
}
67+
68+
public function queryJobs($query, $pagination = array())
69+
{
70+
$uri = $this->uri() . "/jobs/query";
71+
$res = $this->client->post($uri, $pagination, $query);
72+
73+
$jobs = array();
74+
foreach($res["rows"] as &$row)
75+
{
76+
array_push($jobs, new Job($this->client, $row));
77+
}
78+
79+
return $jobs;
80+
}
81+
82+
// Projects
83+
84+
public function readProject($projectId)
85+
{
86+
$uri = $this->uri() . "/projects/" . $projectId;
87+
$res = $this->client->get($uri);
88+
89+
return new Project($this, $res);
90+
}
91+
92+
public function listProjects($pagination = array())
93+
{
94+
$uri = $this->uri() . "/projects";
95+
$res = $this->client->get($uri, $pagination);
96+
97+
$projects = array();
98+
foreach ($res["rows"] as &$project)
99+
{
100+
array_push($projects, new Project($this, $project));
101+
}
102+
103+
return $projects;
104+
}
105+
106+
public function queryProjects($query, $pagination = array())
107+
{
108+
$uri = $this->uri() . "/projects/query";
109+
$res = $this->client->post($uri, $pagination, $query);
110+
111+
$projects = array();
112+
foreach ($res["rows"] as &$project)
113+
{
114+
array_push($projects, new Project($this, $project));
115+
}
116+
117+
return $projects;
118+
}
119+
120+
public function startCreateProject($obj = array())
121+
{
122+
$uri = $this->uri() . "/projects/start";
123+
$res = $this->client->post($uri, array(), $obj);
124+
125+
$jobId = $res["_doc"];
126+
return $this->readJob($jobId);
127+
}
59128
}

src/Project.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
namespace CloudCMS;
4+
5+
class Project extends AbstractPlatformDocument
6+
{
7+
public function __construct($platform, $data)
8+
{
9+
parent::__construct($platform, $data);
10+
}
11+
12+
public function uri()
13+
{
14+
return $this->platform->uri() . "/projects/" . $this->id;
15+
}
16+
17+
18+
}

src/Release.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
namespace CloudCMS;
4+
5+
class Release extends AbstractRepositoryDocument
6+
{
7+
public function __construct($repository, $data)
8+
{
9+
parent::__construct($repository, $data);
10+
}
11+
12+
public function uri()
13+
{
14+
return $this->repository->uri() . "/releases/" . $this->id;
15+
}
16+
17+
18+
}

0 commit comments

Comments
 (0)