Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/test-api.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ jobs:
run: sudo apt-get install curl jq wget -y

# Wait for the API to be ready
# Generally after the 30 first minutes of the current hour (xx:30 to xx:59)
# Generally after the 45 first minutes of the current hour (xx:45 to xx:59)
- name: Wait until API URL is ready
run: |
while (true); do
if $(date +%M | grep -q '^[3-5][0-9]$'); then
if $(date +%M | grep -q '^[4-5][5-9]$'); then
break
fi

Expand Down
2 changes: 1 addition & 1 deletion www/config/properties.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
$config = array(
'project_name' => 'Repomanager',
'project_dir_name' => 'repomanager',
'project_logo' => 'https://github.com/lbr38/repomanager/raw/main/www/public/assets/images/repomanager.png',
'project_logo' => 'https://raw.githubusercontent.com/lbr38/repomanager/main/www/public/assets/official-logo/repomanager-gray-256.png',
'project_git_repo' => 'https://github.com/lbr38/repomanager',
'project_git_repo_raw' => 'https://raw.githubusercontent.com/lbr38/repomanager/main',
'project_update_doc_url' => 'https://github.com/lbr38/repomanager/wiki/01.-Installation-and-update#update-repomanager',
Expand Down
25 changes: 23 additions & 2 deletions www/controllers/Repo/Environment.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,31 @@ public function __construct()
}

/**
* Associate a new env to a snapshot
* Associate a new environment to a snapshot
*/
public function add(string $env, string $description = null, int $snapId)
public function add(string $env, string $description = null, int $snapId) : void
{
$this->model->add($env, $description, $snapId);
}

/**
* Remove an environment from a snapshot
*/
public function remove(int $id) : void
{
$this->model->remove($id);
}

/**
* Update environment description
*/
public function updateDescription(int $id, string $description) : void
{
// Description should not contain single quotes or backslashes
if (str_contains($description, "'") || str_contains($description, "\\") || str_contains($description, '<?') || str_contains($description, '?>')) {
throw new Exception('Description contains invalid characters');
}

$this->model->updateDescription($id, \Controllers\Common::validateData($description));
}
}
27 changes: 19 additions & 8 deletions www/controllers/Repo/Mirror/Deb.php
Original file line number Diff line number Diff line change
Expand Up @@ -767,16 +767,15 @@ private function downloadDebPackages($url)
}

