From 6b8153dab40be9a80758e6b6dc1d71d707bc0d5e Mon Sep 17 00:00:00 2001 From: Touhidur Rahman Date: Fri, 3 Feb 2023 20:30:05 +0600 Subject: [PATCH] pkp/pkp-lib#7486 Clean up of ViewDAO with related migration and files --- classes/core/PKPApplication.php | 1 - .../upgrade/v3_4_0/I6093_AddForeignKeys.php | 4 - .../v3_4_0/I7486_RemoveItemViewsTable.php} | 27 +++--- .../v3_4_0/PreflightCheckMigration.php | 3 - classes/views/ViewsDAO.php | 97 ------------------- xml/schema/views.xml | 38 -------- 6 files changed, 13 insertions(+), 157 deletions(-) rename classes/migration/{install/ViewsMigration.php => upgrade/v3_4_0/I7486_RemoveItemViewsTable.php} (77%) delete mode 100644 classes/views/ViewsDAO.php delete mode 100644 xml/schema/views.xml diff --git a/classes/core/PKPApplication.php b/classes/core/PKPApplication.php index eb3d4257430..2fbdff43cf7 100644 --- a/classes/core/PKPApplication.php +++ b/classes/core/PKPApplication.php @@ -549,7 +549,6 @@ public function getDAOMap() 'TemporaryInstitutionsDAO' => 'PKP\statistics\TemporaryInstitutionsDAO', 'UserStageAssignmentDAO' => 'PKP\user\UserStageAssignmentDAO', 'VersionDAO' => 'PKP\site\VersionDAO', - 'ViewsDAO' => 'PKP\views\ViewsDAO', 'WorkflowStageDAO' => 'PKP\workflow\WorkflowStageDAO', 'XMLDAO' => 'PKP\db\XMLDAO', ]; diff --git a/classes/migration/upgrade/v3_4_0/I6093_AddForeignKeys.php b/classes/migration/upgrade/v3_4_0/I6093_AddForeignKeys.php index 3379ae14ed4..bee1449536c 100755 --- a/classes/migration/upgrade/v3_4_0/I6093_AddForeignKeys.php +++ b/classes/migration/upgrade/v3_4_0/I6093_AddForeignKeys.php @@ -79,10 +79,6 @@ public function up(): void $table->foreign('publication_id')->references('publication_id')->on('publications')->onDelete('cascade'); $table->index(['publication_id'], 'publication_categories_publication_id'); }); - Schema::table('item_views', function (Blueprint $table) { - $table->foreign('user_id')->references('user_id')->on('users')->onDelete('cascade'); - $table->index(['user_id'], 'item_views_user_id'); - }); Schema::table('genres', function (Blueprint $table) { $table->foreign('context_id')->references($this->getContextKeyField())->on($this->getContextTable())->onDelete('cascade'); $table->index(['context_id'], 'genres_context_id'); diff --git a/classes/migration/install/ViewsMigration.php b/classes/migration/upgrade/v3_4_0/I7486_RemoveItemViewsTable.php similarity index 77% rename from classes/migration/install/ViewsMigration.php rename to classes/migration/upgrade/v3_4_0/I7486_RemoveItemViewsTable.php index a93e9565c9f..ef35ab4b488 100644 --- a/classes/migration/install/ViewsMigration.php +++ b/classes/migration/upgrade/v3_4_0/I7486_RemoveItemViewsTable.php @@ -1,29 +1,36 @@ bigInteger('assoc_type'); $table->bigInteger('assoc_id'); @@ -36,12 +43,4 @@ public function up(): void $table->unique(['assoc_type', 'assoc_id', 'user_id'], 'item_views_pkey'); }); } - - /** - * Reverse the migration. - */ - public function down(): void - { - Schema::drop('item_views'); - } } diff --git a/classes/migration/upgrade/v3_4_0/PreflightCheckMigration.php b/classes/migration/upgrade/v3_4_0/PreflightCheckMigration.php index 8220120a86b..50cbba48ca2 100755 --- a/classes/migration/upgrade/v3_4_0/PreflightCheckMigration.php +++ b/classes/migration/upgrade/v3_4_0/PreflightCheckMigration.php @@ -88,9 +88,6 @@ public function up(): void DB::table('publication_categories')->where('publication_id', '=', $publicationId)->delete(); } - // Clean out orphaned views entries - DB::table('item_views AS v')->leftJoin('users AS u', 'v.user_id', '=', 'u.user_id')->whereNull('u.user_id')->whereNotNull('v.user_id')->delete(); - // Clean orphaned genre data $orphanedIds = DB::table('genres AS g')->leftJoin($this->getContextTable() . ' AS c', 'g.context_id', '=', 'c.' . $this->getContextKeyField())->whereNull('c.' . $this->getContextKeyField())->distinct()->pluck('g.genre_id'); foreach ($orphanedIds as $genreId) { diff --git a/classes/views/ViewsDAO.php b/classes/views/ViewsDAO.php deleted file mode 100644 index d2b6fd02978..00000000000 --- a/classes/views/ViewsDAO.php +++ /dev/null @@ -1,97 +0,0 @@ -updateOrInsert( - ['assoc_type' => (int) $assocType, 'assoc_id' => $assocId, 'user_id' => (int) $userId], - ['date_last_viewed' => date('Y-m-d H:i:s')] - ); - } - - /** - * Get the timestamp of the last view. - * - * @param int $assocType - * @param string $assocId - * @param int $userId - * - * @return string|boolean Datetime of last view. False if no view found. - */ - public function getLastViewDate($assocType, $assocId, $userId = null) - { - $params = [(int)$assocType, $assocId]; - if ($userId) { - $params[] = (int)$userId; - } - $result = $this->retrieve( - 'SELECT date_last_viewed - FROM item_views - WHERE assoc_type = ? - AND assoc_id = ?' . - ($userId ? ' AND user_id = ?' : ''), - $params - ); - $row = $result->current(); - return $row ? $row->date_last_viewed : false; - } - - /** - * Move views from one assoc object to another. - * - * @param int $assocType One of the ASSOC_TYPE_* constants. - * @param string $oldAssocId - * @param string $newAssocId - */ - public function moveViews($assocType, $oldAssocId, $newAssocId) - { - return $this->update( - 'UPDATE item_views SET assoc_id = ? WHERE assoc_type = ? AND assoc_id = ?', - [$newAssocId, (int)$assocType, $oldAssocId] - ); - } - - /** - * Delete views of an assoc object. - * - * @param int $assocType One of the ASSOC_TYPE_* constants. - * @param string $assocId - */ - public function deleteViews($assocType, $assocId) - { - return $this->update( - 'DELETE FROM item_views WHERE assoc_type = ? AND assoc_id = ?', - [(int)$assocType, $assocId] - ); - } -} - -if (!PKP_STRICT_MODE) { - class_alias('\PKP\views\ViewsDAO', '\ViewsDAO'); -} diff --git a/xml/schema/views.xml b/xml/schema/views.xml deleted file mode 100644 index 1acf8351b32..00000000000 --- a/xml/schema/views.xml +++ /dev/null @@ -1,38 +0,0 @@ - - - - - - - - - - - - - - - - - Tracking of views for various types of objects such as files, reviews, etc - - assoc_type - assoc_id - user_id - - -
-