public function dbCheck() { $dbOk = true; $localError = false; $this->messages[] = "Checking database"; $installer = new Mage_Sales_Model_Mysql4_Setup('sales_setup'); $installer->startSetup(); if (isset($_GET['fix'])) { $fix = $_GET['fix'] == 'true'; } else { $fix = false; } foreach ($this->_getDbFields() as $field) { switch ($field[0]) { case 'eav': try { $sql = "SELECT `attribute_id` FROM `{$installer->getTable('eav_attribute')}` WHERE `attribute_code` ='{$field['2']}'"; $test = $installer->getConnection('core_read')->fetchRow($sql); if (!isset($test['attribute_id']) && !$test['attribute_id'] > 0) { throw new Exception('eav attribute ' . $field[2] . ' is not installed'); } $this->messages[] = "[OK] eav attribute " . $field[2] . " with id " . $test['attribute_id'] . ""; } catch (Exception $e) { if ($fix) { $this->messages[] = "Attempting fix for eav attribute " . $field[2] . ""; try { $installer->addAttribute($field[1], $field[2], $field[3]); $this->messages[] = "[FIX OK] eav attribute " . $field[2] . " fixed"; } catch (Exception $e) { $this->messages[] = "[FAILED] fixing eav attribute " . $field[2] . ""; $dbOk = false; $this->messages[] = $e->getMessage(); $localError = true; } } else { $this->messages[] = "[FAILED] eav attribute " . $field[2] . ""; Mage::getSingleton('core/session')->addWarning('[FAILED] eav attribute ' . $field[2]); $dbOk = false; $this->messages[] = "[ERR] " . $e->getMessage(); $localError = true; } } break; case 'sql-column': try { $test = $installer->run("SELECT `{$field['2']}` FROM `{$installer->getTable($field[1])}` LIMIT 0"); $this->messages[] = "[OK] column " . $field[2] . ""; } catch (Exception $e) { if ($fix) { $this->messages[] = "Attempting fix for column " . $field[2] . ""; try { $test = $installer->run("ALTER TABLE `{$installer->getTable($field[1])}` ADD COLUMN `{$field['2']}` {$field['3']}"); $this->messages[] = "[FIX OK] column " . $field[2] . " fixed"; } catch (Exception $e) { $this->messages[] = "[FAILED] fixing column " . $field[2] . ""; $dbOk = false; $this->messages[] = $e->getMessage(); $localError = true; } } else { $this->messages[] = "[FAILED] column " . $field[2] . ""; $dbOk = false; $this->messages[] = "[ERR] " . $e->getMessage(); $localError = true; } } break; } } $installer->endSetup(); if (empty($localError)) { return true; } else { if ($dbOk == false) { $this->messages[] = "<p>The selftest has found some problems with your database install.\n You can attempt to fix this by appending ?fix=true to the address or clicking this <a href=\"" . htmlentities($_SERVER['PHP_SELF']) . "?fix=true\">link</a>.</p><p style=\"color:red;\"><em>A DATABASE BACKUP IS strongly RECOMMENDED BEFORE ATTEMPTING THIS!</em></p>"; } return false; } }
<?php require_once 'app/Mage.php'; Mage::app()->setCurrentStore(Mage::getModel('core/store')->load(Mage_Core_Model_App::ADMIN_STORE_ID)); $installer = new Mage_Sales_Model_Mysql4_Setup(); //Mage_Eav_Model_Entity_Setup,Mage_Catalog_Model_Resource_Setup, $installer->startSetup(); $installer->getConnection()->addColumn($this->getTable('sales/order'), 'dailydeals', 'varchar(255) NULL'); $installer->run("\n\nCREATE TABLE IF NOT EXISTS magegiant_dailydeal (\n `id` int(11) unsigned NOT NULL auto_increment,\n `title` varchar(255) NOT NULL default '',\n `products` varchar(255) NULL,\n `products_deal` varchar(255) NULL,\n `product_id` int(11) NOT NULL,\n `product_name` varchar(255) NOT NULL,\n `thumbnail_image` varchar(255) NULL,\n `save` varchar(255) NOT NULL default '0',\n `deal_price` decimal(12,2) NOT NULL,\n `quantity` int(11) NOT NULL default '0',\n `sold` int(11) NOT NULL default '0',\n `start_time` datetime NULL,\n `deal_time` int(11) NULL,\n `time_left` datetime NULL,\n `close_time` datetime NULL,\n `status` int(1) NOT NULL default '1',\n `store_id` text NULL,\n `process` int(1) NOT NULL default '0',\n `is_random` int(1) NOT NULL default '0',\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8;\n\n "); $installer->endSetup();