Previous Value not being retrieved - laravel-backpack-5

I created a default_manufacturer_id field to a table and am trying to show the options under $manufacturer_list in a drop down. The drop down populates fine, but the previous value of default_manufacturer_id is not shown up as selected by default.
If I hard-code a specific value with the "value" key in the addField, then that value is shown up as selected. I was expecting the previous value of the default_manufacturer_id field to show up.
CRUD::addField([
'name' => 'default_manufacturer_id',
'type' => "select_from_array",
'label' => "Default Manufacturer",
'options' => $manufacturer_list,
'allows_null' => false,
]);
What is stopping this value from showing up as selected automatically? I have checked the database, and the value being saved is correct.
Version numbers are as follows:
root#f9c300ad6814:/var/www/html# php artisan backpack:version
PHP VERSION:
PHP 8.1.13 (cli) (built: Nov 26 2022 14:07:55) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.1.13, Copyright (c) Zend Technologies
with Zend OPcache v8.1.13, Copyright (c), by Zend Technologies
with Xdebug v3.2.0, Copyright (c) 2002-2022, by Derick Rethans
LARAVEL VERSION:
v9.49.0#e02d9453442ad0a6a2f5dc9df96ea0319d218026
BACKPACK PACKAGE VERSIONS:
backpack/crud: 5.4.11
backpack/pro: 1.1.2
backpack/generators: v3.3.7
With Regards,
Sharat

Related

Puppet and mysql: revoke and repeat

Grant: this works
I have the following puppet code:
mysql_grant {'my-user-name#1.2.3.4/my-database-name.*':
ensure => 'present',
options => ['GRANT'],
privileges => ['SELECT', 'INSERT', 'DELETE', 'UPDATE'],
table => 'my-database-name.*',
user => 'my-user-name#1.2.3.4',
}
and that does grant the permissions I expect.
Revoke: this doesn't work
If I change my mind and say this:
mysql_grant {'my-user-name#1.2.3.4/my-database-name.*':
ensure => 'absent',
options => ['GRANT'],
privileges => ['SELECT', 'INSERT', 'DELETE', 'UPDATE'],
table => 'my-database-name.*',
user => 'my-user-name#1.2.3.4',
}
I note that it doesn't revoke permission (not even if I change s/GRANT/REVOKE/). Any pointers on how to automate revocation? I haven't been able to find it in the manual or by googling.
Repeat: I'm lost without copy and paste
Now suppose I want to permit access from several hosts. My puppet-fu fails me on how to not repeat the block (i.e., just copy-paste with different IP addresses). I'm sure puppet defines tools for this, but I've not figured out that part yet.
Thanks for any pointers!
For the repeat part I can think of two ways:
puppetDB
hiera
PuppetDB
Whenever you want the fact of a node to do something on a second node, use puppetDB. This is called exported resources. This is also explained in the puppet-mysql documentation.
Example1: Add the SSH Hostkeys of all machines to the known_keys of all other machines.
Example2: Add all machines to monitoring, creating their own host definition.
Example3: On a certain class of machine, allow them to connect to MySQL.
In each case, you first install puppetDB via the puppet-puppetdb module. You will need puppet4 for this. PuppetDB will only start if you have 8+ GB of memory.
You then have to write the resource export and the resource import. On all nodes that have a fact that you want (like ip / fqdn), you write the export:
##mysql_grant {"my-user-name#${::ipaddress}/**my-database-name.*":
ensure => 'absent',
options => ['GRANT'],
privileges => ['SELECT', 'INSERT', 'DELETE', 'UPDATE'],
table => 'my-database-name.*',
user => "my-user-name#${::ipaddress}",
}
The '##' creates the export. Note that the exported resource is lower case. Also note the double quote instead of single quote whenever a variable is used.
What will happen whenever a node sees this, is that it will fill out this exported resource with its fact (in this case ::ipaddress), and send it to puppetDB. You can either add this part to all nodes you want to grant access, partially defeating its purpose, or you can have a manifest that is applied to all nodes and do something along the lines of:
if $::fqdn include? 'app'{
##mysql_grant {"my-user-name#${::ipaddress}/**my-database-name.*":
ensure => 'absent',
options => ['GRANT'],
privileges => ['SELECT', 'INSERT', 'DELETE', 'UPDATE'],
table => 'my-database-name.*',
user => "my-user-name#${::ipaddress}",
}
}
Then you need to write an import statement on the node that should apply this.
Mysql_grant <<| |>>
Please note the upper case.
Another quick example, which we apply to all our linux nodes:
# collect all the public host RSA keys for known hosts
##sshkey { $hostname:
ensure => present,
type => 'rsa',
host_aliases => [$::ipaddress, $::fqdn],
key => $sshrsakey,
}
# and populate known_hosts
Sshkey <<| |>>
#https://projects.puppetlabs.com/issues/21811
file { '/etc/ssh/ssh_known_hosts':
ensure => present,
path => '/etc/ssh/ssh_known_hosts',
mode => '0644',
}
Hiera
Hiera is build for exactly this purpose, to seperate code from data. Please refer to the hiera documentation for how to set it up.
What you end up doing is that you will create a yaml file that has all your data in it:
mysql::grants:
db1:
username: my-user-name
database: my-database-name
ip: 1.2.3.4
ensure: present
options:
- GRANT
privileges:
- SELECT
- INSERT
- DELETE
- UPDATE
table: my-database-name.*
db2:
username: my-user-name
database: my-database-name
ip: 1.2.3.5
ensure: present
options:
- GRANT
privileges:
- SELECT
- INSERT
- DELETE
- UPDATE
table: my-database-name.*
Then you just go ahead and put this in your mysql node (although creating a small module would be cleaner):
$grants = hiera('mysql::grants', undef)
create_resources('mysql::grant', $grants)
Puppet will parse all of hiera, then creating a grant for every db found.
Try using mysql_grant on a new user, then using puppet apply with the -d (debug) and -v (verbose) options on your manifest.
This should give you a load of output that shows what it's doing. What it will be doing is running sql commands on your database such as
grant all on db.* to user
These will also be shown when you run
show grants for user
Then change to 'absent', and repeat.
Now you know exactly what SQL commands puppet is running on your DB.
Then you can try those commands directly in the DB to see if they do what you expect.
Note: using ensure => 'absent' is the correct thing to do to remove permissions, changing grant to revoke won't help.

