Version Update Process

Updating SimpleInvoices can be done quickly, but should be approached with the ability to restore to the previous version if a critical problem is encountered. Whether updating from one of the original SimpleInvoices versions such as master, 2013.1.beta.8, 2011.2, etc., or from a previous version of Fearless359/SimpleInvoices, the following instructions will help assure an error-free experience.

Backup First
There are two backup steps to perform:

  1. Select the Backup Database option on the Settings tab and follow the instructions to backup your database. This will store the backup in the tmp/database_backup directory. You can leave the backup there.
  2. Rename your SimpleInvoices directory to something like, simple_invoices_yyyymmdd_b4_update. The rename moves all content of your current SimpleInvoices directories is preserved for easy recovery if needed.
Update Installation Instructions

Follow these steps to complete your update:

  1. Make sure you do what it says in the Backup First topic.
  2. Recreate the directory that your current SimpleInvoices was installed in that was renamed from in the Backup First step. We will call this the SimpleInvoices directory.
  3. In your browser, download the “master_2019.2” version for PHP 7.2 and greater, or the “master version for PHP 5.6, 7.0 or 7.1 from the Clone or Download button on that page. Note that the master-2019 version should not be used.
  4. Unzip the download file. It will create a directory named the same as the zip file (assuming you didn’t rename it); typically, simpleinvoices-master.
  5. Copy the content of the directory created by the unzip process into the directory created in step 2.
  6. Copy the config/custom.config.php file from your previous SimpleInvoices directory and save it in the config/ directory of the new SimpleInvoice installation directory. Changes to the new version of the config/config.php file will be automatically added to the new copy of the config/custom.config.php file.
  7. If you have your own business invoice template, copy your company logos from the backup template/invoices/logos directory to the updated install template/invoices/logos directory. Next copy the directory your business template is in, from the template/invoices directory to the template/invoices directory.

Proceed to the next topic, First Use Of Update.

First Use Of Update
  1. Access the updated SimpleInvoices site. If authentication is enabled, log in as your normal administrative user.
  2. If there are NO database updates (aka patches) to perform, just start using SimpleInvoices.
  3. If there ARE database updates, you have two quick actions to perform.
    1. You will be on the patch page at this point. This page lists all SimpleInvoices patches; both applied and unapplied. Scroll down the list to see what unapplied patches are pending. They are at the bottom of the list. Scroll back to the top of the list and select the button to apply the patches.
    2. You will now be on the page that lists all the patches, showing that they have all been applied.
  4. Click the button on the applied patches review page and begin using your updated SimpleInvoices.

NOTE: If the patch process reports an error for foreign key update, refer to the Foreign Key Update error section below.

If You Have Special Code
There are three types of special code other than custom invoices templates. They are:

  1. Custom Hooks – These are changes made to the hooks.tpl file in the custom directory. You need to transfer these changes to the same file in the new installation. Verify the are current and work for the newly installed version.
  2. Extensions – Extensions are the proper way to add new functionality to SimpleInvoices. You will need to copy the directory containing your extension to the extensions directory of the new install. You will then need to review your extension code to make sure it is current for any changes to the standard files that need to be incorporated into your extension file. Test your extension to make sure it functions correctly.
  3. Changes to the standard code – Hopefully you kept copious notes and comments on these changes because you have to track them down and implement them in the new version. HOWEVER, when you incorporate it into the updated version do it as an Extension or via the Custom Hooks. Then your life will be more simple the next time you update.

Test your changes and you are ready to us the updated version of SimpleInvoices.

Unable to set Foreign Keys Error Handling

One of the major changes with master-2019.2 is the implementation of foreign key support in the database. This replaces the partial support in the code in prior versions. If you want to know more about foreign key support, please refer to this topic in the How To … menu option.

Foreign key support is implemented in patch #318. If you get the error, “Unable to set Foreign Keys,” the update process will stop after applying all patches up to #318 and will report pertinent error information in the tmp/log/php.log file. Look in this file to see what error(s) have been found. The first part of the error information is an explanation of what has been found. Here is the explanatory text:

Unable to apply patch 318. Found foreign key table columns with values not in
the reference table column. The following list shows what values in foreign
key columns are missing from reference columns.

There two ways to fix this situation. Either change the row columns to reference
an existing record in the REFERENCE TABLE, or delete the rows that contain
the invalid columns.

To do this, the following example of the SQL statements to execute for the test
case where the ‘cron_log’ table contains invalid values ‘2’ and ‘3’ in the
‘cron_id’ column. The SQL statements to consider using are:

UPDATE si_cron_log SET cron_id = 6 WHERE cron_id IN (2,3);
—- or —-
DELETE FROM si_cron_log WHERE cron_id IN (2,3);

The pertinent information to your system then follows in a table that displays all the information you need to correct the error. The following example shows a case where there are orphaned si_invoice_items table record(s) relative to the invoice_id column with a value of “1” that ties back to the id column of the si_invoices table. Here is the example of this:

FOREIGN KEY TABLE  COLUMN      REFERENCE TABLE   COLUMN  INVALID VALUE
invoice_items      invoice_id  invoices          id      1

Using this information, you can decide to perform an UPDATE or a DELETE to resolve the orphaned records after reviewing your database records. In this case, the likely decision is to delete the orphaned records from the si_invoice_items table. Using the DELETE example above, the SQL command you construct would be:

DELETE FROM si_invoice_items WHERE invoice_id = 1

After resolving the foreign key errors, access your SI application again to complete the update process.

Note that the table shown for the FOREIGN KEY TABLE column is “invoice_items” but the delete command references the “si_invoice_items” table. This is because the “si_” prefix is automatically added by the database SQL build logic and the application only knows the “invoice_items” part of the table name.