OJS Upgrade from 3.0.2 to 3.3.0-7 fails because a database table already exists

Description of issue or problem I’m having:
I’m updating OJS from 3.0.2 on a php 5.5.9 server to a new copy at OJS 3.3.0-7 on a php 7.4.3 server. When I run the update script php tools/upgrade.php upgrade on a new instance of the site I get the following error.

[pre-install]
[load: upgrade.xml]
[version: 3.3.0.7]
[code: Installer Installer::checkPhpVersion]
[data: dbscripts/xml/upgrade/3.1.0_preupdate_review_assignments.xml]
[data: dbscripts/xml/upgrade/3.1.0_preupdate_notes.xml (skipped)]
[data: dbscripts/xml/upgrade/3.1.0_preupdate_payments.xml]
[data: dbscripts/xml/upgrade/3.1.1_preupdate_citations.xml]
[data: dbscripts/xml/upgrade/3.1.2_preupdate_user_author_names.xml]
[code: Installer Installer::migrateSubmissionCoverImages]
[data: dbscripts/xml/upgrade/3.2.0_preupdate_email_templates.xml]
[data: dbscripts/xml/upgrade/3.2.0_preupdate_versioning_articleGalleySettings.xml]
ERROR: Upgrade failed: DB: SQLSTATE[42S01]: Base table or view already exists: 1050 Table 'submission_galley_settings' already exists (SQL: CREATE TABLE submission_galley_settings AS SELECT * FROM article_galley_settings WHERE setting_name <> 'excludeDoi' AND setting_name <> 'excludeURN')

I verified that in the original database the table submission_galley_settings already exists.

Steps I took leading up to the issue:
Verified the version of the site that I was upgrading from by checking the page source. <meta name="generator" content="Open Journal Systems 3.0.2.0">, located at epubs.utah.edu.
Downloaded ojs-3.3.0-7.tar.gz, untarred it.
Copied over config.inc.php and public folder from the existing site.
Updated config.inc.php with all the changes from the update files in the docs.
Dumped the database and pulled it into a new database.
Set up the files directory.
Ran the update script php tools/upgrade.php upgrade.

What I tried to resolve the issue:
I checked the php version of the new server. It is 7.4.3. I checked the existing tables in the 3.0.2.0 database, they are as follows.

+---------------------------------------+
| access_keys                           |
| announcement_settings                 |
| announcement_type_settings            |
| announcement_types                    |
| announcements                         |
| article_galley_settings               |
| auth_sources                          |
| author_settings                       |
| authors                               |
| books_for_review                      |
| books_for_review_authors              |
| books_for_review_settings             |
| captchas                              |
| citation_settings                     |
| citations                             |
| comments                              |
| completed_payments                    |
| controlled_vocab_entries              |
| controlled_vocab_entry_settings       |
| controlled_vocabs                     |
| custom_issue_orders                   |
| custom_section_orders                 |
| data_object_tombstone_oai_set_objects |
| data_object_tombstone_settings        |
| data_object_tombstones                |
| dataverse_files                       |
| dataverse_studies                     |
| edit_assignments                      |
| edit_decisions                        |
| email_log                             |
| email_log_users                       |
| email_templates                       |
| email_templates_data                  |
| email_templates_default               |
| email_templates_default_data          |
| event_log                             |
| event_log_settings                    |
| external_feed_settings                |
| external_feeds                        |
| filter_groups                         |
| filter_settings                       |
| filters                               |
| genre_settings                        |
| genres                                |
| gifts                                 |
| group_memberships                     |
| group_settings                        |
| groups                                |
| institutional_subscription_ip         |
| institutional_subscriptions           |
| issue_files                           |
| issue_galley_settings                 |
| issue_galleys                         |
| issue_settings                        |
| issues                                |
| item_views                            |
| journal_settings                      |
| journals                              |
| library_file_settings                 |
| library_files                         |
| metadata_description_settings         |
| metadata_descriptions                 |
| metrics                               |
| mutex                                 |
| notes                                 |
| notification_mail_list                |
| notification_settings                 |
| notification_subscription_settings    |
| notifications                         |
| oai_resumption_tokens                 |
| object_for_review_assignments         |
| object_for_review_persons             |
| object_for_review_settings            |
| objects_for_review                    |
| paypal_transactions                   |
| pln_deposit_objects                   |
| pln_deposits                          |
| plugin_settings                       |
| processes                             |
| published_submissions                 |
| queries                               |
| query_participants                    |
| queued_payments                       |
| referral_settings                     |
| referrals                             |
| review_assignments                    |
| review_files                          |
| review_form_element_settings          |
| review_form_elements                  |
| review_form_responses                 |
| review_form_settings                  |
| review_forms                          |
| review_object_metadata                |
| review_object_metadata_settings       |
| review_object_type_settings           |
| review_object_types                   |
| review_round_files                    |
| review_rounds                         |
| roles                                 |
| rt_contexts                           |
| rt_searches                           |
| rt_versions                           |
| scheduled_tasks                       |
| section_editors                       |
| section_settings                      |
| sections                              |
| sessions                              |
| site                                  |
| site_settings                         |
| stage_assignments                     |
| static_page_settings                  |
| static_pages                          |
| submission_artwork_files              |
| submission_comments                   |
| submission_file_settings              |
| submission_files                      |
| submission_galley_settings            |
| submission_galleys                    |
| submission_html_galley_images         |
| submission_search_keyword_list        |
| submission_search_object_keywords     |
| submission_search_objects             |
| submission_settings                   |
| submission_supplementary_files        |
| submission_tombstones                 |
| submission_xml_galleys                |
| submissions                           |
| subscription_type_settings            |
| subscription_types                    |
| subscriptions                         |
| temporary_files                       |
| theses                                |
| usage_stats_temporary_records         |
| user_group_settings                   |
| user_group_stage                      |
| user_groups                           |
| user_interests                        |
| user_settings                         |
| user_user_groups                      |
| users                                 |
| versions                              |
+---------------------------------------+
141 rows in set (0.001 sec)