Using mysql with asterisk

I have installed asterisk 11 on my centos 6 ,now i want to connect my asterisk with database
I am following this .I have both installed and configured mysql
I have created an outbound call (b.call)
Channel: DAHDI/g0/09********
MaxRetries: 1
RetryTime: 60
WaitTime: 30
Context: out
Extension: 47******
Priority: 1
and a simple dialplan(extensions.conf)
[out]
exten => 47*****,1,NoOp(<-------IVR----------->)
same => n,dial(DAHDI/g0/09********)
same => n,MYSQL(Connect connid localhost username pass dbname)
same => n,MYSQL(Query resultid ${connid} INSERT INTO `emp` (`name`) VALUES ('Akash'))
My problem is that,first 2 lines of dialplan executes perfectly but database lines are not executed,cli shows only first 2 lines executed and last 2 lines not executed.
Am i missing any configuration settings??
Thanks
Very likly you have no app_mysql loaded.
I higly not recommend use outdated mysql app. Use instead function REALTIME and func_ODBC.

Script to Run through each Bugzilla Bug and Select 'Save Changes'

I need to run through each BugZilla bug individually and select the Save Changes button due to a previous problem. As there are over 8000 bugs it would not be possible to do this manually. I think the Perl Module WWW::Bugzilla will let me complete this by connecting to the bugzilla API.
use strict;
use warnings;
use WWW:Bugzilla;
my $bz = WWW::Bugzilla->new( server => 'http://be-qa-01/',
email => 'test.email#test.com',
password => 'pass'
bug_number => 8333 );
# show me the chosen component
my $component = $bz->component;
I'm, not sure how to go about this and would be grateful of any help.

CakePHP added column doesn't appear in query

