├── Console └── Command │ ├── AbstractCommand.php │ ├── Categories.php │ ├── Customers.php │ ├── Orders.php │ ├── Products.php │ └── Reviews.php ├── Model ├── AbstractReset.php ├── Categories.php ├── Customers.php ├── Orders.php ├── Products.php └── Reviews.php ├── README.md ├── composer.json ├── etc ├── di.xml └── module.xml └── registration.php /Console/Command/AbstractCommand.php: -------------------------------------------------------------------------------- 1 | objectManager = $objectManager; 13 | parent::__construct(); 14 | } 15 | 16 | protected function execute(InputInterface $input, OutputInterface $output) 17 | { 18 | $this->input = $input; 19 | $this->output = $output; 20 | 21 | $areaCode = Area::AREA_ADMINHTML; 22 | /** @var \Magento\Framework\App\State $appState */ 23 | $appState = $this->objectManager->get('Magento\Framework\App\State'); 24 | $appState->setAreaCode($areaCode); 25 | /** @var \Magento\Framework\ObjectManager\ConfigLoaderInterface $configLoader */ 26 | $configLoader = $this->objectManager->get('Magento\Framework\ObjectManager\ConfigLoaderInterface'); 27 | $this->objectManager->configure($configLoader->load($areaCode)); 28 | 29 | $this->objectManager->get('Magento\Store\Model\StoreManagerInterface')->setCurrentStore(Area::AREA_ADMIN); 30 | } 31 | } 32 | 33 | -------------------------------------------------------------------------------- /Console/Command/Categories.php: -------------------------------------------------------------------------------- 1 | setName('reset:categories'); 17 | $this->setDescription('Reset categories in database.'); 18 | parent::configure(); 19 | } 20 | 21 | /** 22 | * {@inheritdoc} 23 | */ 24 | protected function execute(InputInterface $input, OutputInterface $output) 25 | { 26 | parent::execute($input, $output); 27 | $output->setDecorated(true); 28 | $sync = $this->objectManager->get('Comunicart\Reset\Model\Categories'); 29 | $sync->setOutput($output); 30 | $sync->reset(); 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /Console/Command/Customers.php: -------------------------------------------------------------------------------- 1 | setName('reset:customers'); 17 | $this->setDescription('Reset customers in database.'); 18 | parent::configure(); 19 | } 20 | 21 | /** 22 | * {@inheritdoc} 23 | */ 24 | protected function execute(InputInterface $input, OutputInterface $output) 25 | { 26 | parent::execute($input, $output); 27 | $output->setDecorated(true); 28 | $sync = $this->objectManager->get('Comunicart\Reset\Model\Customers'); 29 | $sync->setOutput($output); 30 | $sync->reset(); 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /Console/Command/Orders.php: -------------------------------------------------------------------------------- 1 | setName('reset:orders'); 17 | $this->setDescription('Reset orders in database.'); 18 | parent::configure(); 19 | } 20 | 21 | /** 22 | * {@inheritdoc} 23 | */ 24 | protected function execute(InputInterface $input, OutputInterface $output) 25 | { 26 | parent::execute($input, $output); 27 | $output->setDecorated(true); 28 | $sync = $this->objectManager->get('Comunicart\Reset\Model\Orders'); 29 | $sync->setOutput($output); 30 | $sync->reset(); 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /Console/Command/Products.php: -------------------------------------------------------------------------------- 1 | setName('reset:products'); 17 | $this->setDescription('Reset products in database.'); 18 | parent::configure(); 19 | } 20 | 21 | /** 22 | * {@inheritdoc} 23 | */ 24 | protected function execute(InputInterface $input, OutputInterface $output) 25 | { 26 | parent::execute($input, $output); 27 | $output->setDecorated(true); 28 | $sync = $this->objectManager->get('Comunicart\Reset\Model\Products'); 29 | $sync->setOutput($output); 30 | $sync->reset(); 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /Console/Command/Reviews.php: -------------------------------------------------------------------------------- 1 | setName('reset:reviews'); 17 | $this->setDescription('Reset reviews in database.'); 18 | parent::configure(); 19 | } 20 | 21 | /** 22 | * {@inheritdoc} 23 | */ 24 | protected function execute(InputInterface $input, OutputInterface $output) 25 | { 26 | parent::execute($input, $output); 27 | $output->setDecorated(true); 28 | $sync = $this->objectManager->get('Comunicart\Reset\Model\Reviews'); 29 | $sync->setOutput($output); 30 | $sync->reset(); 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /Model/AbstractReset.php: -------------------------------------------------------------------------------- 1 | _resource = $resource; 60 | $this->_indexerFactory = $indexerFactory; 61 | $this->_eventManager = $eventManager; 62 | } 63 | 64 | 65 | /** 66 | * @return \Magento\Framework\DB\Adapter\AdapterInterface 67 | */ 68 | protected function getConnection() 69 | { 70 | if (!$this->_connection) { 71 | $this->_connection = $this->_resource->getConnection(); 72 | } 73 | return $this->_connection; 74 | } 75 | 76 | /** 77 | * @param $table 78 | * @return string 79 | */ 80 | public function getTableName($table) { 81 | return $this->_resource->getTableName($table); 82 | } 83 | 84 | /** 85 | * @param \Symfony\Component\Console\Output\OutputInterface $output 86 | */ 87 | public function setOutput($output) { 88 | $this->_output = $output; 89 | } 90 | 91 | /** 92 | * @param array $indexerIds 93 | */ 94 | protected function reindex($indexerIds) { 95 | foreach ($indexerIds as $indexerId) { 96 | $indexer = $this->_indexerFactory->create(); 97 | $indexer->load($indexerId); 98 | $indexer->reindexAll(); 99 | } 100 | } 101 | 102 | /** 103 | * Perform reset. 104 | */ 105 | public function reset() 106 | { 107 | $this->_eventManager->dispatch('reset_data', [ 108 | 'object' => $this, 109 | 'tables' => $this->_getTables(), 110 | 'execute_before' => $this->_executeBefore(), 111 | 'execute_after' => $this->_executeAfter() 112 | ]); 113 | 114 | $tables = $this->_getTables(); 115 | $before = $this->_executeBefore(); 116 | $after = $this->_executeAfter(); 117 | 118 | if ($this->_output) { 119 | $total = count($tables); 120 | if (! empty($before)) { 121 | $total += count($before); 122 | } 123 | if (! empty($after)) { 124 | $total += count($after); 125 | } 126 | $this->_progressBar = new \Symfony\Component\Console\Helper\ProgressBar($this->_output, $total); 127 | $this->_progressBar->setFormat( 128 | '%current%/%max% [%bar%] %percent:3s%% %elapsed% %memory:6s%' 129 | ); 130 | $this->_output->writeln(''); 131 | $this->_output->writeln('Performing reset...'); 132 | $this->_output->writeln(''); 133 | $this->_progressBar->start(); 134 | $this->_progressBar->display(); 135 | } 136 | 137 | if (! empty($before)) { 138 | foreach ($before as $sql) { 139 | $this->getConnection()->query($sql); 140 | if ($this->_output) { 141 | $this->_progressBar->advance(); 142 | } 143 | } 144 | } 145 | 146 | foreach ($tables as $table) { 147 | $tableName = $this->getTableName($table); 148 | $this->getConnection()->query("DELETE FROM $tableName"); 149 | $this->getConnection()->query("SET FOREIGN_KEY_CHECKS = 0"); 150 | $this->getConnection()->query("TRUNCATE TABLE $tableName"); 151 | $this->getConnection()->query("ALTER TABLE $tableName AUTO_INCREMENT=1"); 152 | $this->getConnection()->query("SET FOREIGN_KEY_CHECKS = 1"); 153 | 154 | if ($this->_output) { 155 | $this->_progressBar->advance(); 156 | } 157 | } 158 | 159 | if (! empty($after)) { 160 | foreach ($after as $sql) { 161 | $this->getConnection()->query($sql); 162 | if ($this->_output) { 163 | $this->_progressBar->advance(); 164 | } 165 | } 166 | } 167 | 168 | $this->_progressBar->finish(); 169 | $this->_output->writeln(''); 170 | $this->_output->writeln(''); 171 | 172 | $this->_output->writeln('Reset has been performed successfully!'); 173 | 174 | $this->_output->writeln(''); 175 | } 176 | 177 | /** 178 | * @param array $tables 179 | */ 180 | public function setTables($tables) { 181 | $this->_tables = $tables; 182 | } 183 | 184 | /** 185 | * @param array $executeBefore 186 | */ 187 | public function setExecuteBefore($executeBefore) { 188 | $this->_executeBefore = $executeBefore; 189 | } 190 | 191 | /** 192 | * @param array $executeAfter 193 | */ 194 | public function setExecuteAfter($executeAfter) { 195 | $this->_executeAfter = $executeAfter; 196 | } 197 | 198 | /** 199 | * Return tables to truncate. 200 | */ 201 | abstract protected function getTables(); 202 | 203 | protected function _getTables() { 204 | if ($this->_tables === null) { 205 | $this->_tables = $this->getTables(); 206 | } 207 | 208 | return $this->_tables; 209 | } 210 | 211 | /** 212 | * Return SQL code to execute before reset 213 | * @return array 214 | */ 215 | abstract protected function executeBefore(); 216 | 217 | protected function _executeBefore() { 218 | if ($this->_executeBefore === null) { 219 | $this->_executeBefore = $this->executeBefore(); 220 | } 221 | 222 | return $this->_executeBefore; 223 | } 224 | 225 | /** 226 | * Return SQL code to execute after reset 227 | * @return array 228 | */ 229 | abstract protected function executeAfter(); 230 | 231 | protected function _executeAfter() { 232 | if ($this->_executeAfter === null) { 233 | $this->_executeAfter = $this->executeAfter(); 234 | } 235 | 236 | return $this->_executeAfter; 237 | } 238 | } 239 | -------------------------------------------------------------------------------- /Model/Categories.php: -------------------------------------------------------------------------------- 1 | getTableName('url_rewrite')." WHERE entity_type = 'category'", 14 | "INSERT INTO ".$this->getTableName('catalog_category_entity')." (entity_id, attribute_set_id, parent_id, created_at, updated_at, path, position, level, children_count) 15 | VALUES 16 | (1, 0, 0, '$now', '$now', '1', 0, 0, 1), 17 | (2, 3, 1, '$now', '$now', '1/2', 1, 1, 0);", 18 | ]; 19 | } 20 | 21 | protected function getTables() { 22 | return [ 23 | 'catalog_category_entity', 24 | 'catalog_category_entity_datetime', 25 | 'catalog_category_entity_decimal', 26 | 'catalog_category_entity_int', 27 | 'catalog_category_entity_text', 28 | 'catalog_category_entity_varchar', 29 | 'catalog_category_product', 30 | 'catalog_category_product_index', 31 | ]; 32 | } 33 | 34 | public function reset() 35 | { 36 | parent::reset(); 37 | $this->_output->writeln('Reindexing...'); 38 | 39 | $this->reindex([ 40 | 'catalog_category_product', 41 | 'catalog_product_category', 42 | ]); 43 | 44 | $this->_output->writeln('Reindexing has been performed successfully!'); 45 | } 46 | } -------------------------------------------------------------------------------- /Model/Customers.php: -------------------------------------------------------------------------------- 1 | _output->writeln('Reindexing...'); 39 | 40 | $this->reindex([ 41 | 'customer_grid', 42 | ]); 43 | 44 | $this->_output->writeln('Reindexing has been performed successfully!'); 45 | } 46 | } -------------------------------------------------------------------------------- /Model/Orders.php: -------------------------------------------------------------------------------- 1 | _storeManager = $storeManager; 22 | } 23 | 24 | protected function executeBefore() { 25 | return []; 26 | } 27 | 28 | protected function executeAfter() { 29 | return []; 30 | } 31 | 32 | protected function getTables() { 33 | $tables = [ 34 | 'eav_entity_store', 35 | 'report_compared_product_index', 36 | 'report_event', 37 | 'sales_bestsellers_aggregated_daily', 38 | 'sales_bestsellers_aggregated_monthly', 39 | 'sales_bestsellers_aggregated_yearly', 40 | 'sales_creditmemo', 41 | 'sales_creditmemo_comment', 42 | 'sales_creditmemo_grid', 43 | 'sales_creditmemo_item', 44 | 'sales_invoice', 45 | 'sales_invoiced_aggregated', 46 | 'sales_invoiced_aggregated_order', 47 | 'sales_invoice_comment', 48 | 'sales_invoice_grid', 49 | 'sales_invoice_item', 50 | 'sales_order', 51 | 'sales_order_address', 52 | 'sales_order_aggregated_created', 53 | 'sales_order_aggregated_updated', 54 | 'sales_order_grid', 55 | 'sales_order_item', 56 | 'sales_order_payment', 57 | 'sales_order_status_history', 58 | 'sales_order_tax', 59 | 'sales_order_tax_item', 60 | 'sales_payment_transaction', 61 | 'sales_refunded_aggregated', 62 | 'sales_refunded_aggregated_order', 63 | 'sales_shipment', 64 | 'sales_shipment_comment', 65 | 'sales_shipment_grid', 66 | 'sales_shipment_item', 67 | 'sales_shipment_track', 68 | 'sales_shipping_aggregated', 69 | 'sales_shipping_aggregated_order', 70 | 'salesrule_coupon_aggregated', 71 | 'salesrule_coupon_aggregated_updated', 72 | 'quote', 73 | 'quote_address', 74 | 'quote_address_item', 75 | 'quote_id_mask', 76 | 'quote_item', 77 | 'quote_item_option', 78 | 'quote_payment', 79 | 'quote_shipping_rate', 80 | 'tax_order_aggregated_created', 81 | 'tax_order_aggregated_updated' 82 | ]; 83 | 84 | foreach ($this->_storeManager->getStores(true) as $store) { 85 | foreach (['invoice', 'order', 'shipment', 'creditmemo'] as $type) { 86 | $tables[] = 'sequence_' . $type . '_' . $store->getId(); 87 | } 88 | } 89 | 90 | return $tables; 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /Model/Products.php: -------------------------------------------------------------------------------- 1 | getTableName('url_rewrite')." WHERE entity_type = 'product'" 13 | ]; 14 | } 15 | 16 | protected function getTables() { 17 | return [ 18 | 'sendfriend_log', 19 | 'catalog_product_bundle_option', 20 | 'catalog_product_bundle_option_value', 21 | 'catalog_product_bundle_selection', 22 | 'catalog_product_entity_datetime', 23 | 'catalog_product_entity_decimal', 24 | 'catalog_product_entity_gallery', 25 | 'catalog_product_entity_int', 26 | 'catalog_product_entity_media_gallery', 27 | 'catalog_product_entity_media_gallery_value', 28 | 'catalog_product_entity_text', 29 | 'catalog_product_entity_tier_price', 30 | 'catalog_product_entity_varchar', 31 | 'catalog_product_link', 32 | 'catalog_product_link_attribute_decimal', 33 | 'catalog_product_link_attribute_int', 34 | 'catalog_product_link_attribute_varchar', 35 | 'catalog_product_option', 36 | 'catalog_product_option_price', 37 | 'catalog_product_option_title', 38 | 'catalog_product_option_type_price', 39 | 'catalog_product_option_type_title', 40 | 'catalog_product_option_type_value', 41 | 'catalog_product_super_attribute_label', 42 | 'catalog_product_super_attribute', 43 | 'catalog_product_super_link', 44 | 'catalog_product_website', 45 | 'catalog_category_product_index', 46 | 'catalog_category_product', 47 | 'cataloginventory_stock_item', 48 | 'cataloginventory_stock_status', 49 | 'catalog_product_entity', 50 | 'search_query', 51 | 'wishlist', 52 | 'wishlist_item', 53 | 'wishlist_item_option', 54 | 'report_viewed_product_aggregated_daily', 55 | 'report_viewed_product_aggregated_monthly', 56 | 'report_viewed_product_aggregated_yearly', 57 | 'report_viewed_product_index', 58 | ]; 59 | } 60 | 61 | public function reset() 62 | { 63 | parent::reset(); 64 | $this->_output->writeln('Reindexing...'); 65 | 66 | $this->reindex([ 67 | 'catalog_category_product', 68 | 'catalog_product_category', 69 | 'catalog_product_price', 70 | 'catalog_product_attribute', 71 | 'cataloginventory_stock', 72 | 'catalogsearch_fulltext', 73 | ]); 74 | 75 | $this->_output->writeln('Reindexing has been performed successfully!'); 76 | } 77 | } -------------------------------------------------------------------------------- /Model/Reviews.php: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Comunicart\Reset\Console\Command\Products 7 | Comunicart\Reset\Console\Command\Reviews 8 | Comunicart\Reset\Console\Command\Categories 9 | Comunicart\Reset\Console\Command\Customers 10 | Comunicart\Reset\Console\Command\Orders 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /etc/module.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /registration.php: -------------------------------------------------------------------------------- 1 |