Update CakePHP from 1.3 to 2.1

UPDATE: the question I asked does not fully reflect how deeply I am doing this update! If you stumble upon this, I hope the answer I clicked is useful to you.

So, in an attempt to get the "forum" plugin to work, I decided to update cakephp from 1.3 to 2.1

(This is due to the fact that the forum plugin uses something called CakeDC utils, and they are already before cakephp 2.0, and unexpected surprise, version 2.3 of the forum version is not clear with which it works ...)

Ok, so I ran the magic thing to improve the cake according to the instructions found here:

http://book.cakephp.org/2.0/en/console-and-shells/upgrade-shell.html#upgrade-shell

And I launched the updater, and he said that this is a bunch of things, and it looks like it's really a bunch of things.

Now, when I find my site, it doesn’t work - no answer at all.

Error logs in apache read:

[Thu Apr 05 02:58:04 2012] [error] [client 173.45.125.112] PHP Fatal error: the application file could not be found. Create / cake _install / app / config / core.php and make sure it is readable by PHP. in / cake _install / cake / libs / configure.php on line 393

The reason the file does not exist is because it was changed to a major "C" Config when updating. What am I missing?

+6
source share
4 answers

The given mensch answer is not quite what I need - I never touched the index.php file - so I will tell you in detail what I'm trying here.

I use this site as a guide, but also my own comment! http://www.paulmarshall.us/blog/migrating-from-cakephp-13-to-cakephp-20

(I also found this: https://github.com/dereuromark/upgrade , in which I could take a picture if the above tutorial fails. but I love super-exhaustive documents rather than

Put `CakePlugin::loadAll();` in your app bootstrap to make sure this plugin is loaded 

which is pointless to me ... can you specify the file folder? Any specific place in the file to add a line? etc., I will try and talk in detail about what I did!)

First of all, I noticed that the index.php that my cake used was not the index.php that came with the cake2.1 code. It is not clear why this is so, but I copied the "new" index 2.1 index.php (yes, this is the file app / webroot / index.php), and now I have a new error:

Note: Undefined index: Error / cake _install / lib / Cake / Core / Configure.php on line 94 Note: Undefined index: Exception in / cake _install / lib / Cake / Core / Configure.php on line 95 Fatal error: class name must be a valid object or line in /cake_install/lib/Cake/Error/ErrorHandler.php on line 126

(where cake_install is the folder where my cake application is located)

Work on it now ...

And now I see that the updater did not update the core.php file - in the / Config application (for 2.1, app / config for 1.3) ... what did the update tool really do? I cut and pasted version 2.1 (that is, from the zip code file 2.1, I took this file /app/Config/core.php and moved it to the / app / Config directory) and made sure that the salt and security were replaced. What is it.

Still out of luck. So, now I updated the database.php file (also in the / Config application or app / config). I changed

 'driver' => 'mysqli', 

to

 'datasource' => 'Database/Mysqli', 

Configuring files arbitrarily is fun!

Oh well, that's why upgrading to the kernel and database changed the error message ... is that good? Still not sure what their exalted “update” script did ... did it just change the file names? Really?

Warning (2): file_put_contents (/cake_install/app/tmp/logs/error.log): stream could not be opened: permission denied [CORE / Cake / Log / Engine / FileLog.php, line 69]

Note (1024): change the "Security.cipherSeed" value in the /Config/core.php application to the numeric (only digits) initial value specific to your application [CORE / Cake / Utility / Debugger.php, line 810]

Fatal error: Class 'AppHelper' not found in / cake _install / lib / Cake / View / Helper / HtmlHelper.php on line 31

Ok, so I am 777 / cake_install / app / tmp / logs / folder (chmod 777 -R folderHere) and

... I think I never updated the encryption seed. Ok, made up a new number! (What does the cipher seed do, you ask? Well, well, bing didn’t help much - I read the code. It seems to be used to encrypt / decrypt from cookies? Well, I can live with it)

Bootstrap.php

I moved the boot file to a zip file in my version (thanks a little, update the script!). Until any changes are made, I think I will need to download the plugins, though ... I'm sure this is well documented (hah!)

So this leaves me with this error:

Fatal error: Class 'AppHelper' not found in / cake _install / lib / Cake / View / Helper / HtmlHelper.php on line 31

And, of course, a qualified cake maker was not able to make another upgrade. Check out this page: http://book.cakephp.org/2.0/en/appendices/2-1-migration-guide.html

