Skip to content

Commit

Permalink
Send instance ID to the updates server
Browse files Browse the repository at this point in the history
  • Loading branch information
JustBlackBird committed Jun 5, 2015
1 parent 6bf331b commit 5af9f92
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/mibew/libs/classes/Mibew/Maintenance/CronWorker.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,10 @@ protected function getUpdateChecker()
{
if (is_null($this->updateChecker)) {
$this->updateChecker = new UpdateChecker();
$id = Settings::get('_instance_id');
if ($id) {
$this->updateChecker->setInstanceId($id);
}
}

return $this->updateChecker;
Expand Down
45 changes: 44 additions & 1 deletion src/mibew/libs/classes/Mibew/Maintenance/UpdateChecker.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@ class UpdateChecker
*/
private $url = null;

/**
* Unique 64 character length ID of the Mibew instance.
*
* @var string
*/
private $instanceId = '';

/**
* A cache for plugins info array.
*
Expand Down Expand Up @@ -72,6 +79,34 @@ public function getUrl()
: $this->url;
}

/**
* Sets Unique ID of the Mibew instance.
*
* @param string $id Unique ID that is 64 characters length at most.
* @throws \InvalidArgumentException
*/
public function setInstanceId($id)
{
if (strlen($id) > 64) {
throw new \InvalidArgumentException(
'The ID is too long. It can be 64 characters length at most.'
);
}

// Make sure the ID is always a string.
$this->instanceId = $id ?: '';
}

/**
* Retrieve Unique ID of the Mibew instance.
*
* @return string
*/
public function getInstanceId()
{
return $this->instanceId;
}

/**
* Retrieves list of errors that took place during update checking process.
*
Expand Down Expand Up @@ -157,10 +192,18 @@ public function run()
*/
protected function getSystemInfo()
{
return array(
$info = array(
'core' => MIBEW_VERSION,
'plugins' => $this->getPluginsInfo(),
);

// Attach Instance ID to the info but only if it's not empty.
$id = $this->getInstanceId();
if ($id) {
$info['uid'] = $id;
}

return $info;
}

/**
Expand Down

0 comments on commit 5af9f92

Please sign in to comment.