How to globally disable doctrine auto generated fields?

Objective

I want to disable GeneratedValue of doctrine without updating the entities.

Context

I have two applications, an old one and the new version.

I’m creating a Php script to migrate the data from the old database to the new database.

On the new application there is Doctrine.

Problem

For now I copy paste all my entities each time I do a change on the new application.

But I have to change the Entities to remove the annotations for the auto generted values

* @ORMGeneratedValue

If I don’t the ID won’t be se same on the new and the old database.

For example I don’t have a user with the ID 500, so when a migrate the users the user supposed to be ID 501 will be 500.

So my first objective is to disable the auto generated, so that when I copy paste the entities I don’t have to changes things on it.

Maybe I can change the generation strategy globally ?

$isDevMode = true;
$proxyDir = null;
$cache = null;
$useSimpleAnnotationReader = false;
$config = Setup::createAnnotationMetadataConfiguration(
    [PROJECT_ROOT . "/Entities"],
    $isDevMode,
    $proxyDir,
    $cache,
    $useSimpleAnnotationReader
);


$queryCache = new ArrayAdapter();
$metadataCache = new ArrayAdapter();
$config->setAutoGenerateProxyClasses(true);


$config->setQueryCache($queryCache);
$config->setMetadataCache($metadataCache);

// database configuration parameters
$conn = [
   'url' => 'postgres://user:password@db/database?serverVersion=14.2',
];

// obtaining the entity manager
$entityManager = EntityManager::create($conn, $config);

Moodle: Attachments are not generated in HTML after course copy

I have the issue that attachments which are included in a Moodle questiontype custom plugin are not generated in HTML Template after copying the course.

All attachments are saved via “backup_qtype_…plugin.class.php” and restored via “restore_qtype…_plugin.class.php”. The attachments are also visible in the copied course but to make them visible in the answer attempt I need to manually open the question settings and just press save before someone tries to solve it.

Restore file:

<?php

defined('MOODLE_INTERNAL') || die();

class restore_qtype_qtype_name_plugin extends restore_qtype_plugin
{

    /**
     * Returns the paths to be handled by the plugin at question level
     */
    protected function define_question_plugin_structure()
    {
        return array(
            new restore_path_element('name', $this->get_pathfor('/name'))
        );
    }

    public function process_name($data)
    {
        global $DB;

        $data = (object)$data;
        $oldid = $data->id;

        // Detect if the question is created or mapped.
        $questioncreated = $this->get_mappingid(
            'question_created',
            $this->get_old_parentid('question')
        ) ? true : false;

        if ($questioncreated) {
            $data->question = $this->get_new_parentid('question');
            $newitemid = $DB->insert_record('qtype_options', $data);
            $this->set_mapping('qtype_options', $oldid, $newitemid);
        }
    }

    // Return the contents of the questions stuff that must be processed by the links decoder
    static public function define_plugin_decode_contents()
    {

        $contents = array();

        $contents[] = new restore_decode_content('qtype_options', 'attachment_1', 'qtype_name');
        $contents[] = new restore_decode_content('qtype_options', 'attachment_2', 'qtype_name');

        return $contents;
    }

I believe that the issue could be either on:

  1. backupmoodle2restore… — That I’m just missing the function that renders attachments (pdf files)
  2. edit_form — the function data_preprocessing is only triggert with pressing on the save button. Therefor it is not possible to include attachment files in exam directly after copying the course.

Has anyone an idea where my error lies or could anyone confirm that my guess is correct and it is simple not possible to add an attachment file directly after copying the course without saving the settings first.

Thank you very much beforehand!

Greetings,
Eduard

cannot modify header information – headers already sent by wordpress plugin

I am creating a gateway plugin but I get this error:

Cannot modify header information – headers already sent by (output started at C:xampp4htdocsmahakwp-includesclass.wp-styles.php:214) in C:xampp4htdocsmahakwp-contentpluginssoolefrontform.php on line 44

and this is my code:

<?php
function soole_form_shortcode(){
    if ( isset( $_GET['status'] ) ){
        require plugin_dir_path( __DIR__ ). '/gateways/payir/verify.php';
    }
 
 
   $form_page = get_option( 'soole_payment_thankyou_page' ); 


    $content = '<form action="#" method="post">';

        $content .= '<label for="gateway-zarrin">زرین پال</label>';
        $content .= '<input type="radio" name="gateway" id="gateway-zarrin" value="zarrin">';
        $content .= '<br />';
        $content .= '<label for="gateway-payir">پی آی آر</label>';
        $content .= '<input type="radio" name="gateway" id="gateway-payir" value="payir">';
        $content .= '<br />';
        $content .= '<input type="submit" name="submit" value="submit">';

    $content .= '</form>';
    
    return $content;
    ob_end_clean();


}
add_shortcode( 'soole_form', 'soole_form_shortcode' );

function soole_redirect_form_to_gateway(){
 
    if ( isset( $_POST['submit'] ) ){
        ob_start();
        $api = 'test';
        $amount = "20000";
        $mobile = "09928615088";
        $factorNumber = "286542";
        $description = "توضیحات";
        $redirect = 'http://localhost/mahak/soole-form/';
        $result = send($api, $amount, $redirect, $mobile, $factorNumber, $description);
        $result = json_decode($result);
        if($result->status) {
            $go = "https://pay.ir/pg/$result->token";
            header("Location: $go");
        } else {
            echo $result->errorMessage;
        }
    
    }

}



add_action ( 'wp_head', 'soole_redirect_form_to_gateway' );

I appreciate all your helps.

Can’t verify Apple Server Notification JWT Token

I’m trying to validate an Apple Server Notification V2 (Sandbox) with a php library:
https://github.com/web-token/jwt-framework

Based on the documentation: https://web-token.spomky-labs.com/v/v2.x/the-components/signed-tokens-jws/jws-loading I thought this should do the job:

$jwt = 'eyJh...';
$jwk = JWKFactory::createFromCertificateFile('AppleRootCA-G3.cer');

$algorithmManager = new AlgorithmManager([
    new ES256(),
]);

$jwsVerifier = new JWSVerifier(
    $algorithmManager
);

$serializerManager = new JWSSerializerManager([
    new CompactSerializer(),
]);

$jws = $serializerManager->unserialize($jwt);
$isVerified = $jwsVerifier->verifyWithKey($jws, $jwk, 0);

Still it doesn’t receive a positive verification. I’ve debugged it onto this point:

$result = openssl_verify($input, $der, $pem, $this->getHashAlgorithm());

Which will give false but no content in openssl_error_string()

Any suggestions?

Query SQLite3 file inside zip without extracting PHP

I’m trying to query a sqlite file that’s still inside a zip archive with PHP.

The reason is… The sqlite file when zipped is around ~16MB, but when extracted its ~150MB+, as its a large file my server sometimes times out during the unzipping, i can’t change any settings to increase the timeout.

I normally query the sqlite file (when extracted manually) like this…

$myPDO = new PDO('sqlite:/home/u756412721/public_html/manifest/manifest.sqlite');

I’ve tried the following but its not working with the .sqlite file, i did a simply echo $str; to confirm its getting the file content but my thoughts are the file_get_content command is messing up the .sqlite file format/hierarchy somehow meaning the new PDO() can’t understand it??

$str = file_get_contents('zip://../manifest.zip#manifest.sqlite');

$myPDO = new PDO($str);

Anyone be able to shed some light on what might solve this?

Thanks.

Can anyone solve this problem using python? [closed]

Body:
In Georgia the currency is made up of Lari (₾) and Tetri (თ).
In the common circulation there are only 8 coins:
1თ, 2თ, 5თ, 10თ, 20თ, 50თ, 1₾ (100თ), and 2₾ (200თ).
Are there any achievable methods to make 2₾ with other coins, for example
like this:
1×1₾ + 2×50თ = 2₾

Question :
Find number of the ways 2₾ can be made by using as much coins as you want, but there is one restriction: You cannot permutate the combinations.

how to hide the div card if API data is empty

Hi everyone i am trying to get Data from Api ,some of them will display empty means there is not any data right but the div card still displaying so i am here to seek for help which i want to hide the div card if it is empty

function getRoom($room){
        $rooms= array();
        $img = "";
        $name = "";
        $description = "";

        $rooms['img'] = $img;
        $rooms['name'] = $name;
        $rooms['description'] = $description;
        $rooms['address'] = $address;

return $rooms;
}


function getRoomCard($room){
        if (empty($room)){
            echo "No trace currently found";
          }
       
        return "
        <div class='col-md m-1'>
            <div class='card h-100'>
                <img class='card-img-top' src='{$room['img']}' alt='Card image cap' style='width:100%;height:180px;background-size: cover;'>
        
                <div class='card-body'>            
                    <h3 class='card-title'>{$room['name']}</h3>
                    <h5='card-text description'>description : {$room['description ']}</h5>
                    <h5='card-text description'>Address: {$room['address']}</h5>
                </div>
        
            </div>
        </div>
        
        ";  
  
    }

Download Video File in URL

how i code to download the video from the link below through PHP

https://v16m-default.akamaized.net/4cfd82fef0629a3002b526cffa88547b/62e2a024/video/tos/useast2a/tos-useast2a-pve-0037-aiso/4835c05581904f6f83c8a06cdb8f068d/?a=0&ch=0&cr=0&dr=0&lr=all&cd=0%7C0%7C0%7C0&cv=1&br=2026&bt=1013&btag=80000&cs=0&ds=3&ft=ArCXsBnZqi2mo0PemccfkVQnNk6bHKJ&mime_type=video_mp4&qs=0&rc=ZmQ1NzY5ZDg3OzpkNjlnNkBpajRnaDk6ZnBqZDMzZjczM0BfNGEtYDYwXl8xLWMyMDUtYSNsaGBvcjRvbHFgLS1kMWNzcw%3D%3D&l=202207280840440102230791570104033E

WordPress: redirecting to the form page after form submission to admin-post.php

I created my first WordPress plugin (I have a lot of coding experience, but that comes from the embedded software world).
It includes a form, presented on the front end.
To process the form entries, I added an action that addresses admin-post.php:

<form action="<?php echo esc_attr( admin_url( 'admin-post.php' ) ); ?>" method="post"> 

I added hooks for logged-in and non-logged-in users to evaluate the submitted form.

add_action( 'admin_post_no1_remember_form_response', array( $this, 'no1_evaluate_remember_form' ) );
add_action( 'admin_post_nopriv_no1_remember_form_response', array( $this, 'no1_evaluate_remember_form' ) );

After doing some checking, securing and processing of the form-data, I want to go back to the page where the form was, but showing some success message instead of the form. That works fine but I can not figure out (though I googled a lot), how to redirect to the page where the form was submitted.
In my dev-environemnt I used the wp_redirect function with a hard coded path:

wp_redirect(
    esc_url_raw(
        add_query_arg(
            array(
                'info'     => $form_eva_result,
                'response' => $_POST,
            ),
            home_url( 'index.php/test-shortcode-no1/' )  
        )
    )
);
exit;

That works fine, but since I want to place the form (via a shortcode) on any page I need to find a way to retrieve the correct URL for the page where the form was submitted.
I understand that using AJAX to submit the form data might be an option, but for now I would like to stick with the POST method (also for educational purposes 🙂 )

Can any one suggest a way to retrieve the correct redirect target?

Thanks, Christian

how to use where which is in foreach in laravel blade

how to use where which is in foreach in laravel blade, i want to display only data with status true

I’ve tried using where in several positions in foreach but still getting error