So now I have to make the files - just as they are on this page. The only trick is that yes, this is in the application folder, and no, my app / View folder created by cakePhp didn’t have a Helper subfolder ... so for AppHelper.php I had to make a helper subfolder under / app / View /.

...

HEY! Now I get the background and logo ... and these:

Note (8): Undefined variable: loggedIn [APP / pages / top_menu.html, line 3]

Note (8): Undefined variable: html [APP / pages / top_menu.html, line 25]

Fatal error: call the member function function () for the non-object in / cake _install / app / pages / top_menu.html on line 25

Great. Some cool new cake 2, which means I can't use $ html? It seems ... strangely appropriate, really.

chance. Now I need to change the way this $> data works? WHAT FOR?? WHAT FOR?? Why can't this crowd decide that apis tends to fix contracts rather than floating ideas ... argh. This is normal, the most used cake line that I have is now ... wrong. I am developing in scala or django from now on, younger languages ​​suck.

Here is what I ran: find. -type f -exec sed -i 's / $ this-> data / $ this-> request-> data / g' {} \;

I went to the / app directory to do this. This is 2.1 ... it's better to be seriously awesome ... the amount of work that everyone has to do to lift it. I suppose this is a normal day working with minor languages?

Ah, science fiction, the problem of $ html is caused by the fact that someone did not like the lowercase case? One may only wonder: Undefined var when using the Html Helper in CakePHP 2.0 And this solution: (thanks to another post in SO)

to find. -type f -exec sed -i 's / $ html / $ this-> Html / g' {} \;

And naturally the same problem with $ session -

to find. -type f -exec sed -i 's / $ session / $ this-> Session / g' {} \;

...

Things are coming! Now I have an incomprehensible error:

PagesController controller class not found.

Oh, for love ... so I need to move the PagesController found here:

Library / Cake / Console / Templates / Skel / Controller / PagesController.php

and put it here

app / Controller /

again, the Cake / updrader installer seems to be sleeping on a job.

And now I have

JavascriptHelper helper class not found.

This is not so bad - you will not find references to "JavascriptHelper", but you will find links to "Javascript" in the array "$ helpers". The inside adds the word Helper for additional obfuscation. Anyway, I searched for php files for any $ helpers arrays and found them in the AppController (2.1) class.

I don’t like and do not understand helpers - anyway, that's why I never used them. I must have been following the textbook blindly at some point and added it ... but I don't need it, so everything goes!

And now I need to clear all the ctp files that I had, where I used "require" to make sure the correct html was used. Once again I will use the find command on top to do this (point them to the View folder, not the View) Sigh. Well, no, it's not that simple, is it? Where I used to be:

required (app / View / Pages / man_front.html)

i now need:

required (/cake_folder/app/View/Pages/man_front.html)

