-
Notifications
You must be signed in to change notification settings - Fork 33
Update the code to not use trigger error or error log in production #208
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
DenisFlorin
wants to merge
1
commit into
master
Choose a base branch
from
fix-warnings-related-to-errors-logs-from-PCP
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -21,61 +21,73 @@ | |||||
| * @package Gitium | ||||||
| */ | ||||||
|
|
||||||
| header( 'Content-Type: text/html' ); | ||||||
| define( 'SHORTINIT', true ); | ||||||
|
|
||||||
| $current_dir = __DIR__; | ||||||
|
|
||||||
| // Define an array of possible WordPress root locations | ||||||
| $try_wp_roots = [ | ||||||
| getenv('DOCUMENT_ROOT'), | ||||||
| filter_input(INPUT_SERVER, 'DOCUMENT_ROOT', FILTER_SANITIZE_FULL_SPECIAL_CHARS), | ||||||
| realpath($current_dir . '/../../../../../'), | ||||||
| realpath($current_dir . '/../../../../'), | ||||||
| realpath($current_dir . '/../../../'), // Typical WordPress structure | ||||||
| realpath($current_dir . '/../../'), // Alternative structure | ||||||
| realpath($current_dir . '/../'), // Closer parent directory | ||||||
| $current_dir, // Fallback to current directory | ||||||
| ]; | ||||||
|
|
||||||
| $wordpress_loader = null; | ||||||
|
|
||||||
| foreach ($try_wp_roots as $root) { | ||||||
| if ($root && file_exists($root . '/wp-load.php')) { | ||||||
| $wordpress_loader = $root . '/wp-load.php'; | ||||||
| break; | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| if ($wordpress_loader) { | ||||||
| require_once $wordpress_loader; | ||||||
| } else { | ||||||
| die('Error: Unable to locate wp-load.php. Please verify your WordPress installation.'); | ||||||
| } | ||||||
|
|
||||||
| require_once __DIR__ . '/functions.php'; | ||||||
| require_once __DIR__ . '/inc/class-git-wrapper.php'; | ||||||
|
|
||||||
| $webhook_key = get_option( 'gitium_webhook_key', '' ); | ||||||
| $get_key = filter_input(INPUT_GET, 'key', FILTER_SANITIZE_FULL_SPECIAL_CHARS); | ||||||
| if ( ! empty ( $webhook_key ) && isset( $get_key ) && $webhook_key == $get_key ) : | ||||||
| ( '1.7' <= substr( $git->get_version(), 0, 3 ) ) or wp_die( 'Gitium plugin require minimum `git version 1.7`!' ); | ||||||
|
|
||||||
| list( $git_public_key, $git_private_key ) = gitium_get_keypair(); | ||||||
| if ( ! $git_public_key || ! $git_private_key ) | ||||||
| wp_die('Not ready.', 'Not ready.', array( 'response' => 403 )); | ||||||
| else | ||||||
| $git->set_key( $git_private_key ); | ||||||
|
|
||||||
| $commits = array(); | ||||||
| $commitmsg = sprintf( 'Merged changes from %s on %s', $_SERVER['SERVER_NAME'], date( 'm.d.Y' ) ); | ||||||
|
|
||||||
| if ( $git->is_dirty() && $git->add() > 0 ) { | ||||||
| $commits[] = $git->commit( $commitmsg ) or trigger_error( 'Could not commit local changes!', E_USER_ERROR ); | ||||||
| } | ||||||
| gitium_merge_and_push( $commits ) or trigger_error( 'Failed merge & push: ' . serialize( $git->get_last_error() ), E_USER_ERROR ); | ||||||
|
|
||||||
| wp_die( $commitmsg , 'Pull done!', array( 'response' => 200 ) ); | ||||||
| else : | ||||||
| wp_die( 'Cheating uh?', 'Cheating uh?', array( 'response' => 403 ) ); | ||||||
| endif; | ||||||
| header( 'Content-Type: text/html' ); | ||||||
| define( 'SHORTINIT', true ); | ||||||
|
|
||||||
| $current_dir = __DIR__; | ||||||
|
|
||||||
| // Define possible WordPress root locations | ||||||
| $try_wp_roots = [ | ||||||
| getenv( 'DOCUMENT_ROOT' ), | ||||||
| filter_input( INPUT_SERVER, 'DOCUMENT_ROOT', FILTER_SANITIZE_FULL_SPECIAL_CHARS ), | ||||||
| realpath( $current_dir . '/../../../../../' ), | ||||||
| realpath( $current_dir . '/../../../../' ), | ||||||
| realpath( $current_dir . '/../../../' ), | ||||||
| realpath( $current_dir . '/../../' ), | ||||||
| realpath( $current_dir . '/../' ), | ||||||
| $current_dir, | ||||||
| ]; | ||||||
|
|
||||||
| $wordpress_loader = null; | ||||||
| foreach ( $try_wp_roots as $root ) { | ||||||
| if ( $root && file_exists( $root . '/wp-load.php' ) ) { | ||||||
| $wordpress_loader = $root . '/wp-load.php'; | ||||||
| break; | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| if ( $wordpress_loader ) { | ||||||
| require_once $wordpress_loader; | ||||||
| } else { | ||||||
| wp_die( 'Error: Unable to locate wp-load.php. Please verify your WordPress installation.', 'Gitium Error', [ 'response' => 500 ] ); | ||||||
| } | ||||||
|
|
||||||
| require_once __DIR__ . '/functions.php'; | ||||||
| require_once __DIR__ . '/inc/class-git-wrapper.php'; | ||||||
|
|
||||||
| $webhook_key = get_option( 'gitium_webhook_key', '' ); | ||||||
| $get_key = filter_input( INPUT_GET, 'key', FILTER_SANITIZE_FULL_SPECIAL_CHARS ); | ||||||
|
|
||||||
| if ( empty( $webhook_key ) || $get_key !== $webhook_key ) { | ||||||
| wp_die( 'Cheating uh?', 'Gitium Error', [ 'response' => 403 ] ); | ||||||
| } | ||||||
|
|
||||||
| if ( version_compare( $git->get_version(), '1.7', '<' ) ) { | ||||||
| wp_die( 'Gitium plugin requires minimum git version 1.7.', 'Gitium Error', [ 'response' => 500 ] ); | ||||||
| } | ||||||
|
|
||||||
| // Load keypair | ||||||
| list( $git_public_key, $git_private_key ) = gitium_get_keypair(); | ||||||
| if ( ! $git_public_key || ! $git_private_key ) { | ||||||
| wp_die( 'Gitium is not ready. SSH keys are missing.', 'Gitium Error', [ 'response' => 403 ] ); | ||||||
| } | ||||||
|
|
||||||
| $git->set_key( $git_private_key ); | ||||||
|
|
||||||
| $commitmsg = sprintf( 'Merged changes from %s on %s', $_SERVER['SERVER_NAME'], date( 'm.d.Y' ) ); | ||||||
| $commits = []; | ||||||
|
|
||||||
| if ( $git->is_dirty() && $git->add() > 0 ) { | ||||||
| $commit = $git->commit( $commitmsg ); | ||||||
| if ( ! $commit ) { | ||||||
| wp_die( 'Error: Could not commit local changes.', 'Gitium Error', [ 'response' => 500 ] ); | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| } | ||||||
| $commits[] = $commit; | ||||||
| } | ||||||
|
|
||||||
| if ( ! gitium_merge_and_push( $commits ) ) { | ||||||
| $error = $git->get_last_error(); | ||||||
| wp_die( 'Error: Merge & push failed. ' . ( is_string( $error ) ? $error : '' ), 'Gitium Error', [ 'response' => 500 ] ); | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| } | ||||||
|
|
||||||
| wp_die( esc_html( $commitmsg ), 'Pull done!', [ 'response' => 200 ] ); | ||||||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like the indentation is inconsistent.