Hoping that there was just a coding oversight that set the update to CREATE DATABASE instead of CREATE DATABASE IF NOT EXISTS I modified the \lib\pkp\classes\install\Installer.inc.php executeAction function in the case of the action type being “data”. Modified it to change sql calls for CREATE TABLE to instead be CREATE TABLE IF NOT EXISTS and output that a change was made.

Reran the upgrade script.

[pre-install]
[load: upgrade.xml]
[version: 3.3.0.7]
[code: Installer Installer::checkPhpVersion]
[data: dbscripts/xml/upgrade/3.1.0_preupdate_review_assignments.xml]
Changed query: '
                        CREATE TABLE review_assignments_tmp AS (SELECT review_id FROM review_assignments WHERE cancelled = 1)
                ' to '
                        CREATE TABLE IF NOT EXISTS review_assignments_tmp AS (SELECT review_id FROM review_assignments WHERE cancelled = 1)
                '
[data: dbscripts/xml/upgrade/3.1.0_preupdate_notes.xml (skipped)]
[data: dbscripts/xml/upgrade/3.1.0_preupdate_payments.xml]
[data: dbscripts/xml/upgrade/3.1.1_preupdate_citations.xml]
[data: dbscripts/xml/upgrade/3.1.2_preupdate_user_author_names.xml]
Changed query: '
                        CREATE TABLE users_tmp AS (SELECT user_id, first_name, last_name, middle_name, salutation, suffix FROM users)
                ' to '
                        CREATE TABLE IF NOT EXISTS users_tmp AS (SELECT user_id, first_name, last_name, middle_name, salutation, suffix FROM users)
                '
Changed query: '
                        CREATE TABLE authors_tmp AS (SELECT author_id, submission_id, first_name, last_name, middle_name, suffix FROM authors)
                ' to '
                        CREATE TABLE IF NOT EXISTS authors_tmp AS (SELECT author_id, submission_id, first_name, last_name, middle_name, suffix FROM authors)
                '
[code: Installer Installer::migrateSubmissionCoverImages]
[data: dbscripts/xml/upgrade/3.2.0_preupdate_email_templates.xml]
[data: dbscripts/xml/upgrade/3.2.0_preupdate_versioning_articleGalleySettings.xml]
Changed query: 'CREATE TABLE submission_galley_settings AS SELECT * FROM article_galley_settings WHERE setting_name <> 'excludeDoi' AND setting_name <> 'excludeURN'' to 'CREATE TABLE IF NOT EXISTS submission_galley_settings AS SELECT * FROM article_galley_settings WHERE setting_name <> 'excludeDoi' AND setting_name <> 'excludeURN''
[data: dbscripts/xml/upgrade/3.2.0_preupdate_versioning.xml]
Changed query: 'CREATE TABLE temp_authors AS SELECT * FROM authors' to 'CREATE TABLE IF NOT EXISTS temp_authors AS SELECT * FROM authors'
Changed query: 'CREATE TABLE temp_submissions AS SELECT * FROM submissions' to 'CREATE TABLE IF NOT EXISTS temp_submissions AS SELECT * FROM submissions'
Changed query: 'CREATE TABLE temp_submission_galleys AS SELECT * FROM submission_galleys' to 'CREATE TABLE IF NOT EXISTS temp_submission_galleys AS SELECT * FROM submission_galleys'
Changed query: 'CREATE TABLE temp_published_submissions AS SELECT * FROM published_submissions' to 'CREATE TABLE IF NOT EXISTS temp_published_submissions AS SELECT * FROM published_submissions'
Changed query: 'CREATE TABLE temp_citations AS SELECT * FROM citations' to 'CREATE TABLE IF NOT EXISTS temp_citations AS SELECT * FROM citations'
[data: dbscripts/xml/upgrade/3.2.0_preupdate_last_activity.xml]
Changed query: 'CREATE TABLE temp_last_activity_submissions AS SELECT * FROM submissions' to 'CREATE TABLE IF NOT EXISTS temp_last_activity_submissions AS SELECT * FROM submissions'
[schema: lib/pkp/xml/schema/common.xml]
PHP Fatal error:  Uncaught Error: Call to undefined function mysql_connect() in /home/sites/epubs.staging.lib.utah.edu/lib/pkp/lib/vendor/adodb/adodb-php/drivers/adodb-mysql.inc.php:461
Stack trace:
#0 /home/sites/epubs.staging.lib.utah.edu/lib/pkp/lib/vendor/adodb/adodb-php/adodb.inc.php(683): ADODB_mysql->_connect()
#1 /home/sites/epubs.staging.lib.utah.edu/lib/pkp/classes/install/Installer.inc.php(362): ADOConnection->Connect()
#2 /home/sites/epubs.staging.lib.utah.edu/lib/pkp/classes/install/Installer.inc.php(251): Installer->executeAction()
#3 /home/sites/epubs.staging.lib.utah.edu/lib/pkp/classes/install/Installer.inc.php(174): Installer->executeInstaller()
#4 /home/sites/epubs.staging.lib.utah.edu/lib/pkp/classes/cliTool/UpgradeTool.inc.php(89): Installer->execute()
#5 /home/sites/epubs.staging.lib.utah.edu/lib/pkp/classes/cliTool/UpgradeTool.inc.php(65): UpgradeTool->upgrade()
#6 /home/sites/epubs.staging.lib.utah.edu/tools/upgrade.php(22): UpgradeTool->execute()
#7 {main}
  thrown in /home/sites/epubs.staging.lib.utah.edu/lib/pkp/lib/vendor/adodb/adodb-php/drivers/adodb-mysql.inc.php on line 461

mysql_connect is deprecated as of php 7, and according to https://pkp.sfu.ca/ojs/ojs_download/ OJS requires php 7.3 or later, so I’m unsure why it’s calling mysql_connect.

Application Version - e.g., OJS 3.1.2:
Supposedly, OJS 3.0.2.0. This seems a little weird to me because OJS3x says it requires PHP 7.3+, but is running on a server with an old php version, 5.5.9. Copying over the old code makes the site not load on the php 7.4.3 server, giving errors related to deprecated code. Running the latest version of OJS only gives errors in the apache logs about missing a database table since I haven’t been able to successfully run the upgrade function.

Additional information, such as screenshots and error log messages if applicable:

The update steps should be as follows:
According to your explanations you are using OJS 3.0.2.
Step one: OJS 3.0.2 to 3.1.1.2
Second step: OJS 3.1.1.2 to 3.2.1-4
Third step: OJS 3.2.1-4 to 3.3.0-8

Don’t forget to take a backup before you start.

Hi all,

There’s a relevant issue filed in Github: upgrade to 3.3 from 3.0.2 fails because submission_galley_settings table already exists · Issue #7642 · pkp/pkp-lib · GitHub

Regards,
Alec Smecher
Public Knowledge Project Team