<?php
namespace WpDownloader\Component;
use WpDownloader\MojoApi;
use WpDownloader\Log;
use WpDownloader\Utility;
class MojoPlugin extends Plugin
{
public $slug = 'mojo-marketplace-wp-plugin';
protected $apiVersionData;
public function getLatestVersion()
{
return $this->getApiVersionData()['version'];
}
public function getDownloadUrl()
{
return $this->getApiVersionData()['download_link'];
}
public function getActivationFile()
{
return 'mojo-marketplace-wp-plugin/mojo-marketplace.php';
}
public function getApiVersionData()
{
if (!isset($this->apiVersionData)) {
$this->apiVersionData = MojoApi::getVersionData();
}
return $this->apiVersionData;
}
public function afterSetData()
{
}
public function downloadLatestVersion()
{
$downloadUrl = $this->componentData['endpoint'];
$version = $this->getLatestVersion();
$localFile = $this->downloadFile($downloadUrl, "{$this->temporaryDirectory}/{$this->slug}.php");
if (!$localFile || !file_exists($localFile)) {
Log::throwException("Downloaded failed or local file {$localFile} does not exist.");
}
$this->extractArchive($localFile);
$this->commitTempToPersistent();
$this->appendLocalData(['version' => $version]);
return $version;
}
}