Magento 2 - error creating db table from custom schema - magento2

I'm trying to create a custom module for Magento 2 and I've got to the point of defining the schema in the /Setup/InstallSchema.php
When running 'php bin/magento setup:upgrade' I get the error:
Call to undefined function Test/Connector/Setup/getConnection()
The module is enabled and correctly showing in the config file. The schema file I'm trying to run is:
<?php
namespace Test\Connector\Setup;
use Magento\Framework\Setup\InstallSchemaInterface;
use Magento\Framework\Setup\ModuleContextInterface;
use Magento\Framework\Setup\SchemaSetupInterface;
use Magento\Framework\DB\Ddl\Table;
class InstallSchema implements InstallSchemaInterface
{
public function install(SchemaSetupInterface $setup, ModuleContextInterface
$context) {
$installer = $setup;
$installer->startSetup();
$tableName = $installer->getTable('test_connector_settings');
if ($installer->getConnection()->isTableExists($tableName) != true) {
$table = $installer->getConnection()
->newTable($installer->getTable('ipos_connector_settings'))
->addColumn('id', Table::TYPE_SMALLINT, null, ['identity'=> true, 'nullable'=>false, 'primary'=>true], 'ID')
->addColumn('api_url', Table::TYPE_TEXT, 255, ['nullable'=>true], 'API URL')
->addColumn('api_user', Table::TYPE_TEXT, 100, ['nullable'=>false], 'API User Name')
->addColumn('api_password', Table::TYPE_TEXT, 100, ['nullable'=>false], 'API Password');
$installer-getConnection()->createTable($table);
}
$installer->endSetup();
}
}
Thanks in advance,

Please change this line
$installer-getConnection()->createTable($table); // your code line.
With
$installer->getConnection()->createTable($table);

Related

SuiteCRM v7.10.29 Custom API v4.1

I am creating a custom API for SuiteCRM. When I attempt to run the new API from {CRM Home}/custom/service/v4_1_custom I receive an 'HTTP ERROR 500'. There are not errors in the error_log file or the SuiteCRM.log file.
I have followed the method in the following two url's
https://fayebsg.com/2013/05/extending-the-sugarcrm-api-updating-dropdowns/
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_10.0/Integration/Web_Services/Legacy_API/Extending_Web_Services/
registry.php
<?php
require_once('service/v4_1/registry.php');
class registry_v4_1_custom extends registry_v4_1
{
protected function registerFunction()
{
parent::registerFunction();
$this->serviceClass->registerFunction('test', array(), array());
}
}
SugarWebServicesImplv4_1_custom.php
<?php
if(!defined('sugarEntry'))define('sugarEntry', true);
require_once('service/v4_1/SugarWebServiceImplv4_1.php');
class SugarWebServiceImplv4_1_custom extends SugarWebServiceImplv4_1
{
/**
* #return string
*/
public function test()
{
LoggerManager::getLogger()->warn('SugerWebServiceImplv4_1_custom test()');
return ("Test Worked");
} // test
} // SugarWebServiceImplv4_1_custom
I found the answer to this issue.
In the file {SuiteCRM}/include/entryPoint.php there are many files that are included thru require_once. In this list of require_once files, there were 4 files that were set as require not require_once. These were classes and therefore could not be included a second time. I changed these to require_once and the HTTP Error 500 went away and the custom APIs started working.

Unexpected data found during update on eloquent / Laravel

I am using ajax to update a model that contains timestamps, but it throw me an exception:
{message: "Unexpected data found.", exception: "InvalidArgumentException",…}
message: "Unexpected data found."
exception: "InvalidArgumentException"
file: "/home/asus/Devagnos/almada/vendor/nesbot/carbon/src/Carbon/Traits/Creator.php"
line: 623
trace: [,…]
i have disabled the timestamps and i set the dateformat like this:
protected $dateFormat = 'Y-m-d H:i:s.u';
public $timestamps = false;
protected $dates = [
'created_at',
'updated_at'
];
alse I added these methods
/**
* #param $val
*/
public function setCreatedAtAttribute($val)
{
return Carbon::createFromFormat('Y-m-d H:i:s.u', $val);
}
/**
* #param $val
*/
public function setUpdatedAtAttribute($val)
{
return Carbon::createFromFormat('Y-m-d H:i:s.u', $val);
}
but I am always getting the same error, What am I doing wrong ?
I'm using laravel 6.8 and postgresql
If you're trying to use microseconds, then you should refer to this guide from the documentation:
https://carbon.nesbot.com/laravel/
I don't get what you tried with setCreatedAtAttribute and setUpdatedAtAttribute, setters are supposed to change the inner property, not to return a value.
Then check you gave to your DB columns enough precision (such as TIMESTAMP(6)) in your migration schemas.