/**
* Deduplication
* Check if package already exists in the previous snapshot
* If so, just create a hard link to the package
*/
if (REPO_DEDUPLICATION) {
if (isset($this->previousSnapshotDirPath)) {
if (file_exists($this->previousSnapshotDirPath . '/' . $relativeDir . '/' . $debPackageName)) {
/**
* Create hard link to the package
*/
if (isset($this->previousSnapshotDirPath)) {
if (file_exists($this->previousSnapshotDirPath . '/' . $relativeDir . '/' . $debPackageName)) {
/**
* If deduplication is enabled
* Create a hard link to the package
*/
if (REPO_DEDUPLICATION) {
if (!link($this->previousSnapshotDirPath . '/' . $relativeDir . '/' . $debPackageName, $absoluteDir . '/' . $debPackageName)) {
throw new Exception('Cannot create hard link to package: ' . $this->previousSnapshotDirPath . '/' . $relativeDir . '/' . $debPackageName);
}
Expand All @@ -785,6 +784,18 @@ private function downloadDebPackages($url)

continue;
}

/**
* If deduplication is not enabled
* Copy package from the previous snapshot
*/
if (!copy($this->previousSnapshotDirPath . '/' . $relativeDir . '/' . $debPackageName, $absoluteDir . '/' . $debPackageName)) {
throw new Exception('Cannot copy package from previous snapshot: ' . $this->previousSnapshotDirPath . '/' . $relativeDir . '/' . $debPackageName);
}

$this->taskLogSubStepController->completed('Copied from previous snapshot');

continue;
}
}

Expand Down
27 changes: 19 additions & 8 deletions www/controllers/Repo/Mirror/Rpm.php
Original file line number Diff line number Diff line change
Expand Up @@ -781,16 +781,15 @@ private function downloadRpmPackages(string $url)
}

/**
* Deduplication
* Check if package already exists in the previous snapshot
* If so, just create a hard link to the package
*/
if (REPO_DEDUPLICATION) {
if (isset($this->previousSnapshotDirPath)) {
if (file_exists($this->previousSnapshotDirPath . '/' . $relativeDir . '/' . $rpmPackageName)) {
/**
* Create hard link to the package
*/
if (isset($this->previousSnapshotDirPath)) {
if (file_exists($this->previousSnapshotDirPath . '/' . $relativeDir . '/' . $rpmPackageName)) {
/**
* If deduplication is enabled
* Create a hard link to the package
*/
if (REPO_DEDUPLICATION) {
if (!link($this->previousSnapshotDirPath . '/' . $relativeDir . '/' . $rpmPackageName, $absoluteDir . '/' . $rpmPackageName)) {
throw new Exception('Cannot create hard link to package: ' . $this->previousSnapshotDirPath . '/' . $relativeDir . '/' . $rpmPackageName);
}
Expand All @@ -799,6 +798,18 @@ private function downloadRpmPackages(string $url)

continue;
}

/**
* If deduplication is not enabled
* Copy package from the previous snapshot
*/
if (!copy($this->previousSnapshotDirPath . '/' . $relativeDir . '/' . $rpmPackageName, $absoluteDir . '/' . $rpmPackageName)) {
throw new Exception('Cannot copy package from previous snapshot: ' . $this->previousSnapshotDirPath . '/' . $relativeDir . '/' . $rpmPackageName);
}

$this->taskLogSubStepController->completed('Copied from previous snapshot');

continue;
}
}

Expand Down
31 changes: 0 additions & 31 deletions www/controllers/Repo/Repo.php
Original file line number Diff line number Diff line change
Expand Up @@ -522,21 +522,6 @@ public function getEnvIdBySnapId(string $snapId)
return $this->model->getEnvIdBySnapId($snapId);
}

/**
* Set environment description
*/
public function envSetDescription(string $envId, string $description) : void
{
// Description cannot contain single quotes or backslashes
if (str_contains($description, "'") || str_contains($description, "\\")) {
throw new Exception('Description contains invalid characters');
}

$description = \Controllers\Common::validateData($description);

$this->model->envSetDescription($envId, $description);
}

/**
* Get repository environment description by the repo name
*/
Expand Down Expand Up @@ -627,22 +612,6 @@ public function snapSetPackagesExcluded(int $snapId, array $packages)
$this->model->snapSetPackagesExcluded($snapId, implode(',', $packages));
}

/**
* Add a repo snapshot in database
*/
public function addSnap(string $date, string $time, string $gpgSignature, array $arch, array $includeTranslation, array $packagesIncluded, array $packagesExcluded, string $type, string $status, string $repoId)
{
$this->model->addSnap($date, $time, $gpgSignature, $arch, $includeTranslation, $packagesIncluded, $packagesExcluded, $type, $status, $repoId);
}

/**
* Remove an env in database
*/
public function removeEnv(string $envId)
{
$this->model->removeEnv($envId);
}

/**
* Return snapshot date from database, from its Id
*/
Expand Down
16 changes: 16 additions & 0 deletions www/controllers/Repo/Snapshot.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,22 @@ private function getUnused(string $repoId, string $retention) : array
return $this->model->getUnused($repoId, $retention);
}

/**
* Return the last insert row ID in database
*/
public function getLastInsertRowID()
{
return $this->model->getLastInsertRowID();
}

/**
* Add a snapshot in database
*/
public function add(string $date, string $time, string $gpgSignature, array $arch, array $includeTranslation, array $packagesIncluded, array $packagesExcluded, string $type, string $status, int $repoId) : void
{
$this->model->add($date, $time, $gpgSignature, $arch, $includeTranslation, $packagesIncluded, $packagesExcluded, $type, $status, $repoId);
}

/**
* Update snapshot status in the database
*/
Expand Down
4 changes: 2 additions & 2 deletions www/controllers/Task/Notify.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ public function error(array $task, string $error)
$message .= '<br>';

$mailSubject = '[ ERROR ] Scheduled task #' . $task['Id'] . ' failed on ' . WWW_HOSTNAME;
$mymail = new \Controllers\Mail(implode(',', $taskRawParams['schedule']['schedule-recipient']), $mailSubject, $message, __SERVER_PROTOCOL__ . '://' . WWW_HOSTNAME . '/run/' . $task['Id'], 'View log file');
$mymail = new \Controllers\Mail(implode(',', $taskRawParams['schedule']['schedule-recipient']), $mailSubject, $message, __SERVER_PROTOCOL__ . '://' . WWW_HOSTNAME . '/run/' . $task['Id'], 'View task log');
}

/**
Expand All @@ -168,6 +168,6 @@ public function success(array $task)
$message .= '<br>';

$mailSubject = '[ SUCCESS ] Scheduled task #' . $task['Id'] . ' succeeded on ' . WWW_HOSTNAME;
$mymail = new \Controllers\Mail(implode(',', $taskRawParams['schedule']['schedule-recipient']), $mailSubject, $message, __SERVER_PROTOCOL__ . '://' . WWW_HOSTNAME . '/run/' . $task['Id'], 'View log file');
$mymail = new \Controllers\Mail(implode(',', $taskRawParams['schedule']['schedule-recipient']), $mailSubject, $message, __SERVER_PROTOCOL__ . '://' . WWW_HOSTNAME . '/run/' . $task['Id'], 'View task log');
}
}
4 changes: 2 additions & 2 deletions www/controllers/Task/Repo/Create.php
Original file line number Diff line number Diff line change
Expand Up @@ -335,12 +335,12 @@ private function local()
/**
* Add snapshot to database
*/
$this->repo->addSnap($this->repo->getDate(), $this->repo->getTime(), 'false', $this->repo->getArch(), array(), array(), array(), $this->repo->getType(), 'active', $this->repo->getRepoId());
$this->repoSnapshotController->add($this->repo->getDate(), $this->repo->getTime(), 'false', $this->repo->getArch(), array(), array(), array(), $this->repo->getType(), 'active', $this->repo->getRepoId());

/**
* Retrieve snapshot Id from the last insert row
*/
$this->repo->setSnapId($this->repo->getLastInsertRowID());
$this->repo->setSnapId($this->repoSnapshotController->getLastInsertRowID());

/**
* Add env to database if an env has been specified by the user
Expand Down
6 changes: 4 additions & 2 deletions www/controllers/Task/Repo/Duplicate.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class Duplicate
private $repo;
private $rpmRepoController;
private $debRepoController;
private $repoSnapshotController;
private $repoEnvController;
private $task;
private $taskLogStepController;
Expand All @@ -25,6 +26,7 @@ public function __construct(string $taskId)
$this->rpmRepoController = new \Controllers\Repo\Rpm();
$this->debRepoController = new \Controllers\Repo\Deb();
$this->task = new \Controllers\Task\Task();
$this->repoSnapshotController = new \Controllers\Repo\Snapshot();
$this->repoEnvController = new \Controllers\Repo\Environment();
$this->taskLogStepController = new \Controllers\Task\Log\Step($taskId);
$this->taskLogSubStepController = new \Controllers\Task\Log\SubStep($taskId);
Expand Down Expand Up @@ -324,12 +326,12 @@ public function execute()
/**
* Add the new repo snapshot in database
*/
$this->repo->addSnap($this->repo->getDate(), $this->repo->getTime(), $this->repo->getSigned(), $this->repo->getArch(), array(), $this->repo->getPackagesToInclude(), $this->repo->getPackagesToExclude(), $this->repo->getType(), $this->repo->getStatus(), $targetRepoId);
$this->repoSnapshotController->add($this->repo->getDate(), $this->repo->getTime(), $this->repo->getSigned(), $this->repo->getArch(), array(), $this->repo->getPackagesToInclude(), $this->repo->getPackagesToExclude(), $this->repo->getType(), $this->repo->getStatus(), $targetRepoId);

/**
* Retrieve the Id of the new repo snapshot in database
*/
$targetSnapId = $this->repo->getLastInsertRowID();
$targetSnapId = $this->repoSnapshotController->getLastInsertRowID();

/**
* Add the new repo environment in database, only if the user has specified an environment
Expand Down
4 changes: 2 additions & 2 deletions www/controllers/Task/Repo/Env.php
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ public function execute()
*/
if (!empty($actualEnvIds)) {
foreach ($actualEnvIds as $actualEnvId) {
$this->repo->removeEnv($actualEnvId['Id']);
$this->repoEnvController->remove($actualEnvId['Id']);
}
}

Expand Down Expand Up @@ -255,7 +255,7 @@ public function execute()
*/
if (!empty($actualEnvIds)) {
foreach ($actualEnvIds as $actualEnvId) {
$this->repo->removeEnv($actualEnvId['Id']);
$this->repoEnvController->remove($actualEnvId['Id']);
}
}

Expand Down
10 changes: 5 additions & 5 deletions www/controllers/Task/Repo/Finalize.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,12 @@ protected function finalize()
* Add snapshot in database
* Empty array() for package translation because it's not used for the moment
*/
$this->repo->addSnap($this->repo->getDate(), $this->repo->getTime(), $this->repo->getGpgSign(), $this->repo->getArch(), array(), $this->repo->getPackagesToInclude(), $this->repo->getPackagesToExclude(), $this->repo->getType(), 'active', $this->repo->getRepoId());
$this->repoSnapshotController->add($this->repo->getDate(), $this->repo->getTime(), $this->repo->getGpgSign(), $this->repo->getArch(), array(), $this->repo->getPackagesToInclude(), $this->repo->getPackagesToExclude(), $this->repo->getType(), 'active', $this->repo->getRepoId());

/**
* Retrieve the last insert row ID
*/
$this->repo->setSnapId($this->repo->getLastInsertRowID());
$this->repo->setSnapId($this->repoSnapshotController->getLastInsertRowID());

/**
* Add env in database if an env has been specified by the user
Expand Down Expand Up @@ -123,13 +123,13 @@ protected function finalize()
/**
* Add snapshot in database
*/
$this->repo->addSnap($this->repo->getDate(), $this->repo->getTime(), $this->repo->getGpgSign(), $this->repo->getArch(), array(), $this->repo->getPackagesToInclude(), $this->repo->getPackagesToExclude(), $this->repo->getType(), 'active', $this->repo->getRepoId());
$this->repoSnapshotController->add($this->repo->getDate(), $this->repo->getTime(), $this->repo->getGpgSign(), $this->repo->getArch(), array(), $this->repo->getPackagesToInclude(), $this->repo->getPackagesToExclude(), $this->repo->getType(), 'active', $this->repo->getRepoId());

/**
* Retrieve the last insert row Id
* And we can set snapId = this Id
*/
$this->repo->setSnapId($this->repo->getLastInsertRowID());
$this->repo->setSnapId($this->repoSnapshotController->getLastInsertRowID());
}
}

Expand Down Expand Up @@ -173,7 +173,7 @@ protected function finalize()
*/
if (!empty($actualEnvIds)) {
foreach ($actualEnvIds as $actualEnvId) {
$this->repo->removeEnv($actualEnvId['Id']);
$this->repoEnvController->remove($actualEnvId['Id']);
}
}

Expand Down
4 changes: 3 additions & 1 deletion www/controllers/Task/Repo/RemoveEnv.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class RemoveEnv
private $repo;
private $task;
private $repoSnapshotController;
private $repoEnvController;
private $taskLogStepController;
private $taskLogSubStepController;

Expand All @@ -19,6 +20,7 @@ public function __construct(string $taskId)
$this->repo = new \Controllers\Repo\Repo();
$this->task = new \Controllers\Task\Task();
$this->repoSnapshotController = new \Controllers\Repo\Snapshot();
$this->repoEnvController = new \Controllers\Repo\Environment();
$this->taskLogStepController = new \Controllers\Task\Log\Step($taskId);
$this->taskLogSubStepController = new \Controllers\Task\Log\SubStep($taskId);

Expand Down Expand Up @@ -84,7 +86,7 @@ public function execute()
/**
* Delete environment from database
*/
$this->repo->removeEnv($this->repo->getEnvId());
$this->repoEnvController->remove($this->repo->getEnvId());

