Skip to content
Merged
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
6 changes: 3 additions & 3 deletions forms-bridge/addons/airtable/class-airtable-form-bridge.php
Original file line number Diff line number Diff line change
Expand Up @@ -275,15 +275,15 @@ function ( $name ) use ( $attachment_name ) {
$uploads = Forms_Bridge::attachments( FBAPI::get_uploads() );

foreach ( $attachments as $attachment ) {
$filetype = array( 'type' => 'octet/stream' );
$filetype = array( 'type' => 'application/octet-stream' );
$filename = $attachment['name'];

foreach ( $uploads as $upload_name => $path ) {
if ( $upload_name === $attachment['key'] || $upload_name === sanitize_title( $attachment['key'] ) ) {
$filename = basename( $path );
$filetype = wp_check_filetype( $path );
if ( empty( $filetype['type'] ) ) {
$filetype['type'] = mime_content_type( $path ) ?: 'octet/stream';
$filetype['type'] = mime_content_type( $path ) ?: 'application/octet-stream';
}
}
}
Expand All @@ -296,7 +296,7 @@ function ( $name ) use ( $attachment_name ) {
)->post(
"/v0/{$base_id}/{$record_id}/{$attachment['id']}/uploadAttachment",
array(
'contentType' => $filetype['type'] ?? 'octet/stream',
'contentType' => $filetype['type'] ?? 'application/octet-stream',
'file' => $attachment['file'],
'filename' => $filename,
),
Expand Down
90 changes: 47 additions & 43 deletions forms-bridge/addons/nextcloud/class-nextcloud-form-bridge.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ private function filepath( &$touched = false ) {
$uploads = Forms_Bridge::upload_dir() . '/nextcloud';

if ( ! is_dir( $uploads ) ) {
if ( ! mkdir( $uploads, 755 ) ) {
if ( ! wp_mkdir_p( $uploads, 755 ) ) {
return;
}
}
Expand Down Expand Up @@ -229,14 +229,12 @@ public function submit( $payload = array(), $attachments = array() ) {

if ( ! $backend ) {
return new WP_Error(
'invalid_bridge',
'invalid_backend',
'Bridge has no valid backend',
(array) $this->data,
);
}

$payload = self::flatten_payload( $payload );

add_filter(
'http_bridge_backend_url',
function ( $url, $backend ) {
Expand All @@ -260,62 +258,68 @@ function ( $url, $backend ) {
2
);

$filepath = $this->filepath( $touched );
if ( 'PUT' === $this->method ) {
$payload = self::flatten_payload( $payload );

if ( is_wp_error( $filepath ) ) {
return $filepath;
}
$filepath = $this->filepath( $touched );

$dav_modified = $this->get_dav_modified_date( $backend );
if ( is_wp_error( $dav_modified ) ) {
return $dav_modified;
}
if ( is_wp_error( $filepath ) ) {
return $filepath;
}

if ( ! $dav_modified ) {
$headers = $this->payload_to_headers( $payload );
$row = $this->payload_to_row( $payload );
$csv = implode( "\n", array( $headers, $row ) );
$dav_modified = $this->get_dav_modified_date( $backend );
if ( is_wp_error( $dav_modified ) ) {
return $dav_modified;
}

file_put_contents( $filepath, $csv );
$response = parent::submit( $csv );
} elseif ( $touched ) {
if ( ! $dav_modified ) {
$headers = $this->payload_to_headers( $payload );
$row = $this->payload_to_row( $payload );
$csv = implode( "\n", array( $headers, $row ) );

file_put_contents( $filepath, $csv );
$response = parent::submit( $csv );
} else {
$local_modified = filemtime( $filepath );

if ( $dav_modified > $local_modified ) {
$response = $backend->get(
$this->endpoint,
array(),
array(),
array(
'stream' => true,
'filename' => $filepath,
)
);

if ( is_wp_error( $response ) ) {
return $response;
} elseif ( $touched ) {
$headers = $this->payload_to_headers( $payload );
$row = $this->payload_to_row( $payload );
$csv = implode( "\n", array( $headers, $row ) );

file_put_contents( $filepath, $csv );
$response = parent::submit( $csv );
} else {
$local_modified = filemtime( $filepath );

if ( $dav_modified > $local_modified ) {
$response = $backend->get(
$this->endpoint,
array(),
array(),
array(
'stream' => true,
'filename' => $filepath,
)
);

if ( is_wp_error( $response ) ) {
return $response;
}
}
}

$this->add_row( $payload );
$this->add_row( $payload );

$csv = file_get_contents( $filepath );
$response = parent::submit( $csv );
}
$csv = file_get_contents( $filepath );
$response = parent::submit( $csv );
}

if ( is_wp_error( $response ) ) {
if ( is_wp_error( $response ) ) {
return $response;
}

touch( $filepath, time() );
return $response;
}

touch( $filepath, time() );
return $response;
return parent::submit( $payload );
}

/**
Expand Down
2 changes: 1 addition & 1 deletion forms-bridge/addons/nextcloud/hooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ function ( $schema, $addon ) {
);
$schema['properties']['endpoint']['pattern'] = '.+\.csv$';

$schema['properties']['method']['enum'] = array( 'PUT' );
$schema['properties']['method']['enum'] = array( 'GET', 'PUT', 'DELETE', 'MOVE', 'MKCOL', 'PROPFIND' );
$schema['properties']['method']['default'] = 'PUT';

return $schema;
Expand Down
Loading