    @foreach ($getfab as $tes)
        <div class="container">
            {{ $tes->listfab->Name }} |
            {{ $tes->listfab->Status }}
            <br><br>
        </div>
    @endforeach


    public function product_detail($id){
     
        $getfab = ProductItem::where('FrameCode',$list->FrameCode)
        ->with('listfab')->get();

        return view('frontend/products/product-detail',compact(''getfab'));
    }

    class FabricList extends Model
{
    use HasFactory;
    protected $table = "t_fabric_list";

    public function itemfab(){
        return $this->hasMany(ProductItem::class, 'Code', 'FabricCode');
    }

}

thanks

Woocommerce changing title on shop depending on variables

I’m trying changing titles on WordPress Woocommerce shop page depends on which variation I’m using.

I’ve found one solution which works perfectly on product pages. I’m stuck now and need to change a little bit the code that will work on shop page too.

Here is the code for the product page:

https://wordpress.org/support/topic/how-to-make-the-title-of-the-product-change-when-choosing-specific-variation/

It works perfectly, you can check the working code here:
http://tattodivi.nhely.hu/product/flower-lily/

I need one more solution which works on Woocommerce shop page too in this link:
http://tattodivi.nhely.hu/

If any of you can help me on this let me know.
Thanks.

i have a problem about looping sequential

i have targeted to solve this problem but i am stuck till now using php
this case iterates sequentially to get time or date range (dataset)

data collection
$array = array(‘2021-06-12’, ‘2021-07-14’, ‘2022-08-05’, ‘2022-09-20’);
$single_array = array();

what I want like this is different
first iteration = date difference 2021-06-12 2021-07-14 = result (push to single_array)
next loop = 2022-08-05 date difference 2022-09-20 = result (push to single_array again)

and the next process will show the results when the array has been collected into a single array before to get the most average.

Symfony 4 Regex, find a pattern that excludes email check from url check

I have a Symfony form that has fields that should let users write emails but not URLs.
I am currently using this regex:

return new Regex(
        [
            'pattern' => '((http|https|ftp|ftps)://)?([a-zA-Z0-9-]*.)+[a-zA-Z0-9]{2,4}(/[a-zA-Z0-9=.?&-]*)?',
            'match'   => false,
            'message' => $this->translator->trans('form.field.urlNotAllowed', ['%label%' => $label])
        ]
    );

This regex matches all URLs, but also match emails for validation.
What I want to do is excluding emails from validation and match only URLs.

My code:

/**
 * @param RegistrationFormField $field
 * @param string $key
 * @param array $validationAttributes
 * @return Regex
 */
public function getUrlNotAllowedConstraint($field, $key, &$validationAttributes)
{
    $event = $field->getRegistrationForm()->getEvent();

    $label = /** @Ignore */
    $this->translator->trans($field->getLabel(), [], 'custom') ?: $this->getDefaultLabelName($event, $key);
    
    $validationAttributes['data-validation'][] = 'url_not_allowed';

    return new Regex(
        [
            'pattern' => '((http|https|ftp|ftps)://)?([a-zA-Z0-9-]*.)+[a-zA-Z0-9]{2,4}(/[a-zA-Z0-9=.?&-]*)?',
            'match'   => false,
            'message' => $this->translator->trans('form.field.urlNotAllowed', ['%label%' => $label])
        ]
    );
}

Any help?

Woocommerce update card total tax – woocommerce_after_calculate_totals

Within my shop I had to adjust the calculation of the total cart value which was successfull. For this task I used add_action( 'woocommerce_after_calculate_totals', 'custom_woocommerce_after_calculate_totals', 30 );.

After my calculations I get for example a price of 167,74€ which includes 27,951… VAT (20%).
Now I have the problem that VAT calculation is wrong after a few digits.
The correct result should be 27,956… => rounded up to 27,96. Which results in a cent difference.

Because of the wrong value I tried to do my own calculation by “reverse engineering” the tax rate and calculating the tax_total on my own.

My calculation:

add_action( 'woocommerce_after_calculate_totals', 'custom_woocommerce_after_calculate_totals', 30 );

function custom_woocommerce_after_calculate_totals( $cart ) {

    $subtotal = 0.0;
    /* Get cart items */
    $items = $cart->cart_contents;

    $do_one_time = 0;
    foreach ($items as $key => $item) {
    
        // Reverse engineer the tax rate because Woocommerce lacks a get rate method on the cart
        if($item['line_total'] && $item['line_tax']){
            if($do_one_time < 1){
                $the_cost = $item['line_total'];
                $the_tax = $item['line_tax'];
                $tax_rate = round(ceil(($the_tax / $the_cost)*1000)/1000,2);
                $do_one_time++;
            }
        }
        /* Calculate cart total value */
        if($item["line_subtotal"]){
            /* manually add up the cart item subtotal value and round it by 2 digits */
            $number = round($item["line_subtotal"], 2);
            $subtotal += $number;
        }

    }
    /* If shipping is set add it to subtotal value otherwise keep the already calculated subtotal*/
    if($cart->shipping_total){
        $subtotal_with_shipping = $cart->shipping_total + $subtotal;
        $subtotal_tax = $subtotal_with_shipping * $tax_rate;
        $total_cost = round($subtotal_with_shipping + $subtotal_tax, 2);
    }else{
        $subtotal_tax = $subtotal * $tax_rate;
        $total_cost = round($subtotal + $subtotal_tax, 2);
    }


    /* Compare cart total value with pre-calculated total value by woocommerce */
    /* If a difference within the values is present we update the total value with our own total value => $total_cost */

    if($subtotal !== $cart->subtotal_ex_tax){
        $cart->total = $total_cost;
    }    
    /* part which is not working */
    if($subtotal_tax !== $cart->tax_total){
        $cart->tax_total = $subtotal_tax;
    }

}

Within my $subtotal_tax I have the correct value of 27,96€ but I can´t find a way to update the value.

For the total value I set the $cart->total = $total_cost; which worked fine.
I tried the same for the total tax with $cart->tax_total = $subtotal_tax; but I won´t change the value.

Is there some way to update the tax_total wihthin the woocommerce_after_calculate_totals action?