Add new table or column on Zend Framework 1.11 - php

I'm currently given a running website, which using Zend-Framework 1.11 (to be precise, 1.11.11) with Doctrine 2.3 on it.
[I know, it's a very-very OLD version, but unfortunately, I can't upgrade it to newer version, since I'm really afraid that it will causing more trouble and destroy this website entirely lol!!]
I'm new with this ZF, but having a bit experience with other framework, such as - Laravel and CodeIgniter.
So, my question is -
How can I add a new table (or column) to an existing database (or table) using ZF-way or CLI-way?
For example - I'm having a Table called Supplier, with 4 columns
id
name
contact
phone
I want to add mobile_phone, a new column. How can I do that?
I need to add a new Table, exactly the same like Supplier above, how can I do that?
I experienced before, to add 2 new tables, BUT I did that manually... and it's such a pain.
Because, I need to create a file, edit the existing Model file (to create a relationships/FK) and then edit the Model Entity, and surprisingly, when I try to create its functionality, like Insert/Update/Delete, it shows me an error, that I need to create a Model Proxy too, which I check, it suppose be auto-generated.
Is there any good way to add that table (or column)? maybe using CLI or else?
Is there a way, to check, IF I can use doctrine-CLI? maybe something like doctrine --v? or something like that
I did try php doctrine list on project root folder and it fails - Could not open input file: doctrine.
I found those questions (maybe) same like here - Add a new column in Doctrine 2 in Zend Framework.
But, to be honest, I really don't know how it works and is that can be executed on project root folder?
I did try check on the details link about doctrine CLI that provided there, but still, I don't understand how to set it up.
On that link too, it drives me to this link, about how to set-up doctrine CLI, but, as I state, I kind of confuse, how I add / create the file.
In summary, I want to know, is there any way, to create a new Table? Like, on Laravel, we can create a new Table using their artisan:make?
And, is there a better way, to add new a Column on the existing Table?
FYI - I can do this syntax on my project root folder zf show version.?, IF, I can use zf syntax to create table and adding new column, I'm okay with that too. :)
Thanks in advance & Cheers! :)
I'm really sorry, if this thread/question is too long or not a straight-forward question, as I'm getting frustrated, to find a good documentation about this old ZF version

Related

Database Migration in TYPO3

I've started to refactor the ext:crawler to make it compatible with TYPO3 9LTS.
Currently we have a domain model based only on a database table + a TCA configuration:
https://github.com/AOEpeople/crawler/blob/master/ext_tables.sql#L48
https://github.com/AOEpeople/crawler/blob/master/Configuration/TCA/tx_crawler_configuration.php
I want to add a regular Domain Model and Repository for the Configurations instead, to benefit more from the code from TYPO3 Core.
My problem is currently:
I don't know how to migrate data from the already existing table tx_crawler_configuration to the new tx_crawler_domain_model_configuration without the users are loosing any data, or need to do any manual work.
I haven't found anything on this topic yet. I know I can "use foreign data source" but it's not foreign data, so not sure this is the best approach.
https://docs.typo3.org/typo3cms/ExtbaseFluidBook/6-Persistence/4-use-foreign-data-sources.html
I appreciate your input, thanks.
Torben Hansen just did something similar, when he migrated sf_bannners from using own Category concept to use the sys_category concept of TYPO3
What he does is creating a ext_update.php script that is being called automatically upon installation. You can see his commit here
https://github.com/derhansen/sf_banners/commit/02c2c6f1729b96940bb4dd0ca29761fe48d28c14
and probably catch him on Slack with any questions

After i change table fields (add or update) in mysql, i really want to recreate all the model and CRUD facility in yii with gii?

Actually, i'm a laravel developer, recently moved to yii and i found gii was there. I can create models, controllers and CRUD facilities with gii... and that's great!
But if I a add more fields in a table or simple delete a field in a table I have to recreate model and controller with gii, otherwise it gives error. It's really taking my time. Is there any other way to do it, because I searched it and found nothing so far about it. People are suggesting command line, but using gii, is it possible?
Why don't you just create a gii model again, once a new field is added.By the looks of it if you do not want to write code again then gii will give an option to modify the existing files and add the fields on its own.Simple as that.
But there is an disadvantage to this,if you have made some modifications as in for logic then that will get overridden once you modify the files using gii.But I suggested this because this fits in your business logic or as far as I can grasp it :p