(where the cake folder is where all my cake things are. It’s not clear why this is, but a simple find is fixed:

 find . -type f -exec sed -i 's/app\/View\/Pages/\/cake_folder\/app\/View\/Pages/g' {} \; 

(the \ will "depower" a /)

So, having done all this and getting your site at some acceptable level, what's next? Now you can find some problems with db:

Warning (2): mysqli :: mysqli () expects parameter 1 to be the string given by the array [CORE / Cake / Model / ConnectionManager.php, line 101]

Fatal error: calling the Undefined method mysqli :: getSchemaName () in / cake _install / lib / Cake / Model / Model.php on line 3383

Of course, mysqli is no longer supported. Edited database.php to use mysql instead (i.e. I just deleted the end of "i")

(what is wrong with peeps in cakephp ??? API means "don’t change everything if it breaks existing code, ever." don’t "change! OBAMAAAAA!" ~ next update, I will click all my code for django or spring or scala. Ruddy bullshit.)

The next problem is the “Components” that I use - I get a cake error saying:

Missing plugin

Error: application is trying to download a file from the Uploader plugin

Error: make sure your plugin loader is in the application / plugin directory and loaded

 <?php CakePlugin::load('Uploader'); 

Download all plugins: if you want to download all plugins at once, use the following line in the app / Config / bootstrap.php file

 CakePlugin::loadAll(); 

So ... not only all my code is ruined, but all the old plugins too? Nice.

The solution is to create the application / plugin folder (yes, the magic upgrade does not do this either), and then look at the plugins that you had. Now! This is different from your components! I don’t know yet how to do this - check my question for a possible answer: Is there a difference between the component and the plugin in cakephp 2.1? - but right now we are just looking at the PLUGIN folder and plugins in general. It seems that there were 1.3 plugins in the cake are listed as follows:

var $ components = array ('Uploader.Uploader', ...);

those. with dotted designation. I can live with it. In my case, I needed to get the latest version of the Uploader plugin (which, fortunately, was updated to be compatible with 2.x!) And put it in the app / Plugin folder

so i got:

 app Plugin Uploader Config Locale <the other files here too!> 

It seems to work right now, cheers!

The following error:

Warning (2): Invalid argument provided by foreach () [CORE / Cake / Utility / Set.php, line 1048]

Warning (2): array_multisort () [ http://php.net/function.array-multisort] : Argument # 1 is expected as an array or sort flag [CORE / Cake / Utility / Set.php, line 1087]

Warning (2): array_unique () expects parameter 1 to be an array, null set to [CORE / Cake / Utility / Set.php, line 1089]

Warning (2): Invalid argument provided by foreach () [CORE / Cake / Utility / Set.php, line 1091]

Warning (2): Unable to change header information - headers already sent (output started in / cake _install / lib / Cake / Utility / Debugger.php: 761) [CORE / Cake / Network / CakeResponse.php, line 395]

Ah, then good. This is clear. I'm glad I know what an error is in my code. Good error messages!

Now I see, it's silly, to think that the Set :: Sort utility will continue to work if the first array is empty! Truly, people with fabric stand, not on the shoulders of giants, but on their very foreheads.

It would seem that the new version 2.1 update eliminates this shabby practice, so now I need to check before any Set: Sort call, to avoid if the array in question is empty or null. Good. Easy enough, but ... booze.

  • I just quit

    if (! empty ($ theArray)) {Set :: sorting ($ theArray, ...); }

and that fixed it.

Now I get FormHelper errors - it looks like $ form in the view now becomes $ this-> Form, so to replace this parameter I will need another quick script:

to find. -type f -exec sed -i 's / $ form / $ this-> Form / g' {} \;

And now the following error I get:

Fatal error: unsupported operand types in / cake _install / lib / Cake / View / Helper / FormHelper.php on line 1804

And now they've already mixed up the "select" method in FormHelper - like this before when I had this:

echo $ this-> Form-> select ('treatment_id', $ treatment, null, array ('empty' => '- select treatment to rate -'));

i now this:

echo $ this-> Form-> select ('treatment_id', $ treatment, array ('empty' => '- select treatment to rate -'));

And now one of my components - in fact, the You_tube_loader_component component - has been broken. I need to change it so that the title reads:

 class YouTubeLoaderComponent extends Component { function __construct(ComponentCollection $collection, $settings = array()) { parent::__construct($collection, $settings); ... } } 

I used to just default valeus uname and password - now I attach them to the "..." section instead of messing around with a mysterious array of "settings"!

Further:

Warning (2): Type of invalid offset [CORE / Cake / Model / Model.php, line 2689]

Warning (2): Type of invalid offset [CORE / Cake / Model / Model.php, line 2665]

Soooo is a problem that is not selected in cake 1.3, but is in version 2.1

The problem is that in the action of the referenced controller, there is a call to "find" without a type parameter. That is, I had

$ results = $ this-> User-> find (array (...), array (...), null, false);

where I should have been:

 $results = $this->User->find('first',array( 'conditions' => array("User.id" => ($this->Auth->user("id"))), 'fields' => array("User.confirmed") ) ); 

Another problem I had was that for some reason the check:

$ this-> set ('loggedIn', $ this-> Auth-> user ('id'));

does not work. Apparently (although I'm not sure how / why), cakePHP auth in 2.x will no longer store all user details in the session. I don’t know what details he stores at the session, or how to modify them - looking at that! - but my code did not save the "id" value, so the check above always sets the loggedIn value to false.

To fix the error, I changed the call as follows:

$ this-> set ('loggedIn', $ this-> Auth-> loggedIn ());

which worked great for me.

The next problem is that the user thios-> auth-> ('id') will return me a sweet nothing after the user logs in. Fortunately, I came across this post, which made everything clearer:

http://ask.cakephp.org/questions/view/unable_to_access_logged-in_users_data_in_2_0

Surprisingly, the geniuses in the cake laboratories believed that changing the way that entering the work would help eliminate some confusion. Honestly, the only thing I am confused with is the one who was so embarrassed that all user data was available in the auth component after logging in. But do not be afraid, they cleared up the confusion and ... removed the function completely.

So what do you do? The link above offers to get all user data, and then send it to the auth authorization section. I don’t particularly like it (because it is a stupid problem, and I can’t believe that it is not so demanding), but that’s what I have to do. Suggestions are welcome!

So, instead of oh-so-confusing:

 if ($this->Auth->login($this->request->data)) { ... //argh! I am so confused by that line above!!!1 

i now have:

 $user = $this->User->find('first', array( 'conditions' => array('User.email' => $this->request->data['User']['email']) ) ); // Use the AuthComponent~Rs login action if ($this->Auth->login($user['User'])) { ... //omg the extra check that the entry is in the db is just brilliant and efficient 

Isn't it so neat and less confusing? Good job cakephp mavericks!

The following error:

Authorization adapter "controller" not found.

Which is a bit vague ...

Oh! Already answered stack overflow: Authorization adapter not found in cakePHP

And it's all! There may be other problems - the speed of the gods on them - but I have not encountered them, so I can no longer help you.

+18
source

You probably had a custom cake path set in app/webroot/index.php . The directory structure for Cake 2.0 has changed a bit, and usually this will be handled by new code that automatically finds the correct value for CAKE_CORE_INCLUDE_PATH . Also, make sure APP_DIR set correctly in the same index.php file.

Make sure app/webroot/index.php contains the correct Cake path, which is /path/to/cake/lib .

 if (!defined('CAKE_CORE_INCLUDE_PATH')) { define('CAKE_CORE_INCLUDE_PATH', DS.'path'.DS.'to'.DS.'cake'.DS.'lib'); } 

Returning to define('CAKE_CORE_INCLUDE_PATH', ROOT) standard define('CAKE_CORE_INCLUDE_PATH', ROOT) may also work if Cake configuration is not too common.

+3
source

Here's my blog post about migrating from 1.3 to 2.x: http://www.forceflow.be/2011/11/12/migrating-from-cakephp-1-3-to-2-0/

In the future, I have included the content of this post here. Enjoy it!

Beginning of work

There are several upgrade methods, but for small to medium sized projects, I found it best to unzip the new CakePHP 2 structure and manually copy your controllers and views into their new folders. Keep in mind that the folder structure has changed significantly. For example, a controller card is now a controller. Pay attention to where you copy the files - do not worry about the file names themselves, come to this later well.

Make sure you update core.php and database.php (now in (cakephp root) / app / Config) with the values ​​for your application. Be sure to copy the salt and encryption values ​​from the old installation, as CakePHP will continue to whine when you use the standard ones - this is a security risk. In addition, to connect to the database again and again, the syntax has been changed:

 'driver' => 'mysqli' 

becomes

 'datasource' => 'Database/Mysql' 

Bulk work: updating through the console

There is a console command to rename all your application files to the new CakePHP file structure. New to CakePHP 2.0 is that each application now has its own console. Go to the application console (and not in the console / lib / Cake!) In / app / Console, make sure that the Console command is executable by running chmod + x and doing:

 ./cake upgrade all 

This will rename all the files to the new cake standard and update all the links in your PHP code.

Cleaning

Unfortunately, this is not the end. The odds are slim that your code will work fine. See CakePHP 2.0 Migration Guide for more information. I will summarize the topics Ive looked at most often:

In your views, you should now access the Helper classes through this object. No need to call anymore, for example

 $html->link( 

his

 $this->Html->link( 

now sir.

also:

  • JavascriptHelper is now called JsHelper.
  • The Auth component has changed significantly. The login () action is not added automatically when using the component, you need to manually specify it now. See the new Auth component documentation for more information.

AjaxHelper has been removed, as well as convenient AJAX-style search functions, such as surveillance. Ive prepared my own observation using jQuery - use at your own risk. I am serializing a form, which in this case contains a query input field that allows me to perform a real-time search and update for backup.

 $this->Js->get('#query')->event('keyup', $this->Js->request( array('controller' => 'sales','action' => 'searchReservations', $event['Event']['id']), array( 'update' => '#view', 'async' => true, 'dataExpression' => true, 'method' => 'post', 'data' => $this->Js->serializeForm(array('isForm' => false, 'inline' => true))) 
+2
source

I got the same problem after using Cake Shell Upgrade tool. Although our web application is great, we never set up the index.php file.

Replacing our myapp / app / webroot / index.php with the recently downloaded CakePHP cakephp-2.3.4 / app / webroot / index.php solved this problem for me.

I'm not sure why CakePHP Upgrade Shell or the instructions do not indicate a change to the index.php file, but as @bharal the long and excellent answer shows that much more work needs to be done, since Shell Upgrade does not do everything.

+1
source

Source: https://habr.com/ru/post/912453/


All Articles