Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: CodeIgniter 4 upgrade #3592

Closed
wants to merge 641 commits into from
Closed

Feature: CodeIgniter 4 upgrade #3592

wants to merge 641 commits into from

Conversation

jekkos
Copy link
Member

@jekkos jekkos commented Nov 13, 2022

Upgrading CodeIgniter to 4.4.3 #842

Here are a list of issues that need to be resolved:

@objecttothis
Copy link
Member

I've created a draft PR just to compare the two branches. We are going to need to write a special upgrade instructions document for this upgrade. @odiea do you care to do this? It will need to include things like manually moving images in item_pics, etc to the new location...

@objecttothis
Copy link
Member

Does this new CI4 branch include the changes from the master that were merged since the original codeigniter_4_upgrade branch was created? Those are going to manually need to be ported to the CI4 format. If they are blindly merged in then they won't work because the syntax for many things is different.

@objecttothis objecttothis changed the title Ci4 upgrade CI4 upgrade (New) Nov 17, 2022
@objecttothis
Copy link
Member

objecttothis commented Nov 17, 2022

@jekkos did we decide whether this version will be 3.4.0 or 4.0.0?

@jekkos
Copy link
Member Author

jekkos commented Nov 17, 2022

@objecttothis I always thought to stick with 3.4.0, as we do not really add new features. But this might not be reflecting the fact that the upgrade was a huge effort.

app/Config/migration.php Outdated Show resolved Hide resolved
@objecttothis
Copy link
Member

@objecttothis I always thought to stick with 3.4.0, as we do not really add new features. But this might not be reflecting the fact that the upgrade was a huge effort.

That's fine. I'll push a commit.

- correct URL
- Removed line endings
- Removed unneeded include
- Removed esc() call that was causing problems
- Renamed function to match CI4 expectations
- String interpolation
- corrected URL for pic_thumb
@jekkos jekkos force-pushed the ci4-upgrade branch 2 times, most recently from 322e357 to 246ea27 Compare November 1, 2023 00:09
@DEV-byoos
Copy link

@objecttothis
the constant BASEPATH not exist on CI4, use FCPATH declared in /root/index.php

@objecttothis
Copy link
Member

@objecttothis the constant BASEPATH not exist on CI4, use FCPATH declared in /root/index.php

Thank you. I will replace those instances tomorrow when I am back in the office.

@DEV-byoos
Copy link

DEV-byoos commented Nov 1, 2023

Thank you @objecttothis for your quick response ho to perfect the fix link the.zip file attached to my message from ********** START debug *************
`// 2023/10/30 chaper company_log
// IN /root/ci4_opensourceospos_latest/app/Views/login.php
//FIX replace "images/" directory to "uploads/logo/"

// IN /root/ci4_opensourceospos_latest/public/config
// the "logo_exists" key is always TRUE
//replace $data['logo_exists'] = $this->config['company_logo'] != '';
// TO FIX
function getIndex() {
$data['logo_exists'] = !empty($this->config['company_logo']);
...
`
// IN /root/ci4_opensourceospos_latest/app/Views/Config/info_config.php
// replace base_url('uploads') TO base_url('images/logo/')

`// IN /root/app/Controllers/Config.php
// Method upload_logo() infos: if $file->guessExtension() is loaded after move function then not work ( /tmp/file_tmp is moved )
private function upload_logo(): array
{
helper(['form']);
$validation_rule = [
'company_logo' => [
'label' => 'Company logo',
'rules' => [
'uploaded[company_logo]',
'is_image[company_logo]',
'max_size[company_logo,1024]',
'mime_in[company_logo,image/png,image/jpg,image/gif]',
'ext_in[company_logo,png,jpg,gif]',
'max_dims[company_logo,800,680]',
]
]
];

	if (!$this->validate($validation_rule))
	{
		return (['error' => $this->validator->getError('company_logo')]);
	}
	else
	{
		$file = $this->request->getFile('company_logo');

		$file_info = [
			'orig_name' => $file->getClientName(),
			'raw_name' => $file->getName(),
			'file_ext' => $file->guessExtension(),
			'error'	   => ''
		];

		 if (! $file->hasMoved()) {
			 //$file->move(WRITEPATH . 'uploads/logo/');
			 $file->move(FCPATH.'public/images/logo/');
			 $success = $this->appconfig->save(['company_logo' => $file->getClientName()]);
		}

		return ($file_info);
	}
}`

`// INFOS: https://stackoverflow.com/questions/58728648/how-to-display-uploaded-images-in-codeigniter-4

// IN /root/app/Controllers/Config.php -> error 404, rename remove_logo TO postRemove_logo
// Method postRemove_logo() erase WRITEPATH . 'uploads/logo/' AND $dirdest = FCPATH.'images/logo/'
/ AND empty config['company_logo'] value
/**
* @throws ReflectionException
*/
public function postRemove_logo(): void
{
helper('filesystem');
$dirdest = FCPATH.'uploads/logo/';
if (file_exists($dirdest)){
delete_files($dirdest);
}

	$success = $this->appconfig->save(['company_logo' => '']);			
	echo json_encode (['success' => $success]);
}

`
Sincerely, Gabriel

