-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7112 from piwik/6436_action_dupes
Refactor new action insertion code so duplicate actions will not exist + provide means to fix duplicates
- Loading branch information
Showing
16 changed files
with
1,374 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
/** | ||
* Piwik - free/libre analytics platform | ||
* | ||
* @link http://piwik.org | ||
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later | ||
*/ | ||
namespace Piwik\DataAccess; | ||
|
||
use Piwik\Db; | ||
use Piwik\Common; | ||
|
||
/** | ||
* Data Access Object for operations dealing with the log_action table. | ||
*/ | ||
class Actions | ||
{ | ||
/** | ||
* Removes a list of actions from the log_action table by ID. | ||
* | ||
* @param int[] $idActions | ||
*/ | ||
public function delete($idActions) | ||
{ | ||
foreach ($idActions as &$id) { | ||
$id = (int)$id; | ||
} | ||
|
||
$table = Common::prefixTable('log_action'); | ||
|
||
$sql = "DELETE FROM $table WHERE idaction IN (" . implode(",", $idActions) . ")"; | ||
Db::query($sql); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<?php | ||
/** | ||
* Piwik - free/libre analytics platform | ||
* | ||
* @link http://piwik.org | ||
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later | ||
*/ | ||
namespace Piwik\DataAccess; | ||
|
||
use Piwik\Db; | ||
|
||
/** | ||
* Data Access Object that can be used to get metadata information about | ||
* the MySQL tables Piwik uses. | ||
*/ | ||
class TableMetadata | ||
{ | ||
/** | ||
* Returns the list of column names for a table. | ||
* | ||
* @param string $table Prefixed table name. | ||
* @return string[] List of column names.. | ||
*/ | ||
public function getColumns($table) | ||
{ | ||
$table = str_replace("`", "", $table); | ||
|
||
$columns = Db::fetchAll("SHOW COLUMNS FROM `" . $table . "`"); | ||
|
||
$columnNames = array(); | ||
foreach ($columns as $column) { | ||
$columnNames[] = $column['Field']; | ||
} | ||
|
||
return $columnNames; | ||
} | ||
|
||
/** | ||
* Returns the list of idaction columns in a table. A column is | ||
* assumed to be an idaction reference if it has `"idaction"` in its | ||
* name (eg, `"idaction_url"` or `"idaction_content_name"`. | ||
* | ||
* @param string $table Prefixed table name. | ||
* @return string[] | ||
*/ | ||
public function getIdActionColumnNames($table) | ||
{ | ||
$columns = $this->getColumns($table); | ||
|
||
$columns = array_filter($columns, function ($columnName) { | ||
return strpos($columnName, 'idaction') !== false; | ||
}); | ||
|
||
return array_values($columns); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.