CakePHP 3.x Database Migration Plugin: Is there a way to Change a table field?

I am trying to figure out how best to modify a MySQL Table's existing Column using the CakePHP Migrations plugin. I do not need to add or drop the column, I simply want to modify a string column's length.
Currently the column is defined as a varchar(50); I am repurposing the column and wish to define it as varchar(2000).
The goal of the migration is to be part of an automated deployment taking place on a standard CakePHP web app installation on a typical web server.
Near as I can tell, it looks like the only way (other than an ALTER statement) to accomplish this using the Migrations Plugin would be to:
rename the column
add the new column
Move/copy the existing data to the new column
drop the old column
Perhaps I have missed the discussion in the documents and countless tutorials and how to's out there on a better way to accomplish this, but this seems like a cumbersome and self defeating method.
I have been through both the CakePHP Migration Plugin's documentation and the Phinx's documentation but am failing to see the recommended method for this change. I appreciate any input for this.
Unfortunately the Phinx docs aren't that complete, there seem to be various undocumented methods, like the one you are looking for: \Phinx\Db\Table::changeColumn()
https://github.com/robmorgan/phinx/blob/v0.4.6/src/Phinx/Db/Table.php#L392
https://github.com/robmorgan/phinx/issues/682
The following should work
$table = $this->table('table_name');
$table->changeColumn('column_name', 'string', [
'limit' => 2000
]);
$table->update();

Keeping update timestamps in sync in Yii

I have a Project model and a Comment model that are connected with has many relationship( project -> comment ).
Im currently using CTimestampBehavior to keep the created and updated fields in sync but i want the project model change update timestamp when a comment is added, changed or deleted. I got several of cases like this in my project and I would just like to know the best way to go about all of this.
Can I use AfterSave() on each model and tell it to update its parent? That would trigger a chain when a comment is updated that would update all the way to the top. Should I do it this way or does Yii have support for this?
To my knowledge Yii does not have support for this feature. Not sure how that should be implemented in the framework either.
Can't really see any negative sides with this, and I'd definitely look into the same approach myself.

Better use of models and migration in symfony

Hey.
I'm having a hard time migrating changes I've done i my config/doctrine/schema.yml file.
I added the column age to the user table. Then I did a php symfony doctrine:generate-migrations-diff followed by php symfony doctrine:migrate .
Looking in my database, the column age is now added, without deleting any data.
But, my /lib/model/doctrine/base/BaseUser.class.php is not changed, there is no age field or functions for age . So I also did the command php symfony doctrine:build-model . Finally the model is updated/migrated too.
So I wonder, is this the only way? Seems like a lot of work, and I'm afraid to miss something each time doing it.
Could I go right into phpmyadmin, add changes in the database there and just do a php symfony doctrine:build-schema , and like that skip the migration part (two commands).
Also when the comes to use of models, am I right that /lib/model/doctrine/User.class.php is where I can make functions and such for my User "data class"? Like, making a function isFemale . If not, where would that kind of function be?
This might be a bad question, but why is the model layer inside the /lib/doctrine path? As far as I have learned, you keep modules inside apps, where you create your view and controller. Why should the model be outside. Like this I can make models without attached controller and view?
Thanks.
Why should the model be outside
Because models can be used everywhere in your project, in example, in different applications and modules.
Could I go right into phpmyadmin, add changes in the database there and just do a php symfony doctrine:build-schema , and like that skip the migration part (two commands).
Of course you can, but migrations are a good approach to track your schema when deploying to production or working in team.
Here how I use doctrine migrations (simple use-case):
Add a column age to my User model in schema.yml
./symfony doctrine:generate-migrations-diff. Migration class(-es) have been generated.
./symfony doctrine:migrate. Column age successfully added to table.
./symfony doctrine:build --all-classes. Build forms/filters/models
That's it. The main idea is that doctrine:generate-migrations-diff class:
Gathers information about all your models' structure (php-representation of schema.yml)
Compares your schema.yml and info from (1)
Generates migration classes based on difference
Also when the comes to use of models, am I right that /lib/model/doctrine/User.class.php is where I can make functions and such for my User "data class"? Like, making a function isFemale . If not, where would that kind of function be?
Yes, you can add such method to User model because it's about users.

Categories