Skip to content

Instantly share code, notes, and snippets.

@jfinstrom
Created January 26, 2024 18:00
Show Gist options
  • Save jfinstrom/7b29fff211696f8e9aa15993ed7b82dd to your computer and use it in GitHub Desktop.
Save jfinstrom/7b29fff211696f8e9aa15993ed7b82dd to your computer and use it in GitHub Desktop.
Dump freepbx queues to csv
<?php
/**
* Copyright (c) 2024 James Finstrom
*
* See the full license at: https://opensource.org/licenses/BSD-3-Clause
*/
// Set OUTPUT PATH HERE
$csvFilePath = "output.csv";
// Include FreePBX configuration
include "/etc/freepbx.conf";
// Get queues data
$queuesModule = FreePBX::Queues();
$allQueues = $queuesModule->listQueues();
// Prepare data for CSV
$final = [];
foreach ($allQueues as $queue) {
$current = [
"extension" => $queue[0],
"description" => $queue[1],
];
$current = array_merge($current, queues_get($queue[0]));
$final[$queue[0]] = $current;
}
// Write to CSV
$file = fopen($csvFilePath, "w");
if ($file === false) {
die("Error opening CSV file.");
}
$headerRow = array_keys(reset($final));
fputcsv($file, $headerRow);
foreach ($final as $dataRow) {
fputcsv($file, $dataRow);
}
fclose($file);
echo "CSV file has been generated successfully at $csvFilePath" . PHP_EOL;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment