Advertisement
Guest User

Untitled

a guest
Oct 30th, 2014
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.26 KB | None | 0 0
  1. if (version_compare(phpversion(), '5.2.0', '<')===true) {
  2. echo '<div style="font:12px/1.35em arial, helvetica, sans-serif;"><div style="margin:0 0 25px 0; border-bottom:1px solid #ccc;"><h3 style="margin:0; font-size:1.7em; font-weight:normal; text-transform:none; text-align:left; color:#2f2f2f;">Whoops, it looks like you have an invalid PHP version.</h3></div><p>Magento supports PHP 5.2.0 or newer. <a href="http://www.magentocommerce.com/install" target="">Find out</a> how to install</a> Magento using PHP-CGI as a work-around.</p></div>';
  3. exit;
  4. }
  5. error_reporting(E_ALL | E_STRICT);
  6. ini_set('display_errors', 1);
  7. $mageFilename = 'app/Mage.php';
  8. if (!file_exists($mageFilename)) {
  9. echo $mageFilename." was not found";
  10. exit;
  11. }
  12. require_once $mageFilename;
  13. Mage::app();
  14. $executionPath = null;
  15. /*
  16. * determine Magento Edition
  17. */
  18. if (file_exists('LICENSE_EE.txt')) {
  19. $edition = 'EE';
  20. }elseif (file_exists('LICENSE_PRO.html')) {
  21. $edition = 'PE';
  22. } else {
  23. $edition = 'CE';
  24. }
  25. if(($edition=='EE' && version_compare(Mage::getVersion(), '1.11.0.0.', '<')===true)
  26. || ($edition=='PE' && version_compare(Mage::getVersion(), '1.11.0.0.', '<')===true)
  27. || ($edition=='CE' && version_compare(Mage::getVersion(), '1.6.0.0.', '<')===true)
  28. ){
  29. $executionPath = 'old';
  30. } else {
  31. $executionPath = 'new';
  32. }
  33. $xpathEntity = 'global/models/sales_entity/entities//table';
  34. if ($executionPath == 'old') {
  35. $xpathResource = 'global/models/sales_mysql4/entities//table';
  36. } else {
  37. $xpathResource = 'global/models/sales_resource/entities//table';
  38. }
  39. $salesEntitiesConf = array_merge(
  40. Mage::getSingleton('core/config')->init()->getXpath($xpathEntity),
  41. Mage::getSingleton('core/config')->init()->getXpath($xpathResource)
  42. );
  43. $resource = Mage::getSingleton('core/resource');
  44. $connection = $resource->getConnection('core_write');
  45. /*
  46. * If you want delete System/Order Statuses (Status and State) you
  47. * should comments below lines (46-51)
  48. */
  49. $skipTables = array (
  50. $resource->getTableName('sales_order_status'),
  51. $resource->getTableName('sales_order_status_state'),
  52. $resource->getTableName('sales_order_status_label')
  53. );
  54. $salesEntitiesConf = array_diff($salesEntitiesConf, $skipTables);
  55. /*
  56. Multiple RDBMS Support in Magento CE 1.6+ / EE 1.11+
  57. http://www.magentocommerce.com/images/uploads/RDBMS_Guide2.pdf
  58. 2.2. Adapters:
  59. ... The new Varien_DB_Adapter_Interface was added to sign a contract that all
  60. developed adapters must execute in order to get Magento working on an actual
  61. database. The interface describes the list of methods and constants that can be used by resource models...
  62. Used below in the loop:
  63. * If $executionPath == 'old'
  64. * Varien_Db_Adapter_Pdo_Mysql::showTableStatus()
  65. * Varien_Db_Adapter_Pdo_Mysql::truncate()
  66. * Else
  67. * Varien_Db_Adapter_Interface::isTableExists()
  68. * Varien_Db_Adapter_Interface::truncateTable()
  69. */
  70. while ($table = current($salesEntitiesConf) ){
  71. $table = $resource->getTableName($table);
  72. if ($executionPath == 'old') {
  73. $isTableExists = $connection->showTableStatus($table);
  74. } else {
  75. $isTableExists = $connection->isTableExists($table);
  76. }
  77. if ($isTableExists) {
  78. try {
  79. if ($executionPath == 'old') {
  80. $connection->truncate($table);
  81. } else {
  82. $connection->truncateTable($table);
  83. }
  84. printf('Successfully truncated the <i style="color:green;">%s</i> table.<br />', $table);
  85. } catch(Exception $e) {
  86. printf('Error <i style="color:red;">%s</i> occurred truncating the <i style="color:red;">%s</i> table.<br />', $e->getMessage(), $table);
  87. }
  88. }
  89. next($salesEntitiesConf);
  90. }
  91. exit('All done...');
  92.  
  93. // $this->_removeButton('delete');
  94.  
  95. public function deleteAction()
  96. {
  97. if ($order = $this->_initOrder()) {
  98. try {
  99. $order->delete();
  100. $this->_getSession()->addSuccess(
  101. $this->__('The order has been deleted.')
  102. );
  103. }
  104. catch (Mage_Core_Exception $e) {
  105. $this->_getSession()->addError($e->getMessage());
  106. }
  107. catch (Exception $e) {
  108. $this->_getSession()->addError($this->__('The order has not been deleted.'));
  109. Mage::logException($e);
  110. }
  111. $this->_redirect('*/*/');
  112. }
  113. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement