class-dc-skroutz-feed-activator.php
1 year ago
class-dc-skroutz-feed-cli.php
1 year ago
class-dc-skroutz-feed-i18n.php
1 year ago
class-dc-skroutz-feed-loader.php
1 year ago
class-dc-skroutz-feed.php
1 year ago
dicha-skroutz-feed-create-cron.php
1 year ago
index.php
1 year ago
class-dc-skroutz-feed-cli.php
57 lines
| 1 | <?php |
| 2 | |
| 3 | if ( ! defined( 'WP_CLI' ) || ! WP_CLI ) return; |
| 4 | |
| 5 | class Dicha_Skroutz_Feed_WP_Cli { |
| 6 | |
| 7 | /** |
| 8 | * CLI command to generate the Skroutz XML file. |
| 9 | * |
| 10 | * ## OPTIONS |
| 11 | * |
| 12 | * [--type=<type>] |
| 13 | * : (Optional) The type of XML file to generate, for example "skroutz". |
| 14 | * If no type provided, the default type is "skroutz". |
| 15 | * |
| 16 | * ## EXAMPLES |
| 17 | * |
| 18 | * wp dicha-skroutz-xml generate --type=skroutz |
| 19 | * |
| 20 | * @param array $args |
| 21 | * @param array $flags |
| 22 | */ |
| 23 | public function generate( array $args, array $flags ) { |
| 24 | |
| 25 | $feed_type = $flags['type'] ?? 'skroutz'; |
| 26 | |
| 27 | $result = $this->generate_xml( $feed_type ); |
| 28 | |
| 29 | if ( $result ) { |
| 30 | WP_CLI::success( "XML file generated successfully for '$feed_type'." ); |
| 31 | } |
| 32 | else { |
| 33 | WP_CLI::error( "Failed to generate XML file." ); |
| 34 | } |
| 35 | } |
| 36 | |
| 37 | |
| 38 | /** |
| 39 | * Handles the XML file generation. |
| 40 | * |
| 41 | * @param string $feed_type The type of XML to generate. |
| 42 | * |
| 43 | * @return bool True if the XML was generated successfully, false otherwise. |
| 44 | */ |
| 45 | private function generate_xml( string $feed_type ): bool { |
| 46 | |
| 47 | $xml_creator = new Dicha_Skroutz_Feed_Creator( $feed_type ); |
| 48 | |
| 49 | return $xml_creator->create_feed(); |
| 50 | } |
| 51 | } |
| 52 | |
| 53 | |
| 54 | /** |
| 55 | * Register the main WP CLI command for our plugin. |
| 56 | */ |
| 57 | WP_CLI::add_command( 'dicha-skroutz-xml', 'Dicha_Skroutz_Feed_WP_Cli' ); |