Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
5d0c502
feat: create new contract for dealing with files.
eddiesshop Dec 1, 2021
203bb0c
feat: create new contract for dealing with a file with iterable data.
eddiesshop Dec 1, 2021
03bc0e2
feat: abstract implementations for dealing with files and iterable files
eddiesshop Dec 1, 2021
3fabfda
feat: interface for additional functionality for CSV files
eddiesshop Dec 1, 2021
9bae934
feat: defining concrete implementations for handling CSV and JSON files
eddiesshop Dec 1, 2021
3504f88
feat: factory to facilitate obtaining File object
eddiesshop Dec 1, 2021
7a36288
feat: creating custom callback implementations.
eddiesshop Dec 1, 2021
d9949e7
feat: new listings importer focusing on callbacks
eddiesshop Dec 1, 2021
7344fe0
feat: Newspack Listings Type pseudo enum class.
eddiesshop Jan 16, 2022
02aa909
feat: Newspack Listings Import Mode pseudo enum class.
eddiesshop Jan 16, 2022
429890c
feat: Newspack Listings Mapper for custom listing types.
eddiesshop Jan 16, 2022
546d96f
feat: Newspack Listings import mode.
eddiesshop Jan 16, 2022
7c01ca8
feat: defining docblocks for Abstract Pre/Post Create Callable classes.
eddiesshop Jan 16, 2022
7ecf009
feat: various refactors.
eddiesshop Jan 16, 2022
e340e22
feat: first commit of HTML templates for Place Newspack Listing.
eddiesshop Jan 16, 2022
b61841a
feat: creating Marketplace_Type pseudo enum class.
eddiesshop Jan 20, 2022
47f7260
feat: stock Newspack Listings Templates
eddiesshop Jan 20, 2022
a7a705d
feat: refactoring $listings_params_map & allowing for template override.
eddiesshop Jan 20, 2022
b378a1e
feat: renaming places template folder to place.
eddiesshop Jan 20, 2022
4f47bfb
feat: correcting naming reference.
eddiesshop Jan 20, 2022
9465482
feat: adding the capability to add categories, and child categories.
eddiesshop Feb 1, 2022
d7e4c6a
feat: ensuring that the row can be mutable.
eddiesshop Feb 1, 2022
f4cc2f7
feat: cleaning up spacing.
eddiesshop Feb 1, 2022
b255087
feat: adding some helpful logging.
eddiesshop Feb 2, 2022
90051e6
feat: allow/enable upload even if URL is provided.
eddiesshop Feb 2, 2022
f292577
feat: was missing featured image implementation for image upload path.
eddiesshop Feb 2, 2022
54f8108
feat: need to properly structure $row['images'] when CSV is provided.
eddiesshop Feb 2, 2022
ba0be97
feat: adding all the necessary files for the update.
eddiesshop Feb 2, 2022
c319357
feat: establishing callable importer as the standard importer.
eddiesshop Feb 2, 2022
8895d9e
Merge branch 'master' into add/new-listings-importer
dkoo Apr 18, 2022
9637d5b
fix: update file path for importer utils
dkoo Apr 18, 2022
c9f278c
fix: update file path for legacy importer
dkoo Apr 18, 2022
0ed9ca6
feat: necessary changes after some testing.
eddiesshop Sep 27, 2022
b3d14e7
feat: With the custom input structure for callables, this should be c…
eddiesshop Jan 30, 2023
8c9f014
feat: corrects that behavior of not downloading image name with spaces.
eddiesshop Jan 30, 2023
7590a89
feat: sets the featured image '_thumbnail_id' for a listing.
eddiesshop Jan 30, 2023
8f5a6af
feat: if a custom template is provided, brackets are added to keys.
eddiesshop Jan 30, 2023
d7e4f38
feat: code sniffing fixes
eddiesshop Jan 30, 2023
174df2e
feat: fixing some bugs and oversight when initially working on this code
eddiesshop Apr 18, 2023
08cee95
feat: fixing bug where input param was expecting wrong param name.
eddiesshop Apr 23, 2023
c320462
fix: removing use of deprecated function `get_page_by_title`
eddiesshop Apr 23, 2023
c8ecd3d
fix: updating query to disambiguate column in constraint
eddiesshop Sep 12, 2023
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
42 changes: 42 additions & 0 deletions includes/importer/class-abstract-callable-post-create.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php
/**
* Custom implementation which provides a mechanism for users to tie into the Newspack Listings Import process.
*
* @package Newspack_Listings.
*/

namespace Newspack_Listings\Importer;

use Newspack_Listings\Contracts\Importer_Mode;
use WP_Post;

/**
* Abstract Class which establishes that a callable must be defined and returned.
*/
abstract class Abstract_Callable_Post_Create {

/**
* Constructor to prevent initialization.
*/
final public function __construct() {
// Prevent instantiation.
}

/**
* Abstract function, forcing the child class to create a user-defined function.
*
* @return callable
*/
abstract protected function get_callable(): callable;

/**
* Automatically execute Abstract_Callable_Post_create class when instantiated.
*
* @param WP_Post $listing Newspack Listing Post.
* @param Importer_Mode $importer_mode Newspack Listing Import Mode.
* @param array $row Row of data from import file.
*/
public function __invoke( WP_Post $listing, Importer_Mode $importer_mode, array $row = [] ) {
$this->get_callable()( $listing, $importer_mode, $row );
}
}
40 changes: 40 additions & 0 deletions includes/importer/class-abstract-callable-pre-create.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php
/**
* Custom implementation which provides a mechanism for users to tie into the Newspack Listings Import process.
*
* @package Newspack_Listings.
*/

namespace Newspack_Listings\Importer;

use Newspack_Listings\Contracts\Importer_Mode;

/**
* Abstract Class which establishes that a callable must be defined and returned.
*/
abstract class Abstract_Callable_Pre_Create {

/**
* Constructor.
*/
final public function __construct() {
// Prevent instantiation.
}

/**
* Abstract function, forcing the child class to create a user-defined function.
*
* @return callable
*/
abstract protected function get_callable(): callable;

/**
* Automatically execute Abstract_Callable_Pre_Create class when instantiated.
*
* @param array $row Row of data from import file.
* @param Importer_Mode $importer_mode Newspack Listing Import Mode.
*/
public function __invoke( array &$row, Importer_Mode $importer_mode ) {
$this->get_callable()( $row, $importer_mode );
}
}
112 changes: 112 additions & 0 deletions includes/importer/class-abstract-file.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
<?php
/**
* Abstract class definition of File.
*
* @package Newspack_Listings
*/

namespace Newspack_Listings;

use Exception;

/**
* Abstract File class, handles low level loading of file and basic functions.
*/
abstract class Abstract_File implements Contracts\File {

/**
* File's full path.
*
* @var string $path
*/
protected string $path;

/**
* The file resource handle.
*
* @var resource $handle
*/
protected $handle = null;

/**
* File's name, including file extension.
*
* @var string $name
*/
protected string $name;

/**
* File's size in MB.
*
* @var int $size
*/
protected int $size;

/**
* Constructor. For now this class expects the file to exist on the system.
*
* @param string $path Full file path.
* @throws Exception If file does not exist.
*/
public function __construct( string $path ) {
if ( ! file_exists( $path ) ) {
throw new Exception( 'File does not exist!' );
}

$this->path = $path;
$parts = explode( '/', $path );
$this->name = array_pop( $parts );
$this->size = filesize( $this->path ) / 1024;
}

/**
* Returns the file's full path.
*
* @inheritDoc
*/
public function get_path(): string {
return $this->path;
}


/**
* Returns a resource stream to the open file.
*
* @return resource
*/
public function get_handle() {
if ( is_null( $this->handle ) ) {
$this->handle = fopen( $this->get_path(), 'r' );
}

return $this->handle;
}

/**
* Returns the file's name, with file extension.
*
* @inheritDoc
*/
public function get_name(): string {
return $this->name;
}

/**
* Returns the file's size, in MB.
*
* @inheritDoc
*/
public function get_size(): int {
return $this->size;
}

/**
* Destructor.
*/
public function __destruct() {
if ( is_resource( $this->handle ) ) {
// phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_read_fclose
fclose( $this->handle );
}
}
}
83 changes: 83 additions & 0 deletions includes/importer/class-abstract-iterable-file.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
<?php
/**
* Abstract implementation of Iterable_File.
*
* @package Newspack_Listings
*/

namespace Newspack_Listings;

use Exception;
use Newspack_Listings\Contracts\Iterable_File;

/**
* Abstract implementation of Iterable File contract.
*/
abstract class Abstract_Iterable_File extends Abstract_File implements Contracts\Iterable_File {

/**
* The row/line the iteration should begin at.
*
* @var int $start Default to 0 for first row/line.
*/
protected int $start = 0;

/**
* The row/line at which the iteration should terminate.
*
* @var int $end Default value max integer.
*/
protected int $end = PHP_INT_MAX;

/**
* Setter for $start.
*
* @param int $start Row/line to start iteration at.
* @returns Iterable_File
* @throws Exception Thrown if $start is greater than $end.
*/
public function set_start( int $start = 0 ): Iterable_File {
if ( $start > $this->end ) {
throw new Exception( 'Start cannot be greater than End.' );
}

$this->start = $start;

return $this;
}

/**
* Returns the integer value representing the row/line at which iteration should begin.
*
* @returns int
*/
public function get_start(): int {
return $this->start;
}

/**
* Setter for $end.
*
* @param int $end Row/line to end iteration at.
* @returns Iterable_File
* @throws Exception Thrown if $end is less than $start.
*/
public function set_end( int $end = PHP_INT_MAX ): Iterable_File {
if ( $end < $this->start ) {
throw new Exception( 'End cannot be less than Start.' );
}

$this->end = $end;

return $this;
}

/**
* Returns the integer value representing the row/line at which iteration should end.
*
* @returns integer
*/
public function get_end(): int {
return $this->end;
}
}
Loading