Hi all,
Firstly, some background. I am a relatively experienced php programmer, I can usually get things done simply. I don't have much experience coding php with drupal though. I have never made a custom module, but I have added some things to an existing module.
I am currently trying to convert a 4.7 module to 5.x, and eventually 6.x. But I am having some issues just getting from 4.7 to 5.x. I did a search for all the things listed on the upgrading modules to 5.x page from drupal.org. I found some, fixed some, but still having some issues.
One of them is an issue with the database, apparently the install function didn't work properly, I get errors because the tables don't exist. Did anything actually change that would prevent working 4.7 install code fromworking? I didn't notice anything. Here is the install function:
function thermometer_install()
{
$db_table_sold_trans = variable_get('db_table_sold_trans',"stellar_ipn_trans");
$db_table_sold_item = variable_get('db_table_sold_item',"stellar_ipn_item");
$db_build_trans = "
CREATE TABLE `$db_table_sold_trans` (
`id` INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
`invoice` VARCHAR(127),
`custom` VARCHAR(255),
`test_ipn` INTEGER UNSIGNED DEFAULT 0,
`memo` VARCHAR(255),
`business` VARCHAR(127),
`receiver_id` VARCHAR(13),
`receiver_email` VARCHAR(127),
`first_name` VARCHAR(64),
`last_name` VARCHAR(64),
`contact_phone` VARCHAR(24),
`address_city` VARCHAR(40),
`address_country` VARCHAR(64),
`address_country_code` VARCHAR(2),
`address_name` VARCHAR(128),
`address_state` VARCHAR(40),
`address_status` VARCHAR(12),
`address_street` VARCHAR(200),
`address_zip` VARCHAR(20),
`payer_business_name` VARCHAR(127),
`payer_email` VARCHAR(127),
`payer_id` VARCHAR(13),
`payer_status` VARCHAR(12),
`residence_country` VARCHAR(2),
`txn_id` VARCHAR(17),
`txn_type` VARCHAR(24),
`transaction_entity` VARCHAR(10),
`tax` DECIMAL(6,4),
`auth_id` VARCHAR(64),
`auth_exp` VARCHAR(64),
`auth_status` VARCHAR(12),
`auth_amount` DECIMAL(10,2),
`num_cart_items` INTEGER,
`mc_currency` VARCHAR(3),
`exchange_rate` DECIMAL(10,2),
`mc_fee` DECIMAL(10,2),
`mc_gross` DECIMAL(10,2),
`parent_txn_id` VARCHAR(17),
`payment_date` VARCHAR(64),
`payment_status` VARCHAR(24),
`payment_type` VARCHAR(12),
`pending_reason` VARCHAR(16),
`reason_code` VARCHAR(16),
`remaining_settle` DECIMAL(10,2),
`mc_handling` DECIMAL(10,2),
`mc_shipping` DECIMAL(10,2),
`settle_amount` DECIMAL(10,2),
`settle_currency` VARCHAR(3),
`case_id` VARCHAR(64),
`case_type` VARCHAR(12),
`case_creation_date` VARCHAR(64),
`handling` DECIMAL(10,2),
`shipping` DECIMAL(10,2),
`receipt_id` VARCHAR(24),
`time` DATETIME,
`method` varchar(20) NOT NULL default 'paypal',
PRIMARY KEY(`id`)
)
TYPE = InnoDB;";
$db_build_item = "CREATE TABLE `$db_table_sold_item` (
`id` INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
`parent_id` INTEGER UNSIGNED,
`sequence_id` INTEGER UNSIGNED,
`test_ipn` INTEGER UNSIGNED DEFAULT 0,
`item_name` VARCHAR(127) NOT NULL,
`item_number` VARCHAR(127),
`mc_gross` DECIMAL(10,2),
`option_name1` VARCHAR(64),
`option_selection1` VARCHAR(200),
`option_name2` VARCHAR(64),
`option_selection2` VARCHAR(200),
`quantity` INTEGER,
`mc_shipping` DECIMAL(10,2),
`mc_handling` DECIMAL(10,2),
`shipping` DECIMAL(10,2),
`tax` DECIMAL(6,4),
`time` DATETIME,
`method` varchar(20) NOT NULL default 'paypal',
PRIMARY KEY(`id`)
)
TYPE = InnoDB;";
$result = mysql_query($db_build_trans);
$result = db_query($db_build_item);
variable_set("db_table_sold_trans","stellar_ipn_trans");
variable_set("db_table_sold_item","stellar_ipn_item");
variable_set('thermometer_type',0);
variable_set('thermometer_itemNumber',"donation");
variable_set("thermometer_goal",0);
}
Next: I am getting field offset errors. My searches yield results, that seem to point in the direction of wrapping things with curly braces {}. This was a fix for a certain module at least. I am hoping there is a more logically explained fix for this. So I can actually see what needs to be changed. I'll list the reported function here, but there are probably others that need changed as well.
Fatal error: Cannot use string offset as an array in /home/rizen/public_html/drupfive/modules/system/system.module on line 1077
The actual line number is way off, theres only 829 lines in the module.
function thermometer_menu() {
drupal_add_css(drupal_get_path('module', 'thermometer') .'/thermometer.css');
$items = array();
$items[] = array(
'path' => 'admin/settings/thermometer',
'title' => t('Donations Thermometer'),
'description' => t('This is where you can change the settings for the donations thermometer module.'),
'callback' => 'thermometer_admin',
'access' => user_access('administer thermometer'),
'type' => MENU_NORMAL_ITEM
);
$items[] = array(
'path' => 'thermometer_admin_index',
'title' => t('Donation Thermometer'),
'callback' => 'thermometer_admin_index',
'access' => user_access('administer thermometer'),
'type' => MENU_NORMAL_ITEM
);
$items[] = array(
'path' => 'thermometer_DeleteDonations',
'title' => t('Delete Donations'),
'callback' => 'thermometer_DeleteDonations',
'access' => user_access('administer thermometer'),
'type' => MENU_SUGGESTED_ITEM
);
$items[] = array(
'path' => 'thermometer_EnterMailed',
'title' => t('Enter Mailed Donation'),
'callback' => 'thermometer_EnterMailed',
'access' => user_access('administer thermometer'),
'type' => MENU_SUGGESTED_ITEM
);
$items[] = array(
'path' => 'thermometer_viewDonations',
'title' => t('View Donations'),
'callback' => 'thermometer_viewDonations',
'access' => user_access('administer thermometer'),
'type' => MENU_SUGGESTED_ITEM
);
$items[] = array(
'path' => 'thermometer_Delete',
'title' => t('Deleted'),
'callback' => 'thermometer_Delete',
'access' => user_access('administer thermometer'),
'type' => MENU_SUGGESTED_ITEM
);
return $items;
}
Any help and suggestions would be much appreciated. Feel free to just modify the code as you see fit. Is there any actual tutorial for upgrading somewhere on the web? I certainly have not been able to find one. I assume there were lots of common problems people had when upgrading their modules, and I would love to learn from the people who have already been fixing them.
Thank You!
Comments
Okay so I figured out the
Okay so I figured out the first one. Apparently you can't just have the install function inside the module anymore. Though I didn't see anything about it in the upgrading from 4.7 to 5 article. Maybe the guy who wrote this module didn't know, or maybe it worked with 4.7.
I split it into the .install file and it now works. YaY! \o/
However the string offset thing is still there. Any ideas?
RiZeN
Did you get this working?
Not sure I could help with your problem but I wondered if you got this working? I'd like to use something like this. Would you consider sharing the module?