[Solved] Concrete 5.7.3.1 Insert data into table during package installation
Permalink
Hello everyone,
during the installation of a packet created by me, I'm using the db.xml to create new tables in the database. This works quite well so far.
But I want to fill the new tables with the some date during the installation of the package.
Here's what I've tried:
1. db.xml query instructions
The installation of the packet is successful, but there are no data in the table.
2. SQL statements during installation in the controller
The installation of the packet is successful, but there are no data in the table.
I tried it with the version 5.7.3 and 5.7.3.1. both unfortunately unsuccessful.
What exactly do I have to do to fill the tables with data during installation?
Preliminary ever thank you for your help and sorry for my bad english.
Greetings
Daniel
during the installation of a packet created by me, I'm using the db.xml to create new tables in the database. This works quite well so far.
But I want to fill the new tables with the some date during the installation of the package.
Here's what I've tried:
1. db.xml query instructions
<?xml version="1.0"?> <schema version="0.3"> <table name="cs_test"> <field name="TestID" type="I" /> <field name="TestValue" type="C" size="200" /> </table> <sql> <query>INSERT INTO cs_test (TestID, TestValue) VALUES ('1', 'Hello World')</query> </sql> </schema>
The installation of the packet is successful, but there are no data in the table.
2. SQL statements during installation in the controller
namespace Concrete\Package\CSTest; use SinglePage; use Database; class Controller extends \Concrete\Core\Package\Package { protected $pkgHandle = 'cstest'; protected $appVersionRequired = '5.7.3'; protected $pkgVersion = '0.0.1'; public function getPackageDescription() { return t('This is the description of the test package.'); } public function getPackageName() { return t('Test Package Name'); } public function install() { $pkg = parent::install();
Viewing 15 lines of 23 lines. View entire code block.
The installation of the packet is successful, but there are no data in the table.
I tried it with the version 5.7.3 and 5.7.3.1. both unfortunately unsuccessful.
What exactly do I have to do to fill the tables with data during installation?
Preliminary ever thank you for your help and sorry for my bad english.
Greetings
Daniel
I added some code to the /concrete/src/Package/Package.php file -
That seems to have taken care of some of the additional SQL I'd like to execute in my db.xml upon package installation.
$dbxml = simplexml_load_file($xmlFile); foreach($dbxml->sql as $sql) { foreach($sql->query as $query) { $db->query($query); } }
That seems to have taken care of some of the additional SQL I'd like to execute in my db.xml upon package installation.
Thanks axiandev,
I added your code in the installDB() function, just before "$db->commit();"
Also added ""use Loader;" (thanks Andrew)
Works like a champ!
How long does it take for a code fix to work it's way into a production release?
I have a new block ready for the marketplace, but having it's support data is critical to it's operation. It will need to sit on the shelf until Concrete5 can load data during a package install.
I added your code in the installDB() function, just before "$db->commit();"
Also added ""use Loader;" (thanks Andrew)
Works like a champ!
How long does it take for a code fix to work it's way into a production release?
I have a new block ready for the marketplace, but having it's support data is critical to it's operation. It will need to sit on the shelf until Concrete5 can load data during a package install.
Same issue. bugs..? in concrete 5.6 query statement work fine but when migrating to 5.7 not work and need execute manually in package controller.
I didn't even know ADODB let you execute queries in AXMLS with a <sql> XML node. That will not work in our updated compatibility version.
Your second example, however, should totally work. At a glance, though, it looks like you're never importing the "Loader" class. If you had use Loader; at the top of the script that would fix it.
Your second example, however, should totally work. At a glance, though, it looks like you're never importing the "Loader" class. If you had use Loader; at the top of the script that would fix it.
Thank you for your help. With use Loader everything works fine. Solved
It seems like the core Package class's installDB method only really cares about DDL and no DML.
Anyone out there having any luck?