Namespace missing

I have following class in folder frontend/migrations
use yii\db\Schema;
class m170727_180101_Bewerbungen extends \yii\db\Migration
{
public function safeUp()
{
$tableOptions = null;
if ($this->db->driverName === 'mysql') {
$tableOptions = 'CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE=InnoDB';
}
$this->createTable('bewerbungen', [
'bew_id' => $this->primaryKey(),
'datum' => $this->date()->notNull(),
'firma' => $this->string(100)->notNull(),
'rechtsart' => $this->integer(11),
'stadt' => $this->string(100)->notNull(),
'plz' => $this->integer(11)->notNull(),
'strasse_nr' => $this->string(100),
'ansprech_person' => $this->string(100),
'email' => $this->string(50)->notNull(),
'feedback' => $this->integer(11),
'bemerkungen' => $this->string(150),
'FOREIGN KEY ([[feedback]]) REFERENCES nachricht ([[id_message]]) ON DELETE CASCADE ON UPDATE CASCADE',
'FOREIGN KEY ([[rechtsart]]) REFERENCES rechtsform ([[id_recht]]) ON DELETE CASCADE ON UPDATE CASCADE',
], $tableOptions);
}
public function safeDown()
{
$this->dropTable('bewerbungen');
}
}
Each try to read out method safeUp() throws out error:
Unable to find 'frontend\migrations\m170727_180101_Bewerbungen' in file: E:\xampp\htdocs\Yii2_Mail/frontend/migrations/m170727_180101_Bewerbungen.php. Namespace missing?**
Here is my script:
namespace frontend\migrations; ...
$connect=new m170727_180101_Bewerbungen();
$connect->safeUp(); ...
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
What the hell is that?
The same error using like this:
$connect=new \frontend\migrations\m170727_180101_Bewerbungen();
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Try using the full path
$connect=new \frontend\migration\m170727_180101_Bewerbungen();
You have got this error because there is no namespace in your file so autoloader can not find it.
But this is not the real problem here - you are not using Yii 2 migration properly. Follow the Yii2 Migration Guide.
In addition, since you placed this migration in frontend you might want to take a look at Namespaced Migrations to actually add namespace there and to run it properly.

Fatal error: Class 'Mage_Productview_Helper_Data' not found in /app/Mage.php on line 546

In Magento admin, when trying to Add a New Role I am getting this error:
Login to admin
Go to System->Permmissions->Roles->Add New Role
Fatal error: Class 'Mage_Productview_Helper_Data' not found in /app/Mage.php on line 546
Please help. I tried to replace Adminhtml folder with fresh extraction folder but could not help
I solved this by:
adding
public static function helper($name)
{
$registryKey = '_helper/' . $name;
if (!self::registry($registryKey)) {
$helperClass = self::getConfig()->getHelperClassName($name);
if ($helperClass != "Mage_Productview_Helper_Data" )//add THIS line
self::register($registryKey, new $helperClass);
}
return self::registry($registryKey);
}
to /app/Mage.php (line 547)
And also, comment out:
if ( is_null($represent2Darray) ) {
//$result[$resourceName]['name'] = Mage::helper($module)->__((string)$resource->title);
$result[$resourceName]['level'] = $level;
}
in /app/code/core/Mage/Admin/Model/Roles.php (line 160)
Hope this helps.

send email through cakephp shell Fatal error: Class 'CakeLog' not found

i am trying to send email using cakephp shell. Following is my code:
<?php
error_reporting(0);
class EmailShell extends AppShell {
public $uses = array('Email');
public function show() {
$Email = new CakeEmail();
$Email->from('abc#gmail.com');
$Email->to('xyz#gmail.com');
$Email->subject('Forgot Password');
$Email->send();
}
}
?>
when i run this in shell i get the following error:
Fatal error: Class 'CakeLog' not found in /mnt/public_html/music_directory/web/cakephp/app/Config/bootstrap.php on line 172
where am i getting wrong? how do i solve it?
If you actually use the CakeLog class that early (in your own bootstrap)
you need to assert it is loaded.
You forgot the following statement prior to using the class:
App::uses('CakeLog', 'Log');