anvc / scalar

Born-digital, open source, media-rich scholarly publishing that’s as easy as blogging.
Other
231 stars 73 forks source link

Changin url on new book throws error #213

Closed alexdryden closed 1 year ago

alexdryden commented 1 year ago

Changing the url segment of a book that was just created and has no content results in a fatal PHP error in PHP 8.0:

Fatal error: Uncaught TypeError: implode(): Argument #1 ($pieces) must be of type array, string given in /var/www/scalar/system/application/models/book_model.php:759 
Stack trace: #0 /var/www/scalar/system/application/models/book_model.php(759): implode() 
#1 /var/www/scalar/system/application/controllers/system.php(531): Book_model->save() 
#2 /var/www/scalar/system/application/controllers/system.php(62): System->dashboard() 
#3 /var/www/scalar/system/core/CodeIgniter.php(326): System->_remap() 
#4 /var/www/scalar/codeigniter.php(203): require_once('/var/www/scalar...') 
#5 {main} thrown in /var/www/scalar/system/application/models/book_model.php on line 759

This is because when a book is new there are no book versions or pages, and as a consequence the variables $book_page_ids and $book_version_ids are never set (see: here and here) . So, as a result implode is given an undefined variable, which threw a warning before php 8 but now throws a fatal error.

I just tested this on the latest release (2.6.6) and the master branch.