pierobot / mangapie

This is a self-hosted server for archived manga.
BSD 3-Clause "New" or "Revised" License
65 stars 9 forks source link

History order #200

Closed kurim closed 4 years ago

kurim commented 4 years ago

Hey pierobot,

i think a last read "1 hour ago" should be on top instead of 2 days image

pierobot commented 4 years ago

Yes, it should. The sql server is what sorts the rows. What version of MySQL or MariaDB are you using?

I'll see if I can reproduce with a test.

kurim commented 4 years ago

Hi,

it is 10.4.13-MariaDB

pierobot commented 4 years ago

This should be a workaround for now, https://github.com/pierobot/mangapie/commit/0214f0a2a327b69657b9b4c4934f8e648ef95ad7

kurim commented 4 years ago

fine, but I got another error...

local.ERROR: Trying to get property 'name' of non-object (View: /resources/views/user/history.blade.php) {"userId":3,"exception":"[object] (ErrorException(code: 0): 
Trying to get property 'name' of non-object (View: /resources/views/user/history.blade.php) at /storage/framework/views/01601be8b2b2f797dd91e741c3b2fe4fbb202b34.php:30, ErrorException(code: 0): 
Trying to get property 'name' of non-object at /storage/framework/views/01601be8b2b2f797dd91e741c3b2fe4fbb202b34.php:30) [stacktrace]

I'am not sure where it come from may be I delete one chapter which now cannot be found

edit: find the old entries and delete them, to fix it. But I think if you remove a manga or chapter it should cleanup also in history feed, or marked as not available anymore.

pierobot commented 4 years ago

Good catch. https://github.com/pierobot/mangapie/commit/ae682b070e487bef7731a7c27c9447797cc031b3

kurim commented 4 years ago

Not sure if it cause the remove of the old entries (by hand) or some other reason.

Illuminate\Database\QueryException : SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (mangapie.#sql-675_1ccb4, CONSTRAINT reader_histories_user_id_foreign FOREIGN KEY (user_id) REFERENCES users (id) ON DELETE CASCADE) (SQL: alter table reader_histories add constraint reader_histories_user_id_foreign foreign key (user_id) references users (id) on delete cascade)

/vendor/laravel/framework/src/Illuminate/Database/Connection.php:664
    660|         // If an exception occurs when attempting to run a query, we'll format the error
    661|         // message to include the bindings with SQL, which will make this exception a
    662|         // lot more helpful to the developer instead of just the database's errors.
    663|         catch (Exception $e) {
  > 664|             throw new QueryException(
    665|                 $query, $this->prepareBindings($bindings), $e
    666|             );
    667|         }
    668| 
pierobot commented 4 years ago

I think that might have been caused by a deleted entry before the migration. See if this returns anything in php artisan tinker

ReaderHistory::whereDoesntHave('user')->get();

If it does then do

ReaderHistory::whereDoesntHave('user')->forceDelete();
donotos commented 4 years ago

Same problem here. I dit delete an entry with the command, but still can't init mangapie:

Generating app key...
App key already exists. Skipping.
Publishing vendor files...
Config file for Intervention\Image already exists. Skipping.
Vendor pagination blade already exists. Skipping.
Migrating...

   Illuminate\Database\QueryException  : SQLSTATE[HY000]: General error: 1005 Can't create table `mangapie`.`completed` (errno: 121 "Duplicate key on 
write or update") (SQL: alter table `completed` add constraint `completed_user_id_foreign` foreign key (`user_id`) references `users` (`id`) on delete
 cascade)

  at /var/www/mangapie/vendor/laravel/framework/src/Illuminate/Database/Connection.php:664
    660|         // If an exception occurs when attempting to run a query, we'll format the error
    661|         // message to include the bindings with SQL, which will make this exception a
    662|         // lot more helpful to the developer instead of just the database's errors.
    663|         catch (Exception $e) {
  > 664|             throw new QueryException(
    665|                 $query, $this->prepareBindings($bindings), $e
    666|             );
    667|         }
    668| 

  Exception trace:

  1   Doctrine\DBAL\Driver\PDOException::("SQLSTATE[HY000]: General error: 1005 Can't create table `mangapie`.`completed` (errno: 121 "Duplicate key o
n write or update")")
      /var/www/mangapie/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOStatement.php:129

  2   PDOException::("SQLSTATE[HY000]: General error: 1005 Can't create table `mangapie`.`completed` (errno: 121 "Duplicate key on write or update")")
      /var/www/mangapie/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOStatement.php:127

  Please use the argument -v to see more details.
kurim commented 4 years ago

My Issue can be solved after I add the deleted entry manualy

But it end in the same error like donotos have

   Illuminate\Database\QueryException  : SQLSTATE[HY000]: General error: 1005 Can't create table `mangapie`.`reader_histories` (errno: 121 "Duplicate key on write or update") (SQL: alter table `reader_histories` add constraint `reader_histories_user_id_foreign` foreign key (`user_id`) references `users` (`id`) on delete cascade)

  at /home/kurim/public_html/manga.kurim.de/vendor/laravel/framework/src/Illuminate/Database/Connection.php:664
    660|         // If an exception occurs when attempting to run a query, we'll format the error
    661|         // message to include the bindings with SQL, which will make this exception a
    662|         // lot more helpful to the developer instead of just the database's errors.
    663|         catch (Exception $e) {
  > 664|             throw new QueryException(
    665|                 $query, $this->prepareBindings($bindings), $e
    666|             );
    667|         }
    668| 

But that the table can't created is logic cause it already exist in database...

pierobot commented 4 years ago

Both of you likely had an error after the table was already altered and that's why you can't migrate.

In your mysql client,

@donotos show keys from completed;

@kurim show keys from reader_histories;

You're going to need to drop the foreign keys and indexes.

kurim commented 4 years ago

You mean this:

image

pierobot commented 4 years ago

Yes, that's why it's saying there's a duplicate key. It's trying to create it again. Sorry, It's show keys from reader_histories; not show all keys from reader_histories;

kurim commented 4 years ago

result is nearly the same image

pierobot commented 4 years ago

Okay, then you only need to drop that one. In php artisan tinker

Illuminate\Support\Facades\Schema::table('reader_histories', function ($table) {
    $table->dropForeign(['user_id']);
});

I just pushed a commit, try to php artisan mangapie:init again.

donotos commented 4 years ago

no duplicate on my side

MariaDB [mangapie]> show keys from completed;
+-----------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+--------
-------+
| Table     | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_c
omment |
+-----------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+--------
-------+
| completed |          0 | PRIMARY  |            1 | id          | A         |          16 |     NULL | NULL   |      | BTREE      |         |        
       |
+-----------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+--------
-------+
1 row in set (0.000 sec)
pierobot commented 4 years ago

@donotos What is the last row you get from select * from migrations ?

donotos commented 4 years ago

i reupdated from my last snapshot. seems that your last commit worked. everything is alright now thanks!

kurim commented 4 years ago

your commit works fine, thx