flochman / Laduna

Laduna is fork of OSSN - Open Source Social Network with PostgreSQL support
Other
0 stars 4 forks source link

Debuggin Ossn in general #1

Open githubertus opened 7 years ago

githubertus commented 7 years ago

Hi, and thanks for providing your fork. I see you already added echo $this->query; on line 110 in OssnDatabase.

I think, more helpful would be logging the queries into the Ossn error_log file instead. Thus,

  1. Enable "Error Reporting" from your Ossn Admin panel
  2. change your line 110 to error_log($this->query);

Of course, the numerous lines you'll get this way is a pain in the ass, so I'd try to reduce the output with something like


if (preg_match('/ossn_users/', $this->query)) {
error_log($this->query);
}

because the last activity column is of interest for displaying who is online.

Then log off, wait a minute and log in to your admin panel again. This should lead to the queries of interest.

Please note, that I'm currently very busy with other jobs, so don't expect instant answers every time.
Good luck!
flochman commented 7 years ago

Hi,

@githubertus thank you for answer.

I try to configure error_log($this->query); but cannot find where is stored log file.

Where is ossn log file stored and what is its name?

Thanks.

flochman commented 7 years ago

Hi, @githubertus

the problem is that I modified OSSN PHP files and SQL qeries that now NO error is happend, so there is no error reporting to error_log();

I would like to inspect SQL queries and their result even that no error is happend.

Do you know the best parctice how to do this?

Thanks you very much in advance.

I understand that you are very busy with other jobs so I really appreciate your time and effort.

Thanks.

githubertus commented 7 years ago

Where is ossn log file stored and what is its name?

The file is named error_log and is located in your Ossn installation root. See https://www.opensource-socialnetwork.org/wiki/view/1954/how-to-enable-ossn-error-reporting for more details

If you replace your lime 110 as I said, the SQLs queries should be written to that file.

flochman commented 7 years ago

@githubertus

I replaced line 110 as you said.

I switched Error logging to on in Admin Panel and no error_log is in root directory of OSSN.

I also created DISPLAY_ERRORS file in root of OSSN and also error_log is not in root of OSSN.

I switched dispay_error to on in installation/index.php when I experimented with installation and is still switched on in PHP file, but I do not think that this is reason why is error_log file not in root directory of OSSN.

flochman commented 7 years ago

OK. Now is error_log in root directory. Thank you.

I had problems with directory rights.

I needed again setup :

chgrp www-data /path/to/ossn_parent_directory chmod g+w /path/to/ossn_parent_directory

Now is evrything OK.

Thanks.

githubertus commented 7 years ago

Ok, I was just about pointing you to http://php.net/manual/en/function.error-log.php

See Example 3 which way to define your own log file.

Meanwhile I'm trying to get a virtual instance of turnkey linux with postgres up and running... Actually, my last postgres experience was decades ago :)

flochman commented 7 years ago

Yes, thanks.

Good to know this options in php.net example for error_log.

:-)

flochman commented 7 years ago

Btw.

I now discovered one issue with original OSSN PHP file.

In OssnDatabse.php in line 118 you have not ended UPDATE SQL statement with ";".

Maybe is it not big error because OSSN works, just for you are informed. :-)

flochman commented 7 years ago

Hi,

OK, now I researched what possibilities give me error_log(); function.

I also compared MySQL and PostgreSQL error_log() outputs during logging session /no errors but full and all SQL queries) and I do not finded any diffrence between calling SQL queries in MySQL and PostgreSQL version of OSSN exeption in changes what I did.

What supprise! :-)

So, I need to find another way how to check why is my fork doesnot works.

I will investigate fetch results.

flochman commented 7 years ago

@githubertus

OK, I investigated SQL streams between MySQL and PostgreSQL in OSSN and discovered diffrence.

The problem is after my modified SQL query.

In MySQL you have :

SELECT u.guid, u.* FROM ossn_users as u WHERE(u.time_created IS NOT NULL) ORDER by u.guid ASC LIMIT 0, 10;

