aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/sabre/vobject/bin/mergeduplicates.php
diff options
context:
space:
mode:
authorMario <mario@mariovavti.com>2019-04-25 11:24:09 +0200
committerMario <mario@mariovavti.com>2019-04-25 11:24:09 +0200
commitf1c07977809ce3221286d53e99f0d91145b1166f (patch)
tree4c067a3b701ea56f10070c386b26a30f93666eb0 /vendor/sabre/vobject/bin/mergeduplicates.php
parent701167bc125700efb3e6ce759b85bcb4d36ee42e (diff)
downloadvolse-hubzilla-f1c07977809ce3221286d53e99f0d91145b1166f.tar.gz
volse-hubzilla-f1c07977809ce3221286d53e99f0d91145b1166f.tar.bz2
volse-hubzilla-f1c07977809ce3221286d53e99f0d91145b1166f.zip
Revert "update composer libs"
This reverts commit e779335d060b3a51d6a144d23af4097ae6801473
Diffstat (limited to 'vendor/sabre/vobject/bin/mergeduplicates.php')
-rw-r--r--vendor/sabre/vobject/bin/mergeduplicates.php100
1 files changed, 62 insertions, 38 deletions
diff --git a/vendor/sabre/vobject/bin/mergeduplicates.php b/vendor/sabre/vobject/bin/mergeduplicates.php
index e6cde73dd..076524d36 100644
--- a/vendor/sabre/vobject/bin/mergeduplicates.php
+++ b/vendor/sabre/vobject/bin/mergeduplicates.php
@@ -6,8 +6,8 @@ namespace Sabre\VObject;
// This sucks.. we have to try to find the composer autoloader. But chances
// are, we can't find it this way. So we'll do our bestest
$paths = [
- __DIR__.'/../vendor/autoload.php', // In case vobject is cloned directly
- __DIR__.'/../../../autoload.php', // In case vobject is a composer dependency.
+ __DIR__ . '/../vendor/autoload.php', // In case vobject is cloned directly
+ __DIR__ . '/../../../autoload.php', // In case vobject is a composer dependency.
];
foreach ($paths as $path) {
@@ -22,12 +22,14 @@ if (!class_exists('Sabre\\VObject\\Version')) {
die(1);
}
-echo 'sabre/vobject ', Version::VERSION, " duplicate contact merge tool\n";
+echo "sabre/vobject ", Version::VERSION, " duplicate contact merge tool\n";
if ($argc < 3) {
+
echo "\n";
- echo 'Usage: ', $argv[0], " input.vcf output.vcf [debug.log]\n";
+ echo "Usage: ", $argv[0], " input.vcf output.vcf [debug.log]\n";
die(1);
+
}
$input = fopen($argv[1], 'r');
@@ -40,72 +42,83 @@ $splitter = new Splitter\VCard($input);
// but not in others, we don't consider them for the sake of finding
// differences.
$ignoredProperties = [
- 'PRODID',
- 'VERSION',
- 'REV',
- 'UID',
- 'X-ABLABEL',
+ "PRODID",
+ "VERSION",
+ "REV",
+ "UID",
+ "X-ABLABEL",
];
+
$collectedNames = [];
$stats = [
- 'Total vcards' => 0,
- 'No FN property' => 0,
- 'Ignored duplicates' => 0,
- 'Merged values' => 0,
- 'Error' => 0,
- 'Unique cards' => 0,
- 'Total written' => 0,
+ "Total vcards" => 0,
+ "No FN property" => 0,
+ "Ignored duplicates" => 0,
+ "Merged values" => 0,
+ "Error" => 0,
+ "Unique cards" => 0,
+ "Total written" => 0,
];
-function writeStats()
-{
+function writeStats() {
+
global $stats;
foreach ($stats as $name => $value) {
- echo str_pad($name, 23, ' ', STR_PAD_RIGHT), str_pad($value, 6, ' ', STR_PAD_LEFT), "\n";
+ echo str_pad($name, 23, " ", STR_PAD_RIGHT), str_pad($value, 6, " ", STR_PAD_LEFT), "\n";
}
// Moving cursor back a few lines.
- echo "\033[".count($stats).'A';
+ echo "\033[" . count($stats) . "A";
+
}
-function write($vcard)
-{
+function write($vcard) {
+
global $stats, $output;
- ++$stats['Total written'];
- fwrite($output, $vcard->serialize()."\n");
+ $stats["Total written"]++;
+ fwrite($output, $vcard->serialize() . "\n");
+
}
while ($vcard = $splitter->getNext()) {
- ++$stats['Total vcards'];
+
+ $stats["Total vcards"]++;
writeStats();
- $fn = isset($vcard->FN) ? (string) $vcard->FN : null;
+ $fn = isset($vcard->FN) ? (string)$vcard->FN : null;
if (empty($fn)) {
+
// Immediately write this vcard, we don't compare it.
- ++$stats['No FN property'];
- ++$stats['Unique cards'];
+ $stats["No FN property"]++;
+ $stats['Unique cards']++;
write($vcard);
$vcard->destroy();
continue;
+
}
if (!isset($collectedNames[$fn])) {
+
$collectedNames[$fn] = $vcard;
- ++$stats['Unique cards'];
+ $stats['Unique cards']++;
continue;
+
} else {
+
// Starting comparison for all properties. We only check if properties
// in the current vcard exactly appear in the earlier vcard as well.
foreach ($vcard->children() as $newProp) {
+
if (in_array($newProp->name, $ignoredProperties)) {
// We don't care about properties such as UID and REV.
continue;
}
$ok = false;
foreach ($collectedNames[$fn]->select($newProp->name) as $compareProp) {
+
if ($compareProp->serialize() === $newProp->serialize()) {
$ok = true;
break;
@@ -113,11 +126,14 @@ while ($vcard = $splitter->getNext()) {
}
if (!$ok) {
- if ('EMAIL' === $newProp->name || 'TEL' === $newProp->name) {
+
+ if ($newProp->name === 'EMAIL' || $newProp->name === 'TEL') {
+
// We're going to make another attempt to find this
// property, this time just by value. If we find it, we
// consider it a success.
foreach ($collectedNames[$fn]->select($newProp->name) as $compareProp) {
+
if ($compareProp->getValue() === $newProp->getValue()) {
$ok = true;
break;
@@ -125,36 +141,44 @@ while ($vcard = $splitter->getNext()) {
}
if (!$ok) {
+
// Merging the new value in the old vcard.
$collectedNames[$fn]->add(clone $newProp);
$ok = true;
- ++$stats['Merged values'];
+ $stats['Merged values']++;
+
}
+
}
+
}
if (!$ok) {
- // echo $newProp->serialize() . " does not appear in earlier vcard!\n";
- ++$stats['Error'];
- if ($debug) {
- fwrite($debug, "Missing '".$newProp->name."' property in duplicate. Earlier vcard:\n".$collectedNames[$fn]->serialize()."\n\nLater:\n".$vcard->serialize()."\n\n");
- }
+ // echo $newProp->serialize() . " does not appear in earlier vcard!\n";
+ $stats['Error']++;
+ if ($debug) fwrite($debug, "Missing '" . $newProp->name . "' property in duplicate. Earlier vcard:\n" . $collectedNames[$fn]->serialize() . "\n\nLater:\n" . $vcard->serialize() . "\n\n");
+
$vcard->destroy();
continue 2;
}
+
}
+
}
$vcard->destroy();
- ++$stats['Ignored duplicates'];
+ $stats['Ignored duplicates']++;
+
}
foreach ($collectedNames as $vcard) {
+
// Overwriting any old PRODID
- $vcard->PRODID = '-//Sabre//Sabre VObject '.Version::VERSION.'//EN';
+ $vcard->PRODID = '-//Sabre//Sabre VObject ' . Version::VERSION . '//EN';
write($vcard);
writeStats();
+
}
echo str_repeat("\n", count($stats)), "\nDone.\n";