Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions HumanFormat.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,13 @@ class HumanFormat {
public static function toHumanReadableString($item) {
$itemFile = '--- ' . $item->title . ' ---' . "\n";
$itemFile .= 'Item ID: ' . $item->item_id . "\n";
$itemImages = array();
if ($item instanceof PodioItem) {
foreach ($item->fields as $field) {
if ($field instanceof PodioItemField) {
if($field instanceof PodioImageItemField) {
$itemImages = $field->values;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here should be something like array_merge to account for multiple image fields in one item.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are probably correct, I will have to spin up an organization to test that out, since I only have one image field.

$itemFile .= $field->label . ': ' . HumanFormat::getFieldValue($field) . "\n";
} elseif ($field instanceof PodioItemField) {
$itemFile .= $field->label . ': ' . HumanFormat::getFieldValue($field) . "\n";
} else {
echo "WARN non PodioItemField:";
Expand All @@ -38,7 +42,7 @@ public static function toHumanReadableString($item) {
}
}
$itemFile .= "\n";
return $itemFile;
return array($itemFile, $itemImages);
}

/**
Expand Down
22 changes: 19 additions & 3 deletions podio_backup_full_cli.php
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,8 @@ function backup_app($app, $path, $downloadFiles) {

foreach ($allitems as $item) {

// print_r($item);

if ($verbose)
echo " - " . $item->title . "\n";

Expand All @@ -223,7 +225,7 @@ function backup_app($app, $path, $downloadFiles) {

unset($itemFile);

$itemFile = HumanFormat::toHumanReadableString($item);
list($itemFile, $itemImages) = HumanFormat::toHumanReadableString($item);

if ($downloadFiles) {
foreach ($appFiles as $file) {
Expand All @@ -240,6 +242,19 @@ function backup_app($app, $path, $downloadFiles) {
}
}

/* */
if (sizeof($itemImages) > 0){
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be inside the above if($downloadFiles) - shouldn't it`?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't believe so, since you could have image field(s) without files to download.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok

foreach ($itemImages as $file){
$link = downloadFileIfHostedAtPodio($path_item, $file);
if (!preg_match("/^http/i", $link)) {
$link = RelativePaths::getRelativePath($path_app, $path_item . '/' . $link);
}
$itemFile .= "Image: $link\n";
$files_in_app_html .= "<tr><td>" . $file->name . "</td><td><a href=\"" . $link . "\">" . $link . "</a></td><td>" . $file->context['title'] . "</td></tr>";
}
}
/* */

//TODO refactor to use less api calls: (not possible??!)
if ($item->comment_count > 0) {
#echo "comments.. (".$item->comment_count.")\n";
Expand Down Expand Up @@ -422,7 +437,7 @@ function contacts2text($contacts) {
function fixDirName($name) {
$name = preg_replace("/[^.a-zA-Z0-9_-]/", '', $name);

$name = substr($name, 0, 25);
// $name = substr($name, 0, 25);
return $name;
}

Expand Down Expand Up @@ -462,6 +477,7 @@ function downloadFileIfHostedAtPodio($folder, $file) {
$filename = fixDirName($file->name);
while (file_exists($folder . '/' . $filename))
$filename = 'Z' . $filename;

if (array_key_exists($file->file_id, $filestore)) {

echo "DEBUG: Detected duplicate download for file: $file->file_id\n";
Expand Down Expand Up @@ -493,4 +509,4 @@ function downloadFileIfHostedAtPodio($folder, $file) {
return $link;
}

?>
?>