$this->taskLogStepController->completed();

Expand Down
16 changes: 0 additions & 16 deletions www/controllers/ajax/repo.php
Original file line number Diff line number Diff line change
@@ -1,20 +1,4 @@
<?php

/**
* Edit a repo description
*/
if ($_POST['action'] == "setRepoDescription" and !empty($_POST['envId']) and isset($_POST['description'])) {
$myrepo = new \Controllers\Repo\Repo();

try {
$myrepo->envSetDescription($_POST['envId'], $_POST['description']);
} catch (\Exception $e) {
response(HTTP_BAD_REQUEST, $e->getMessage());
}

response(HTTP_OK, "Description has been saved");
}

/**
* Get repo size
*/
Expand Down
18 changes: 18 additions & 0 deletions www/controllers/ajax/repo/environment.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

/**
* Edit a repo description
*/
if ($_POST['action'] == 'update-description' and !empty($_POST['envId']) and isset($_POST['description'])) {
$repoEnvController = new \Controllers\Repo\Environment();

try {
$repoEnvController->updateDescription($_POST['envId'], $_POST['description']);
} catch (\Exception $e) {
response(HTTP_BAD_REQUEST, $e->getMessage());
}

response(HTTP_OK, "Description has been saved");
}

response(HTTP_BAD_REQUEST, 'Invalid action');
Loading