Closed brianw777 closed 4 months ago
Wow, that is a beautiful issue! <3 I will review and evaluate this as soon as I find a minute! Thank you for your contribution.
I can reproduce this and this issue only appears with MySQL. A fix comes with the current milestone.
Describe the bug When I select the 3 bar menu up in the top right then select History from the list I get a 500 Internal Server error.
I also get the same error when going to a plant and clicking on history to move the plant to history. The plant does get moved to the history and is no longer in the list of plants but the error is displayed and I use the browser back button to go back. I have confirmed that the history and history_date fields in the plants table show data. I have also confirmed that this error is produced from all servers (i.e. nginx, apache2 and internal php asatru serve)
To Reproduce Steps to reproduce the behavior:
Expected behavior I am not exactly sure what is supposed to happen I have just been playing around with Hortusfox and haven't seen the history before. From the documentation it looks like a history of all the plants moved to history should show up.
Screenshots If applicable, add screenshots to help explain your problem.
Software:
Additional context I wanted to run the query manually so found the query string in the file app/models/PlantsModel.php in the function getHistoryYears()
return static::raw('SELECT DISTINCT YEAR(history_date) AS history_year FROM
' . self::tableName() . 'WHERE history = 1 AND history_date IS NOT NULL ORDER BY history_date DESC');
From within mysql I ran the query substituting plants for the tablename and got the error:
By removing the DISTINCT I can get the list of years:
After doing some research I found that the ORDER BY must also be in the SELECT so, after testing other things and failing, I tested it by replacing the ORDER BY history_date with ORDER BY YEAR(history_date) and the error went away and the distinct years was shown.
By changing the line of code in the file app/models/PlantsModel.php in the function getHistoryYears() I was able to run it without the error:
return static::raw('SELECT DISTINCT YEAR(history_date) AS history_year FROM
' . self::tableName() . 'WHERE history = 1 AND history_date IS NOT NULL ORDER BY YEAR(history_date) DESC');