Skip to content

Commit 800cc13

Browse files
committed
Added truncate tables feature
1 parent 54a0f68 commit 800cc13

File tree

1 file changed

+19
-18
lines changed

1 file changed

+19
-18
lines changed

src/Classes/DeleteHelper.php

+19-18
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,23 @@ public function dropMultiTables()
3333
return $this;
3434
}
3535

36+
/**
37+
* truncate multiple tables by their names in the database
38+
*
39+
* @return DeleteHelper
40+
* @author karam mustafa
41+
*/
42+
public function truncateMultiTables()
43+
{
44+
$this->disableAndEnableForeignChecks(function () {
45+
foreach ($this->tables as $index => $table) {
46+
$this->appendToQuery("TRUNCATE $table;");
47+
}
48+
});
49+
50+
return $this;
51+
}
52+
3653
/**
3754
* this function is divide the process of deleting data into a number of queries,
3855
* instead of making a large query that may take longer.
@@ -68,26 +85,10 @@ public function deleteLargeData(\Closure $callback = null)
6885
*/
6986
public function prepareDataBaseTablesToDrop()
7087
{
71-
$this->getAllTablesFromDatabase();
72-
73-
$columnName = 'Tables_in_'.env('DB_DATABASE');
74-
75-
foreach ($this->getSavedItems() as $table) {
76-
$this->setTables($table->$columnName);
77-
}
78-
79-
$this->dropMultiTables();
88+
$this->getAllTablesFromDatabase()
89+
->dropMultiTables();
8090

8191
return $this;
8292
}
8393

84-
/**
85-
* fetch all database tables.
86-
*
87-
* @author karam mustafa
88-
*/
89-
private function getAllTablesFromDatabase()
90-
{
91-
$this->setSavedItems(DB::select('SHOW TABLES'));
92-
}
9394
}

0 commit comments

Comments
 (0)