Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- Plugin Name: Sync Job Applicants
- Plugin URI: https://www.creatit.hu/en/
- Description: Synchronization of all applicants to the Tempus database
- Version: 1.0
- Author: Creatit Solutions
- Author URI: https://www.creatit.hu/en/
- */
- add_action('wpcf7_before_send_mail', function() {
- $submission = WPCF7_Submission::get_instance();
- insertApplicantIntoTempus([
- 'first_name' => $submission->get_posted_data('first-name'),
- 'last_name' => $submission->get_posted_data('last-name'),
- 'mobile' => $submission->get_posted_data('mobile'),
- 'email' => $submission->get_posted_data('email'),
- 'linkedin_url' => $submission->get_posted_data('linkedin-url'),
- 'cv_english' => transformFilePathToURL($submission->uploaded_files()['cv-english']),
- 'cv_hungarian' => transformFilePathToURL($submission->uploaded_files()['cv-hungarian'])
- ]);
- });
- function insertApplicantIntoTempus(array $applicant) {
- $connection = connectToTempusDatabase();
- $result = $connection->insert(
- 'jelentkezesek',
- [
- 'Vezeteknev' => $applicant['last_name'],
- 'Utonev' => $applicant['first_name'],
- 'Telefon' => $applicant['mobile'],
- 'Email' => $applicant['email'],
- 'LinkedIn_URL' => $applicant['linkedin_url'],
- 'Jelentkezes_datuma' => current_time('mysql'),
- 'Tempus_atvetel_datuma' => current_time('mysql'),
- 'CV_magyar_filenev' => $applicant['cv_hungarian'],
- 'CV_nem_magyar_filenev' => $applicant['cv_hungarian']
- ]
- );
- if (!$result) {
- error_log('Can\'t create applicant entry in Tempus database: ' . json_encode($result));
- }
- }
- function transformFilePathToURL(string $filePath) : string {
- $fileUrl = 'http://' . getenv('DOCKERAPP_WEB_DOMAIN');
- return str_replace('/srv/dockerapp/web', $fileUrl, $filePath);
- }
- function connectToTempusDatabase() {
- try {
- $connection = new wpdb(
- 'magdianyus', // getenv('TEMPUS_DATABASE_USER')
- getenv('TEMPUS_DATABASE_PASSWORD'),
- getenv('TEMPUS_DATABASE_SCHEME'),
- getenv('TEMPUS_DATABASE_HOST')
- );
- } catch (\Exception $e) {
- echo 'dded';exit;
- }
- if ($connection->show_errors()) {
- error_log('Can\'t connect to Tempus database. Check the credentials or try again later.');
- } else {
- return $connection;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement