Tangerine-Community / Tangerine

Digitize your offline data collection. Create your Forms online with Tangerine Editor, conduct them offline with the Tangerine Android App. All results you collect can be exported as a CSV file, easy for processing in a spreadsheet. Tangerine has been used in over 1 million assessments and surveys in over 60 countries and in 100 languages.
http://www.tangerinecentral.org/
GNU General Public License v3.0
49 stars 29 forks source link

Upgrading Client app from v3.6.4 to v3.11.0 results in broken app #2224

Closed rjcorwin closed 4 years ago

rjcorwin commented 4 years ago

@lachko Has reported that after a Client installation on v3.6.4 upgrades to v3.11.0, that the app gets stuck on a blank screen with tangerine logo.

chrisekelley commented 4 years ago

I see the issue - Lachko explained that he did only the 3.11.0 update. Our DB.factory code tests if the update-v3.8.0 was run,and if it wasn't, it runs the sqlite db instead of indexedb.

if (window['isCordovaApp'] && window['sqlitePlugin'] && !localStorage.getItem('ran-update-v3.8.0')) {
chrisekelley commented 4 years ago

One thing to note: window['sqlitePlugin'] is provided by SQLitePlugin.js, which is avail in 3.11.0 even if the sqlite plugin is not running.

chrisekelley commented 4 years ago

We could test for window.sqliteStorageFile instead - that will not be available in pre-3.11 versions of Tangerine.

chrisekelley commented 4 years ago

Still, the bigger issue is updates: they are not getting processed. The value "ran-update-v3.8.0" should be already in localStorage.

chrisekelley commented 4 years ago

aha! It is not in localstorage because the update failed because it could not properly connect to the db.

This is fixed in 259005245659f5715b98bf0971468914a82dcaa2 and released in https://github.com/Tangerine-Community/Tangerine/releases/tag/v3.11.1-rc-2

chrisekelley commented 4 years ago

Here is the error in v3.11.0 - before the fix:

vendor.js:155894 WebSQL threw an error TypeError: Cannot read property 'resolveAbsolutePath' of undefined
    at SQLitePlugin.open (SQLitePlugin.js:217)
    at new SQLitePlugin (SQLitePlugin.js:86)
    at Object.<anonymous> (SQLitePlugin.js:680)
    at Object.openDatabase (SQLitePlugin.js:60)
    at Object.websql (vendor.js:145472)
    at openDatabaseWithOpts (vendor.js:146606)
    at openDBSafely (vendor.js:146612)
    at openDB (vendor.js:146624)
    at PouchDB.WebSqlPouch (vendor.js:146711)
    at PouchDB.CordovaSQLitePouch (vendor.js:145496)

Error happens in this line of code:

  if ('default' in WebSqlPouchCore && typeof WebSqlPouchCore.default.call === 'function') {
    WebSqlPouchCore.default.call(this, _opts, callback)
  } else {
    WebSqlPouchCore.call(this, _opts, callback)
  }

Also, this error is thrown, but is not the cause of the blank screen:

vendor.js:41577 ERROR Error: Uncaught (in promise): TypeError: Cannot read property 'permissions' of undefined
TypeError: Cannot read property 'permissions' of undefined
    at AppComponent.<anonymous> (main.js:22121)
    at Generator.next (<anonymous>)
    at main.js:21778
    at new ZoneAwarePromise (polyfills.js:83775)
    at push../src/app/app.component.ts.__awaiter (main.js:21774)

It's from initing the permission plugin in app.component:

 const permissions = window['cordova']['plugins']['permissions'];
chrisekelley commented 4 years ago

Confirmed that the v3.11.1-rc-2 fix works - upgraded the server with

# There was a bug in 3.11.0 that causes a blank screen in earlier APK's
git checkout v3.11.1-rc-2
./start.sh v3.11.1-rc-2

Released an APK, did an OTA update, and was able to login with the local user.

Looks like we did not make a v3.11.1 - we may have skipped directly to 3.12.0

chrisekelley commented 4 years ago

I'm currently able to upgrade a 3.6.4 group all the way to 3.13.0. One caveat - the first loading of the app leads to a blank screen. Subsequent loads work.

chrisekelley commented 4 years ago

Looked at the code that was changed in v3.11.1-rc-2:

https://github.com/Tangerine-Community/Tangerine/commit/62d3071cf9c25cfac4cc3cd4be36ec33e673021a

db.factory:

if (window['isCordovaApp'] && window['sqliteStorageFile'] && !localStorage.getItem('ran-update-v3.8.0')) {

We are currently (release/3.13.0) using that sqliteStorageFile but no longer check for ran-update-v3.8.0.

  if (window['isCordovaApp'] && window['sqliteStorageFile']) {

It should be fine to run this update without the v3.11.1-rc-2: image.

lachko commented 4 years ago

I don't understand why but if I first update the site to the new image that you created: v3.11.1-rc-2 (inserting this update between 3.11.0 and 3.12.5) the update works for the tablet. I didn't try a pwa update again