# |
Jun 22nd 2021, 09:48 |
drashti.b.patel |
Hi everyone, I am upgrading cakephp version from 3.9 to 4.0. I am following the "https://www.cakedc.com/rafael_queiroz/2020/09/15/upgrading-to-cakephp-4" and original doc but having an issue while doing the dependency update for a composer. Please find the error given below: composer require --update-with-dependencies "cakephp/cakephp:4.0.*" ./composer.json has been updated Running composer update cakephp/cakephp |
# |
Jun 22nd 2021, 09:26 |
slackebot1 |
!empty($records)) { $this->records = Hash::extract($records, '{n}.' . $model->alias); } } } }``` May be i missed a configuration in the doc ? Or if you have a better solution than mine. Thanks :) |
# |
Jun 22nd 2021, 09:26 |
slackebot1 |
!isset($this->import['connection']) ? 'default' : $this->import['connection'] ); $db = $model->getDataSource(); $query = [ 'fields' => $db->fields($model, null, array_keys($this->fields)), 'table' => $db->fullTableName($model), 'alias' => $model->alias, ] + $recordsImportOptions; $records = $db->fetchAll($db->buildStatement($query, $model), false, $model->alias); if ($records !== false andand |
# |
Jun 22nd 2021, 09:26 |
slackebot1 |
$recordsImportOptions = $this->import['options']; $this->import['records'] = false; } parent::init(); if (!is_null($recordsImportOptions)) { list($plugin, $modelClass) = pluginSplit($this->import['model'], true); App::uses($modelClass, $plugin . 'Model'); if (!class_exists($modelClass)) { throw new MissingModelException(array('class' => $modelClass)); } $model = new $modelClass( null, null, |
# |
Jun 22nd 2021, 09:26 |
slackebot1 |
```<?php /** * Article Fixture */ class ArticleFixture extends CakeTestFixture { /** * Import * * @var array */ public $import = [ 'model' => 'Article', 'records' => false, 'options' => [ 'conditions' => ['Article.id IN' => [1, 2, 3, 4]] ] ]; public $records = []; public function init() { $recordsImportOptions = null; if (array_key_exists('options', $this->import) andand empty($this->records)) { |
# |
Jun 22nd 2021, 09:26 |
slackebot1 |
null, array_keys($this->fields)), 'table' => $db->fullTableName($model), 'alias' => $model->alias, 'conditions' => array(), 'order' => null, 'limit' => null, 'group' => null ); $records = $db->fetchAll($db->buildStatement($query, $model), false, $model->alias);``` So i create a fixture in a specific folder, and in this fixture i have overwritten the init() method. It's work but i feel it heavy if there are several fixtures involved. |
# |
Jun 22nd 2021, 09:26 |
adrienlambertwac |
[CakePhp2.10][PhpUnit3.7] Import records in Fixture Hi everyone, Do you know the best way to import specific record into fixture ? I want to test specific records with id, and just import this ones. And when i check the *init()* method in *Cake\TestSuite\Fixture\CakeTestFixture.php* the "conditions" option is initialized with empty array. ```$this->records = array(); $query = array( 'fields' => $db->fields($model, |
# |
Jun 22nd 2021, 09:02 |
etibor |
yes that would be the easier solution thank you @steinkel |
# |
Jun 22nd 2021, 08:50 |
steinkel |
`if ($person_name) { $query->where(...) }` you can check if the $person_name is null in your code and decide which condition to apply in the where |
# |
Jun 22nd 2021, 08:46 |
etibor |
```COALESCE``` ? |
# |
Jun 22nd 2021, 08:44 |
etibor |
do you have any suggest? |
# |
Jun 22nd 2021, 08:43 |
etibor |
and search for e-mail address, return the record with exact e-mail and name is null(not the other fields) |
# |
Jun 22nd 2021, 08:42 |
etibor |
just need a solution when name is null but the email is not |
# |
Jun 22nd 2021, 08:42 |
etibor |
yes i checked this in mysql its works exactly like this |
# |
Jun 22nd 2021, 08:35 |
conehead |
So what are you expecting? |
# |
Jun 22nd 2021, 08:16 |
etibor |
but in this case the rest of the filter fields does not work and return all of the records with name NULL |
# |
Jun 22nd 2021, 08:15 |
etibor |
i tried to combine with following: `->Where(['OR'=>[['People.name IS NULL'],['People.name LIKE'=>'%'.($person_name).'%']]])` |
# |
Jun 22nd 2021, 08:14 |
etibor |
sometimes People's name is null in my db |
# |
Jun 22nd 2021, 08:14 |
etibor |
i have tiny issue with using find with LIKE'=>'%'.$name.'%' because it does not work when the value is NULL `->Where(['People.name LIKE'=>'%'.($person_name).'%'])` |
# |
Jun 22nd 2021, 08:12 |
etibor |
hello everyone |
# |
Jun 22nd 2021, 07:41 |
kevin.pfeifer |
hreflang link tags improve your SEO rating https://webmasters.stackexchange.com/questions/105998/what-is-the-difference-between-html-lang-tag-and-html-hreflang-tag the html lang value is usually only there to indicate the current language of the DOM |
# |
Jun 22nd 2021, 06:56 |
slackebot1 |
Just had problems with auto correction when switching languages and was wondering if this could have anything to do with it |
# |
Jun 22nd 2021, 06:56 |
conehead |
@angelxmoreno yeh, thanks I read that already, but it somehow seemed like it does not make too much of a difference if its set to en or any other language. I know it would be a tiny "tool", but I resolved it with the following line now: ```<html lang="<?= substr(Configure::read('App.defaultLocale', 'en_EN'), 0, 2) ?>">``` And I have to admit although my mother language is german, I have never really used the lang tag as well. |
# |
Jun 22nd 2021, 06:20 |
angelxmoreno |
tbh i never set it in the 21 years i’ve been coding even back in the html4 days. my audience and language has always been the US and english..boring i know |
# |
Jun 22nd 2021, 06:18 |
angelxmoreno |
@conehead why it matters --> https://www.w3.org/International/questions/qa-html-language-declarations#langvalues what “tools” ? would you like to see? |
# |
Jun 22nd 2021, 05:32 |
conehead |
Is there actually a need/advantage to change "<html lang="en">" to the correct language? Does ist affect the page in many ways? Was just wondering cause Cake does not seem to have any tools for this? |
# |
Jun 22nd 2021, 05:32 |
conehead |
Good morning everyone! |
# |
Jun 21st 2021, 19:22 |
kevin.pfeifer |
@vinicius.big I would create a global `var MY_I18N` variable an populate it with the translations you need |
# |
Jun 21st 2021, 19:19 |
kevin.pfeifer |
what :point_up: said :) I though you had other variables outside the anonymous function which you need but accessing variables inside the class/object (you are in a Table object space here) can be done via $this without passing the via the `use` |
# |
Jun 21st 2021, 19:19 |
vinicius.big |
hey folks! What is your suggestion to translate JS strings on Cake? There is a lot of JS libraries for this but, I would like to see your experience on it |
# |
Jun 21st 2021, 19:12 |
greg138 |
As for what do do in the function, do everything that needs to be "all or nothing" saved. |
# |
Jun 21st 2021, 19:11 |
greg138 |
You should be able to access `$this` in that function without any issue, so need real need to pass in the model either (you can use `$this->Tags`). |
# |
Jun 21st 2021, 19:09 |
alamnaryab |
yes that was the issue even without return false it worked now next step @kevin.pfeifer Should I pass $this->request->getData() to this anonymous function or make separate function for each model e.g next I have to save record in notification table saying "Logged-in-user has saved new tag at id = newly-saved-Tag->id" |
# |
Jun 21st 2021, 18:59 |
greg138 |
Any chance you're using a database that just doesn't support rollback? The MyISAM engine in MySQL, for example, doesn't. |
# |
Jun 21st 2021, 18:48 |
alamnaryab |
still redirected to index and record inserted ``` $entity = $this->Tags->patchEntity($tag, $this->request->getData()); $model = $this->Tags; $this->Tags->getConnection()->transactional(function () use ($model, $entity) { $model->save($entity, ['atomic' => false]); return false; }); return $this->redirect(['action' => 'index']);``` |
# |
Jun 21st 2021, 18:46 |
greg138 |
Try returning `false` from inside your "transactional" function. |
# |
Jun 21st 2021, 18:45 |
alamnaryab |
I tried below code, I have not written `commit` still it is saved in table ``` $entity = $this->Tags->patchEntity($tag, $this->request->getData()); $model = $this->Tags; $this->Tags->getConnection()->transactional(function () use ($model, $entity) { $model->save($entity, ['atomic' => false]); }); return $this->redirect(['action' => 'index']);``` |
# |
Jun 21st 2021, 18:39 |
greg138 |
Doesn't the save code check that it's not already in a transaction before starting a transaction? |
# |
Jun 21st 2021, 18:21 |
kevin.pfeifer |
https://stackoverflow.com/questions/41896991/why-is-the-automatic-transaction-option-in-cakephp-is-called-atomic/41898090 |
# |
Jun 21st 2021, 18:21 |
kevin.pfeifer |
```->save($entity, ['atomic' => false]);``` |
# |
Jun 21st 2021, 18:21 |
kevin.pfeifer |
is the term that says that it shouldn't have a transaction |