@objecttothis
Copy link
Member

@DEV-byoos thank you for the helpful tips. Please check out ci4-branch, make the changes there and submit a pull request against ci4-branch for these changes. I can do a code review at that time, but wading through the shorthand in your comment is difficult.

@objecttothis objecttothis changed the title CI4 upgrade (New) Feature: CodeIgniter 4 upgrade Nov 3, 2023
@jekkos
Copy link
Member Author

jekkos commented Nov 5, 2023

@objecttothis should we reopen the pull request now with the new branch instead?

@jekkos
Copy link
Member Author

jekkos commented Nov 5, 2023

@DEV-byoos indeed it might be better if you submit your fixes in a pull request. Do you know how to do that? Thanks!

@objecttothis
Copy link
Member

@objecttothis should we reopen the pull request now with the new branch instead?

I think you can edit this PR so it's ci4-branch trying to merge into master instead of ci4-upgrade. It would be a shame to lose the conversation history in this PR by creating a new one.

@DEV-byoos
Copy link

@objecttothis hello,

Well, thank you for your suggestion but I'm not a github boss and my Internet network is weak.
While I get used to the pull-request I suggest sending you patch by patch on "Feature: CodeIgniter 4 upgrade #3592" you can test then update the ci4-upgrade, OK?
like /root/app/controllers/Config.php --- remove_logo method
FIX rename remove_logo with postRemove_logo
code
` public function postRemove_logo(): void
{
$file = FCPATH.'uploads/' . $this->config['company_logo'];
if (is_readable($file) && unlink($file)) {
$success = $this->appconfig->save(['company_logo' => '']);
} else {
$success = "The file was not found";
}
$success = $this->appconfig->save(['company_logo' => '']);

	echo json_encode (['success' => $success]);
}`

@objecttothis
Copy link
Member

objecttothis commented Nov 6, 2023

@objecttothis hello,

Well, thank you for your suggestion but I'm not a github boss and my Internet network is weak. While I get used to the pull-request I suggest sending you patch by patch on "Feature: CodeIgniter 4 upgrade #3592" you can test then update the ci4-upgrade, OK? like /root/app/controllers/Config.php --- remove_logo method FIX rename remove_logo with postRemove_logo code ` public function postRemove_logo(): void { $file = FCPATH.'uploads/' . $this->config['company_logo']; if (is_readable($file) && unlink($file)) { $success = $this->appconfig->save(['company_logo' => '']); } else { $success = "The file was not found"; } $success = $this->appconfig->save(['company_logo' => '']);

	echo json_encode (['success' => $success]);
}`

@owlbrudder @jekkos do either of you want to take the time to look through @DEV-byoos changes and implement them? @DEV-byoos I'm working through fixing some problems with attributes right now. I'm sorry, but I just don't have time to submit these changes myself. The formatting does not come through very well in github because you aren't using ``` before and after your code blocks. Your changes are probably very helpful, but I can't get to it. I don't know what your first language is, but I recommend reading a tutorial on how to create a branch, make changes and submit them as a pull request. You can even do these by hand in Github if you need to.

@owlbrudder
Copy link
Collaborator

owlbrudder commented Nov 6, 2023 via email

@DEV-byoos
Copy link

DEV-byoos commented Nov 6, 2023

DAY 1
thanks @owlbrudder

following explanation:
the company_logo config option allows you to replace the OSPOS logo with the company logo, OK

  1. Add company logo YES
  2. validate the config modification YES after fix
  3. delete the logo NO because it does not disappear on disk, only in the database TABLE ospos_app_config KEY company_logo
  4. if we reload a new company logo the name on the disk will be indexed filename_1...
    NOTE company logo can only be loaded once.
    Like /root/app/controllers/Config.php --- remove_logo method
    FIX rename remove_logo with postRemove_logo
    code
  	public function postRemove_logo(): void
	{
		$file = FCPATH.'uploads/' . $this->config['company_logo'];
		if (is_readable($file) && unlink($file)) {
			$success = $this->appconfig->save(['company_logo' => '']);
		} else {
			$success = "The file was not found";
		}
		$success = $this->appconfig->save(['company_logo' => '']);
		
		echo json_encode (['success' => $success]);
	}

PS I use code tags, I don't understand why it's buggy??? OK I found thanks @objecttothis your code
best regards

@owlbrudder
Copy link
Collaborator

owlbrudder commented Nov 6, 2023 via email

@DEV-byoos
Copy link

@DEV-byoos indeed it might be better if you submit your fixes in a pull request. Do you know how to do that? Thanks!

Answer @DEV-byoos
@jekkos
en fait je n'utilise GITHUB seulement pour mes dépôts ou fork et le téléchargement de projet ho mais je vais essayer de trouver un bon tuto pour apprendre cela.

@jekkos
Copy link
Member Author

jekkos commented Nov 6, 2023

4. if we reload a new company logo the name on the disk will be indexed filename_1...
NOTE company logo can only be loaded once.
Like /root/app/controllers/Config.php --- remove_logo method
FIX rename remove_logo with postRemove_logo
code

Ca sera bon si tu apprendrais a faire un requet tirer. Ou autrement vous pouvez justement envoyer un diff generé par git. Je pense que ca va etre plus facile a inspecter;

@jekkos
Copy link
Member Author

jekkos commented Nov 6, 2023

@objecttothis should we reopen the pull request now with the new branch instead?

I think you can edit this PR so it's ci4-branch trying to merge into master instead of ci4-upgrade. It would be a shame to lose the conversation history in this PR by creating a new one.

I checked this, you can only change the target branch, but not the source. Which might make sense. The conflicts we see here are resolved in the other branch. I can copy the content of the issue list here to a new PR.
The history will remain then in this conversation, in my opinion it has become already a bit too long.

@jekkos
Copy link
Member Author

jekkos commented Nov 6, 2023

DAY 1 thanks @owlbrudder

following explanation: the company_logo config option allows you to replace the OSPOS logo with the company logo, OK

1. Add company logo YES

2. validate the config modification YES after fix

3. delete the logo NO because it does not disappear on disk, only in the database TABLE ospos_app_config KEY company_logo

4. if we reload a new company logo the name on the disk will be indexed filename_1...
   NOTE company logo can only be loaded once.
   Like /root/app/controllers/Config.php --- remove_logo method
   FIX rename remove_logo with postRemove_logo
   code
  	public function postRemove_logo(): void
	{
		$file = FCPATH.'uploads/' . $this->config['company_logo'];
		if (is_readable($file) && unlink($file)) {
			$success = $this->appconfig->save(['company_logo' => '']);
		} else {
			$success = "The file was not found";
		}
		$success = $this->appconfig->save(['company_logo' => '']);
		
		echo json_encode (['success' => $success]);
	}

PS I use code tags, I don't understand why it's buggy??? best regards

Thanks for the proposition. Regarding the function rename, I would not mix camelcase with snake case. In this case camelcase is the way to go.

@DEV-byoos
Copy link

DEV-byoos commented Nov 6, 2023

DAY 2
thanks @owlbrudder

following explanation:
updating the company logo in its original version works but generates two critical errors in php 8.2 -- php8.3
let me explain ho, it all starts with the info_config.php form
<?php echo form_open('config/saveInfo/',
when validating "change image" on POST to controller /root/app/Controllers/Config.php postSaveInfo method

  1. $upload_success = !empty($upload_data['error']); the variable $upload_success is not loaded ( !isset ) and causes a critical error on line 357 $message = $upload_success ? $message: strip_tags($upload_data['error']);
    fix in upload_logo method.

coded

	private function upload_logo(): array
	{
		helper(['form']);
		$validation_rule = [
			'company_logo' => [
				'label' => 'Company logo',
				'rules' => [
					'uploaded[company_logo]',
					'is_image[company_logo]',
					'max_size[company_logo,1024]',
					'mime_in[company_logo,image/png,image/jpg,image/gif]',
					'ext_in[company_logo,png,jpg,gif]',
					'max_dims[company_logo,800,680]',
				]
			]
		];

		if (!$this->validate($validation_rule))
		{
			return (['error' => $this->validator->getError('company_logo')]);
		}
		else
		{
			$file = $this->request->getFile('company_logo');

			$file_info = [
				'orig_name' => $file->getClientName(),
				'raw_name' => $file->getName(),
				'file_ext' => $file->guessExtension(),
				'error'	   => ''
			];

			 if (! $file->hasMoved()) {
				 $file->move(FCPATH.'uploads/');
				 $success = $this->appconfig->save(['company_logo' => $file->getClientName()]);
			}

			return ($file_info);
		}
	}

the $file_info = [...] block is moved up and an 'error' key is added to initialize the value to empty.
I hope this will be clear enough because I'm doing it with what I have.
bye see you tomorrow
PS // INFOS: https://stackoverflow.com/questions/58728648/how-to-display-uploaded-images-in-codeigniter-4

@objecttothis
Copy link
Member

objecttothis commented Nov 6, 2023

@DEV-byoos this comment section is going to get long and chaotic. Please use Element (formerly glitter). You can use their online client or download a client on their website (https://matrix.org/ecosystem/clients/element/) just change the server to gitter.im. I will send you an invite to the dev room of opensourcepos. Just use your GitHub account to login.

We will be closing and deleting this PR soon since the other PR is what will be merged with the master. post a message to opensourcepos/Lobby and I'll send the invite to opensourcepos/devroom

@objecttothis
Copy link
Member

I'm closing this PR as it will not be one we will merge. See #3858

@objecttothis objecttothis deleted the ci4-upgrade branch December 4, 2023 11:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment