Define an SQL file for installation, e.g.:
<install>
<sql>
<file driver="mysql" charset="utf8">install.mysql.utf8.sql</file>
</sql>
</install>
...then add that sql file at the root of a plugin before zipping everything for installation.
The SQL should be executed (a table created in this case) along with the plugin installation.
The plugin is installed without the SQL file being parsed at all.
$this->parseQueries()
in the install() method of /libraries/src/Installer/InstallerAdapter.php returns NULL.
Joomla 3.8.11, PHP 7.1 (latest), Apache 2.4, MySQL 5.7 (via MAMP v5 on macOS).
Triple checked paths, naming conventions, XML attributes, you name it. Nada.
Labels |
Added:
?
|
Category | ⇒ | SQL |
Status | New | ⇒ | Information Required |
Update.
On Fri, Aug 10, 2018, 11:38 PM Georgios Papadakis notifications@github.com
wrote:
Ok so this is an installation of a new plugin
Maybe for some reason, the installer thinks it is an update, thus
... will not be used by parseQueries()if you add
\JFactory::getApplication()->enqueueMessage($this->route, 'notice');
before:
$this->parseQueries()
do you get an 'install' or an 'update' message ?
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
#21543 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/ABPdG1OW_h9kifg_5vDKic1fjglp4r1Uks5uPe8pgaJpZM4V4hGr
.
Status | Information Required | ⇒ | Discussion |
Update
I do not know why the installer treats it as an update,
thinking that the plugin is already installed thus not executing <install><sql>...
Maybe something went wrong during uninstall of the plugin ? and there is a record in extensions table ?
Anyway since you would want to add an upgrade file too
you can do
<!-- e.g. Version 2.1.5 need a new DB Table -->
<version>2.1.5</version>
<!-- New installations full DB schema here -->
<install>
<sql>
<file driver="mysql" charset="utf8">install.mysql.utf8.sql</file>
</sql>
</install>
<!-- Upgrade DB schema of older installations, in incremental steps -->
<!-- (1 SQL file per version introducing a DB schema change) -->
<update>
<schemas>
<schemapath type="mysql">sql/updates/mysql</schemapath>
</schemas>
</update>
add the SQL schema change of version 2.1.5 (e.g. CREATE TABLE) to both files:
install.mysql.utf8.sql
sql/updates/mysql/2.1.5.sql
The above info is from
https://docs.joomla.org/Manifest_files
Please note of something that is not documented (i think it is not)
#__schemas
table thus if you downgrade to v2.1.4, the #__schemas
table will still have information that DB schema was updated to v2.1.5 some time in the past, and Joomla installer will use this info, not running 2.1.5.sql againThis is nice and correct behavior
... just it is annoyance during testing as it can be confusing ... when i saw this behaviour , i thought it was a bug of the installer ... but it is not
Well, it was an update as the plugin was installed already (as v1.0) and
then I had it updated to v1.1 adding the SQL file (new features). There was
no SQL file at v1.0.
I honestly consider this a weird behaviour for the J installer.
What if an existing plugin is improved with DB tables and there is a huge
installation base of users already?
This installation behavior forces developers to add more code (install
script) just to bypass this.
On Sat, Aug 11, 2018, 1:27 PM Georgios Papadakis notifications@github.com
wrote:
Update
I do not know why the installer treats it as an update,
thinking that the plugin is already installed thus not executing
...Maybe something went wrong during uninstall of the plugin ? and there is a
record in extensions table ?Anyway since you would want to add an upgrade file too
you can do2.1.5
install.mysql.utf8.sql sql/updates/mysqladd the SQL schema change of version 2.1.5 (e.g. CREATE TABLE) to both
files:install.mysql.utf8.sql
sql/updates/mysql/2.1.5.sqlThe above info is from
https://docs.joomla.org/Manifest_filesPlease note of something that is not documented (i think it is not)
- if you upgrade to v2.1.5 and then downgrade to v2.1.4 and then
re-upgrade to v2.1.5
then you will not get the file sql/updates/mysql/2.1.5.sql as one may
expect,
this is because the "Schema version" of every extension is keep in
#__schemas table thus if you downgrade to v2.1.4 #__schemas table will
still have information that DB schema was update to v2.1.5 some time in the
past, and Joomla installer will use this infoThis is nice and correct behavior
... just it is annoyance during testing as it can be confusing ... when i
saw this behaviour , i thought it was a bug of the installer ... but it is
not—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
#21543 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/ABPdG2IWmYfQpLmifzTC72jAtMQM3CMwks5uPrGegaJpZM4V4hGr
.
Making the installer smarter
aka aware if previous versions had a particular SQL file would be
a new feature
e.g. add some extra option to inside XML to indicate the exact -version- when a SQL installation file was first added or something like this ... thus the installer will run it
if would want to try making such an effort
you can make a PR
and then try to convince people of it being worthwhile to be merged
about current issue , i guess it can be closed ...
Status | Discussion | ⇒ | Closed |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2018-08-11 19:28:39 |
Closed_By | ⇒ | fevangelou |
Yeah, it's not a bug, it's a feature.
Ok so this is an installation of a new plugin
Maybe for some reason, the installer thinks it is an update, thus
<install><sql>...
will not be used byparseQueries()
if you add
\JFactory::getApplication()->enqueueMessage($this->route, 'notice');
before:
$this->parseQueries()
do you get an 'install' or an 'update' message ?