aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorgi Nikolov <ggeorgi60@gmail.com>2025-02-01 18:20:15 +0200
committerGeorgi Nikolov <ggeorgi60@gmail.com>2025-02-01 18:20:15 +0200
commit40b78735aeba6082363e6a8d98b78da9ba230687 (patch)
tree036207435be8d7cc27e1f468f7791c11890709c3
parent34903b6553f6483f52e57133fc6305779461db29 (diff)
downloadnowayforward_human-40b78735aeba6082363e6a8d98b78da9ba230687.tar
nowayforward_human-40b78735aeba6082363e6a8d98b78da9ba230687.tar.gz
nowayforward_human-40b78735aeba6082363e6a8d98b78da9ba230687.zip
Fixed the create table workaround
This included creating an update function that can update the archive after its creation, setting the correct title and favicon path
-rw-r--r--controllers/archive.php8
-rw-r--r--models/webpage.php5
2 files changed, 8 insertions, 5 deletions
diff --git a/controllers/archive.php b/controllers/archive.php
index 35ab1dd..ffe9c70 100644
--- a/controllers/archive.php
+++ b/controllers/archive.php
@@ -37,10 +37,7 @@ class DownloadPage {
$page_url_pattern = $this->getCorrectLinkPattern($this->page_url);
$simular_pages = Database\Webpage::getArchivePathsByPattern('%' . $page_url_pattern . '%');
if ($website_exists) {
- // NOTE: This is incredibly dumb, Databas\Webpage::create returns the
- // auto-incremented ID, so it should be used here.
- // The logic needs to be reorganized!
- $this->folder_name = Database\Webpage::getPagesCount() + 1;
+ $this->folder_name = Database\Webpage::create($folder_location, $this->page_url, $requester_uid, "default", "Default title");
$this->page_contents = $this->downloadFile($this->page_url);
$this->createArchive($simular_pages);
if (!$this->favicon_path) {
@@ -48,7 +45,8 @@ class DownloadPage {
// Fallback and try to download them from the server directly
$this->tryDownloadFavicon();
}
- Database\Webpage::create($folder_location, $this->page_url, $requester_uid, $this->favicon_path, $this->page_title);
+ Database\Webpage::updateNewArchive($this->folder_name, $this->favicon_path, $this->page_title);
+
} else {
echo "Website does not exist";
}
diff --git a/models/webpage.php b/models/webpage.php
index 6347397..e85046f 100644
--- a/models/webpage.php
+++ b/models/webpage.php
@@ -35,10 +35,15 @@ class Webpage extends Table {
}
// TODO: remove this, refer to archive.php
+ // NOTE: Why remove? Let it be. Leave the thing alone
static function getPagesCount() : int {
return Table::_get_entries_count("Webpages");
}
+ static function updateNewArchive(int $WID, string $faviconPath, string $newTitle) : void {
+ Table::_update("Webpages", "FaviconPath = \"$faviconPath\", Title = \"$newTitle\"", "WID = $WID");
+ }
+
static function fromDBmostVisited(int $count) : array {
return Table::_get_all(
'Webpages',