Account::copyConfiguration PHP Method

copyConfiguration() public method

public copyConfiguration ( $data )
    public function copyConfiguration($data)
    {
        $dataSetId = Utils::sanitize($data["dataSetId"]);
        $configurationName = Utils::sanitize($data["newDataSetName"]);
        $prefix = Core::getDbTablePrefix();
        $response = Core::$db->query("\n\t\t\tINSERT INTO {$prefix}configurations (status, date_created, account_id, num_rows_generated)\n                SELECT status, date_created, account_id, num_rows_generated\n                FROM {$prefix}configurations\n                WHERE configuration_id = {$dataSetId}\n\t\t");
        if (!$response["success"]) {
            return array("success" => false, "message" => "There was a problem copying the Data Set: " . $response["errorMessage"]);
        }
        // if it worked okay (it should!) update the last_updated and configuration_name fields
        $newConfigurationID = mysqli_insert_id(Core::$db->getDBLink());
        $response2 = Core::$db->query("\n            INSERT INTO {$prefix}configuration_history (configuration_id, last_updated, configuration_name, content)\n                SELECT {$newConfigurationID} as configuration_id, last_updated, configuration_name, content\n                FROM {$prefix}configuration_history\n                WHERE configuration_id = {$dataSetId}\n        ");
        $now = Utils::getCurrentDatetime();
        $response3 = Core::$db->query("\n            UPDATE {$prefix}configurations\n            SET date_created = '{$now}'\n            WHERE configuration_id = {$newConfigurationID}\n        ");
        $response4 = Core::$db->query("\n            UPDATE {$prefix}configuration_history\n            SET configuration_name = '" . $configurationName . "'\n            WHERE configuration_id = {$newConfigurationID}\n            ORDER BY history_id DESC\n            LIMIT 1\n        ");
        if ($response2["success"] && $response3["success"] && $response4["success"]) {
            return array("success" => true, "message" => "");
        } else {
            return array("success" => false, "message" => "There was a problem copying the Data Set.");
        }
    }