In PostgreSQL I have:

SELECT u.guid, u.* FROM ossn_users as u WHERE(u.time_created IS NOT NULL) GROUP by u.guid, u.type, u.username, u.email, u.password, u.salt, u.first_name, u.last_name, u.last_login, u.last_activity, u.activation, u.time_created ORDER by u.guid ASC LIMIT 0 OFFSET 10;

PostgreSQL after your MySQL query got error and wanted GROUP BY clausule or agregate function. I did not know how to simply solve the situation that I added GROUP BY clausule.

After that query the SQL stream between MySQL and Postgres is diffrent.

I know that it is more than I can expect from support from you but if you have suggestion how to modify my PostgreSQL query I will be very appreciate.

Thank you vey much in advance.

flochman commented 7 years ago

@githubertus

I will show you how are these SQL streams differ:

For MySQL:

error_log.txt

For PostgreSQL:

error_log.txt

githubertus commented 7 years ago

Before I go to bed ... As I said already: my postgres knowledge is = zero.

Meanwhile, my virtual Laduna Site is up and running now. And i tried to get a list of users on my admin panel at http://laduna/administrator/users But the list is empty.

The corresponding query produced by your code is: SELECT u.guid, u.* FROM ossn_users as u WHERE(u.time_created IS NOT NULL) GROUP by u.guid, u.type, u.username, u.email, u.password, u.salt, u.first_name, u.last_name, u.last_login, u.last_activity, u.activation, u.time_created ORDER by u.guid ASC LIMIT 0 OFFSET 10;

In fact, this will give an empty result in mysql, too. Because there's a mixup of the LIMIT and OFFSET values: Correctly it should read: LIMIT 10 OFFSET 0 !!

I haven't had the time to check your code changes, but it looks like the array of parameters/values has gone out of tune somwhere.

flochman commented 7 years ago

Thanks for answer and thanks that you installed Laduna fork on your virtual server and tested. I really apreciate.

OK. I will consult PostgreSQL statemens on stackoverflow forum.

Yes. LIMIT was bad. Now I had it corrected and User List is fully working. I tried add users and they are normaly shown on User List.

I will do commit to Laduna github and provide new OssnDatabse.php with corrected LIMIT in few minutes.

Now I would like to focus why is not shown active online users.

Can you navigate me where to focus to investigate this area please?

What SQL statement check the online users? I mean aproximately.

Thanks.

flochman commented 7 years ago

You wrote: I haven't had the time to check your code changes, but it looks like the array of parameters/values has gone out of tune somwhere.

Yes, I somewhere in OssnEntities.php OssnUser.php and OssnObject.php /only in these 3 files/ I added new group_by parameter to SQL statements.

If you will search for /added PostgreSQL fork / comment you will easy find these changes.

I did it because PostgreSQL allways got error about somethink like

ERROR: column "e.guid" must appear in the GROUP BY clause or be used in an aggregate function

so I added group_by parameters in some SQL statements creation.

flochman commented 7 years ago

I know that I write too much and when you getup this morning you will find lot of stuff but I can not sleep thus I am programming at 3 o'clock morning :-)

Here is screen image and the error if I want to login as diffrent user which I created in Admin Panel. I do not know how to handle because there is nothing.

170519032651_1

flochman commented 7 years ago

OK. Success! I done it!

I modiefied OssnWall.php and OssnAnnotation.php and now seems that evrything works fine!

Also Online users now are visible.

Only thing what does not work is Graphs in Dasboard panel in Admin Panel and likes.

Please, clone master of Laduna fork and test it ! It seems that evrything works now even graphs and likes.

Thank you.

githubertus commented 7 years ago

No, not here. Cloned the latest fork and still no users in admin panel (no overview, no online)

flochman commented 7 years ago

Just now, I cloned master and installed and find the newest version on master. So you have newest version.