I have added a new_column to a MyISAM table on a MySQLproduction server.
I have deleted the appropriate model cache file from the /app/tmp/models folder.
Upon reloading the page and inspection, the newly generated cache file for the model INCLUDES the new column.
The new column doesn't appear in SQL queries or results when read with fields => null.
debug($this->read(null, $id));
//Query generates fields: SELECT Model.column_a, Model.column_b, Model.id WHERE ...
//Results do not include the new column
debug($this->read(array('new_column'), $id));
//Query generates fields: SELECT Model.new_column, Model.id WHERE ...
//Results include the new column and id
Possible caveats and additional info:
The table has 39 columns (why would this be a problem?)
The model is an EXTENDED class from a plugin
The new column definition is TEXT DEFAULT null
Previous updates to the table gave expected results
Local development replica of the app doesn't have this issue
The test controller action enables Configure::write(debug => 2)
CakePHP 2.3.6, PHP 5.4.19, MySQL 5.1.70
How to make the Model recognize the new table definition? Are there any other cache systems I should investigate?
Edit #1:
debug($this->ModelName->getDataSource()->describe('table_name'));
// outputs all columns
// ...
'new_column' => array(
'type' => 'text',
'null' => true,
'default' => null,
'length' => null,
'collate' => 'utf8_general_ci',
'charset' => 'utf8'
)
Edit #2:
I have tried disabling the cache completely. Although the model picks up the new column, it is not really a solution.
Configure::write('Cache.disable', true);
// new_column appears in both query and results
Edit #3:
Further debugging shows that there is a discrepancy between these two results:
$this->ModelName->getDataSource()->fields($this->Model, 'ModelName');
//returns fields without new_colum
array_keys($this->ModelName->schema());
//returns fields with new_column
And this temporarily solves the problem:
$ds = $this->ModelName->getDataSource();
$ds->cacheMethods = false;
...
Method caching of the DboSource is the source of this issue. Slowly getting to the bottom of things.. :D
You have to clear all the cache files (but not directories) in app/tmp/cache whenever you update an application that is in production (debug is set to 0).
The actual cache causing problems in this issue was the app/tmp/cache/persistent/_cake_core_method_cache. Don't let the persistent part fool you, as it did me.
See this great answer for more details.
It is probably something related to the Database cache engine: in this case you can solve your issue just changing the query (for example, removing a field using the 'fields' statement). You can even try deleting the CakePHP's model cache: it's located in app/tmp/cache/models.
Happy Coding!
In fact what you can add a bootstrap file if you use a Plugin.
In my global bootstrap file I put:
CakePlugin::load('Myplugin', array('routes' => true, 'bootstrap' => true));
and in Plugin/Myplugin/Config/bootstrap.php I have
<?php
Cache::config('_cake_core_', array(
'engine' => 'File',
'prefix' => 'cake_core_myplugin_',
'path' => CACHE . 'persistent' . DS,
'serialize' => true,
'duration' => '+7 days',
));
?>
I added two columns in one of my models and I faced the same issue has you. Then I deleted all the models and persistent cache files and I change the duration inside my bootstrap file to 1 min.
Finally, my model was ok and reloaded. Later I go back to the initial duration.
It is durty, but it also looks like CakePHP messed up a little bit with cache.
Hope that it can help

Cakephp Auth login returns false even though SQL query finds rows

I have Cakephp app installed on a linux box.
The Mysql Driver is installed and php-pecl-acl has been removed.
There are no problems with the Cookies. The users and passwords exist in the database. The password is a CHAR(40) in the database.
The Auth->login() method always returns false, even though the sql query debug log shows that rows affected = 1
array(
'log' => array(
(int) 0 => array(
'query' => 'SELECT `User`.`id`, `User`.`username`, `User`.`password`, `User`.`email`, FROM `somedatabase`.`users` AS `User` WHERE `User`.`username` = 'someuser' AND `User`.`password` = '2d7a34c9ef8efa2cfdf4b89175f7edec1cd0ddda' LIMIT 1',
'params' => array(),
'affected' => (int) 1,
'numRows' => (int) 1,
'took' => (float) 2
)
),
'count' => (int) 1,
'time' => (float) 2
Please help.
Thank you.
Sounds like the exact same issue I was having that ended up being a server-specific issue related to PDO / PECL:
$this->Auth->login() creates correct query that returns 1 row, but fails IF check (server specific issue)
Edit:
Comment from OP about how he fixed:
I uninstalled PECL, then uninstalled php-pdo and put back the original
php.ini file. After that I reinstalled mysql-php and php-pdo packages
from Amazon and it worked. You were correct it was server issue with
the pdo installation.
I to had the same problem. I had contacted my server man he said that we didn't installed either PECL or php-pdo packages. What would be the problem.