I know that the fork is not finished completly jet, but now You can see User List, search and login with other users etc.

It is possible create other new users and when from other browser you login and make friends, you will see online users-friends green on right panel.

Yes, the dashboard users overview and online users is not functioning also is not functioning likes.

So I see only this dashboard and likes not working.

Can you reviewed this clone code why is not dashboard users overview and online doesnot works, please?

For online male users there is SQL query:

SELECT count(*) as total FROM ossn_users as u JOIN ossn_entities as e ON e.owner_guid=u.guid JOIN ossn_entities_metadata as emd ON emd.guid=e.guid WHERE(e.type='user' AND e.subtype='gender' AND emd.value='male' AND last_activity > 1495178076 - 100) ;

but is giving output 0 instead of for example 3 users /when are created/.

I did what I could, now is needed your skills, please.

Thank you.

githubertus commented 7 years ago

When creating a new user from admin panel, there's only one record inserted into ossn_users. The entity record (which stores gender, etc) is missing. Most likely because getLastEntry() fails.

githubertus commented 7 years ago

No, not quite right ... the datatype seems wrong ...

githubertus commented 7 years ago

Yes, your $this->last_id = $insert_row[0]; is giving back a string, which of course can't be used for GUID. That's why creation of entity fails. You have to cast it to an integer like $this->last_id = (int)$insert_row[0];

githubertus commented 7 years ago

As a side note: I saw you already replaced backticks with doublequotes in OssnDatabase.

Be aware that there are a lot of other places where backticks are still used (just got a crash trying to install a component)

I'll talk to Arsalan whether we could get rid of these ticks in general in the future, as they are not really necessary and only useful with very strange table/column names.

Just found these ticks are causing your Like problem:

PHP WARNING: 2017-05-19 15:01:52 (CEST): "pg_query(): Query failed: ERROR: syntax error at or near "" LINE 1: INSERT INTO ossn_likes (subject_id,guid,type`) ^" in file /var/www/laduna/classes/OssnDatabase.php (line 106)

Postgres accepts it completely without ticks. Just changes line 43 of the OssnLikes class to: $this->statement("INSERT INTO ossn_likes (subject_id, guid, type) VALUES('{$subject_id}', '{$guid}', '{$type}');");

I have just confirmed (making the same change on my newblue testsite) that MySQL doesn't need these backticks neither.

flochman commented 7 years ago

Yes. Many, many thanks for you expertise.

Yes. Like now is running. Unlike is not running yet, I looked to SQL statment in OssnLikes.php but in UnLike() I do not find any special.

$this->last_id = (int)$insert_row[0];

I corrected. Thanks.

Now only unlike and dashboard overview is wrong.

githubertus commented 7 years ago

Hmmm ... no idea ... both like and unlike are working for me now.

As for the dashboard overview: I think you have still some users without entity record. Delete them and add them again and they should appear. You may give one of them admin permissions in order to delete your original admin account, too. Or add the entity record manually from PhpPGAdmin

flochman commented 7 years ago

It is strange. For me unlike does not works.

Did you only changed the the ticks in this statment in OssnLikes.php? $this->statement("INSERT INTO ossn_likes (subject_id, guid, type) VALUES('{$subject_id}', '{$guid}', '{$type}');");

I think you must changed also somethink diffrent.

Like working. But for unlike I need to refresh page. It is not like in MySQL withouth refreshing of page.

Now after $this->last_id = (int)$insert_row[0];

is working dashboard overwiev. For online connections it is OK.

For user count it is not OK.

What you mean users withouth entity record?

When I looked tp PhpPgAdmin to database in ossn_entities thera are records:

1 1 user birthdate 1495212548 0 2 1 2 1 user gender 1495212548 0 2 1 3 2 user birthdate 1495212641 0 2 1 4 2 user gender 1495212641 0 2 1 5 3 user birthdate 1495212687 0 2 1 6 3 user gender 1495212687 0 2 1 7 1 object poster_guid 1495212733 0 2 1 8 1 object access 1495212733 0 2 1

githubertus commented 7 years ago

So users 1, 2, 3 have entities. And your count should be 3. What does it show instead?

flochman commented 7 years ago

Yes, I have 3 users and in dashboard count it shows 1.

githubertus commented 7 years ago

Could you list the ossn_users table like that or take a screenshot? And the entities_metadata table. I'm a little concerned because of the low user ids. Did you start the database from scratch?

flochman commented 7 years ago

Yes, I started again from scratch.

ossn_users table is:

2 normal miroslav dodo@ax.sk 99c12e740b9512271a12f29790b9fc55 26192c76 Miroslav Public 0 0 1495212641 3 normal vladimir qq@ax.sk 7efec4ddf311b934eaa6967cd7a35e07 28f5b4f2 Vladimir Godunov 1495212726 1495213944 1495212687 1 admin admin xxx@ax.sk 29b5c706f1ae2b09345ae5f4841d3a9a 2040883d Ondrej Janicko 1495212561 1495213853 1495212548

Befour last colum there is emty colum activation in database.

githubertus commented 7 years ago

Ah ok. As the guid from users table (column 1) corresponds to owner_guid (column 2) in entities. So that's correct in your case.

Then what about the metadata records?

flochman commented 7 years ago

the metadata are:

1 1 01/01/2004 2 2 male 3 3 01/05/2017 4 4 male 5 5 01/05/2017 6 6 male 7 7 3 8 8 2

githubertus commented 7 years ago

Everything looks fine. No idea whats different. :( What I did was:

  1. Getting a snapshot from you this morning at 11:17
  2. Copying OssnDatabase and OssnAnnotations onto my installation from yesterday
  3. Added some error_logs() into OssnDatabase and OssnUser class in order to resolve the $this->last_id problem
  4. added the int cast
  5. Deleted 2 of my 3 users and added them again to get the corresponding entities/entities_metadata records After that the admin panel starts working. (Count is still missing one member, but that's ok because I didn't recreate my first user)
  6. Finally I removed the backticks in the Likes component class. That's all I did.
flochman commented 7 years ago

That is strange.

I did new commits to master just now. Added new OssnDatabase.php and OssnLikes.php. Now is the master the latest version that I have.

Can you clone master and start installing again from stratch, please?

I would like to know if unlike will work for you.

What sholud be probably bad with users count in dashboard overview? Any idea?

Thanks.

flochman commented 7 years ago

You do not copy OssnWall.php to your yesterday install which I modified also.

flochman commented 7 years ago

OK. The dashboard users overview is solved. I edited OssnEntities.php and on function searchEntities I did some tricks to fit SQL statment in OssnUser.php

The problem was my modified SQL statement in function countBygender where I needed add Group BY clause. There was conflict with ORDER BY which MySQL corrected but PostgreSQL doesnot. Now I used tric to elimine GROUP BY and ORDER BY clauses.

OK. This problem is done. Dashboard with overview is fully functioning.

I did commits to master.

Remain problem with unlike. Any idea?

Thanks for help.

flochman commented 7 years ago

I found why unlike does not work.

There is syntax error in SQL statement, yes ticks:

DELETE FROM ossn_notifications WHERE(subject_guid = '1' AND type IN ('like:entity:file:profile:photo','like:entity:file:profile:cover','like:entity:file:ossn:aphoto'));

I can not find where this statement is created.

Any idea?

Thanks.

flochman commented 7 years ago

It strange, ticks are gone here in github editor.

They are on ossn_notifications after DELETE FROM

flochman commented 7 years ago

OK. I done it.

There were ticks on delete function in OssnDatabase.php

Now seems evrything is done.

flochman commented 7 years ago

How are upgrades works?

I discover that there are many ticks in upgrade files. Are thise upgrade files incorporated in system after install ? Or when they are used?

Thanks.

flochman commented 7 years ago

Now I discovered that cache does not work.