Forum OpenACS Development: Ecommerce under 5.9

Request notifications

Collapse
Posted by Iuri Sampaio on
Hi Torben,

After upgrading to OACS 5.9, E-Commerce package started to return the following error. PSQL version is (9.1.23)

Have you faced the same problem?

Since those are core related issues, I decided to ask first, before going to the source code and start to fix it.

Best wishes,

[02/Nov/2016:14:38:23][22527.b5237b70][-conn:evex:1-] Error: nsdbpg: result status: 7 message: ERROR: invalid input syntax for integer: "[ec_id]"
LINE 4: where package_id = '[ec_id]';
^

[02/Nov/2016:14:38:23][22527.b5237b70][-conn:evex:1-] Error: nsdbpg: result status: 7 message: ERROR: invalid input syntax for integer: "[ec_id]"
LINE 4: where apm_parameter_values.package_id = '[ec_id]'
^

[02/Nov/2016:14:38:23][22527.b5237b70][-conn:evex:1-] Error: Database operation "0or1row" failed (exception ERROR, "ERROR: invalid input syntax for integer: "[ec_id]"
LINE 4: where apm_parameter_values.package_id = '[ec_id]'
^
")

ERROR: invalid input syntax for integer: "[ec_id]"
LINE 4: where apm_parameter_values.package_id = '[ec_id]'
^

SQL:
select apm_parameter_values.attr_value
from apm_parameters, apm_parameter_values
where apm_parameter_values.package_id = '[ec_id]'
and apm_parameter_values.parameter_id = apm_parameters.parameter_id
and apm_parameters.parameter_name = 'CacheRefresh'

while executing
"ns_pg_bind 0or1row nsdb0 {
select apm_parameter_values.attr_value
from apm_parameters, apm_parameter_values
where apm_parameter_valu..."
("uplevel" body line 1)
invoked from within
"uplevel $ulevel [list ns_pg_bind $type $db $sql]"
invoked from within
"db_exec 0or1row $db $full_name $sql"
("uplevel" body line 2)
invoked from within
"uplevel 1 $code_block "
invoked from within
"db_with_handle -dbn $dbn db {
set selection [db_exec 0or1row $db $full_name $sql]
}"
(procedure "::nsf::procs::db_string" line 27)
invoked from within
"db_string select_instance_parameter_value {} -default """
(procedure "::nsf::procs::ad_parameter_cache" line 17)
invoked from within
"ad_parameter_cache $package_id $parameter"
(procedure "::nsf::procs::parameter::get" line 30)
invoked from within
"parameter::get -localize=$localize_p -package_id $package_id -parameter $name -default $default"
(procedure "::nsf::procs::ad_parameter" line 7)
invoked from within
"ad_parameter -package_id {[ec_id]} CacheRefresh 600"
invoked from within
"ns_cache_eval {*}$max_age -- util_memoize $script {*}$script"
(procedure "util_memoize" line 5)
invoked from within
"util_memoize {ad_parameter -package_id [ec_id] CacheRefresh 600} 600"
(procedure "ec_cache_refresh_mem" line 2)
invoked from within
"ec_cache_refresh_mem"
invoked from within
"ns_cache_eval {*}$max_age -- util_memoize $script {*}$script"
(procedure "util_memoize" line 5)
invoked from within
"util_memoize {ec_cache_refresh_mem} 300"
(procedure "ec_cache_refresh" line 2)
invoked from within
"ec_cache_refresh"
(procedure "ec_url" line 2)
invoked from within
"ec_url"
("uplevel" body line 61)
invoked from within
"uplevel {
ad_page_contract {

Entry page to the ecommerce store.

@param usca_p
@param how_many
@param start_row

@author
..."
(procedure "code::tcl::/var/www/evex/packages/ecommerce/www/index" line 2)
invoked from within
"code::tcl::$__adp_stub"
("uplevel" body line 12)
invoked from within
"uplevel {

if { [file exists $__adp_stub.tcl] } {

# ensure that data source preparation procedure exists and is up-to-date
..."
(procedure "adp_prepare" line 2)
invoked from within
"adp_prepare"
invoked from within
"template::adp_parse [file rootname [ad_conn file]] {}"
(procedure "adp_parse_ad_conn_file" line 6)
invoked from within
"$handler"
("uplevel" body line 2)
invoked from within
"uplevel $code"
invoked from within
"ad_try {
$handler
} ad_script_abort val {
# do nothing
}"
invoked from within
"rp_serve_concrete_file [ad_conn file]"
(procedure "::nsf::procs::rp_serve_abstract_file" line 60)
invoked from within
"rp_serve_abstract_file "$root/$extra_url""
("uplevel" body line 2)
invoked from within
"uplevel $code"
invoked from within
"ad_try {
rp_serve_abstract_file "$root/$extra_url"
set tcl_url2file([ad_conn url]) [ad_conn file]
set ..."
called from rp_handler
GET http://192.199.241.135:8000/ecommerce/? referred by 'http://evex.co/xowiki/' peer 192.199.241.135 user_id 0

X-Forwarded-For: 186.203.216.22
Host: 192.199.241.135:8000
Connection: close
Pragma: no-cache
Cache-Control: no-cache
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
User-Agent: Mozilla/5.0 (X11; Linux i686) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/40.0.2214.111 Safari/537.36
Referer: http://evex.co/xowiki/
Accept-Encoding: gzip, deflate, sdch
Accept-Language: en-US,en;q=0.8
Cookie: user_session_id="0"; ad_session_id="40008%252c0%252c0%252c1478097449%2b%257b628%2b1478098649%2bACF045E1367800029715E5BADA2F0F3B31192F4A%257d"

Collapse
2: Re: Ecommerce under 5.9 (response to 1)
Posted by Gustaf Neumann on
The commerce package does not belong to the ~90 packages i am trying to maintain, ... and i am not Torben, but it seems to me that the following function is causing troubles. This should not have worked in earlier releases either, since util_memoize is called without variable substitution (curly braces). Furthermore, ad_parameter is deprecated since at least more than 12 years.

The following change should you help to bypass this problem

-g

ad_proc -private ec_cache_refresh_mem {} {
 } {
     return [util_memoize {ad_parameter -package_id [ec_id] CacheRefresh 600} 600]
}
should read as
ad_proc -private ec_cache_refresh_mem {} {
 } {
     return [util_memoize [list parameter::get -parameter CacheRefresh -package_id [ec_id] -default 600] 600]
}

Collapse
3: Re: Ecommerce under 5.9 (response to 1)
Posted by Benjamin Brink on
Hi Iuri,
Much of the underlying code in ecommerce has been depricated. This error is likely the tip of an iceberg of issues anyone will encounter when using ecommerce with OpenACS 5.9.

Most likely, there is less work in refactoring the parts you need into a new package or packages.

Most of the key components exist as monolithic processes that can be extracted into new packages. Refactoring using the newer coding standards with the existing data model will likely avoid most issues.

The ecommerce templating system has been refactored into a wiki: Q-Wiki. Depending on the organizational environment, xowiki may be more suitable.

If payment processing is external, such as with PayPal, the cl-custom package may be a solution.

Stable versions of Q-Wiki and cl-custom are at https://github.com/openacs-ecg2

If you have experience with the mature OpenACS object system, it may make sense to use its features to define a new product data model.

As for a more elaborate system, I'm (still) re-writing ecommerce into a suite of packages that includes porting sql-ledger.

cheers,
Ben

Collapse
4: Re: Ecommerce under 5.9 (response to 3)
Posted by Benjamin Brink on
ps, for cl-custom package, iirc, the datamodel does not automatically load during install. This is fixed for the version at github.com/tekbasse/cl-custom
cheers,
Ben
Collapse
5: Re: Ecommerce under 5.9 (response to 4)
Posted by Iuri Sampaio on
Ben,

Why does ad_proc [ec_get_user_session_id] returns "0" instead of just 0?

set user_session_id [ec_get_user_session_id]
ns_log Notice "USESSION_ID: $user_session_id"

Log file returns:
[06/Nov/2016:22:32:37][7947.abc23b70][-conn:evex:3-] Notice: USESSION_ID: "0"

There ins't anything wrong with its source.

ad_proc ec_get_user_session_id {} { Gets the user session from cookies } {
ns_log Notice "Running ad_proc ec_user_session_id"

set headers [ns_conn headers]
set cookie [ns_set get $headers Cookie]

# grab the user_session_id from the cookie
if { [regexp {user_session_id=([^;]+)} $cookie match user_session_id] } {
return $user_session_id
} else {
return 0
}
}

Best wishes

Collapse
6: Re: Ecommerce under 5.9 (response to 5)
Posted by Iuri Sampaio on
Thanks Gustaf!

I'll keep digging and fixing ecommerce tcl scripts, using your samples, in order to get them working under oacs-5.9.

I've written a palliative using lindex to remove "".

Best wishes,

Collapse
7: Re: Ecommerce under 5.9 (response to 5)
Posted by Benjamin Brink on
Hi Iuri,

> Why does ad_proc [ec_get_user_session_id] returns "0" instead of just 0?

Looking at the code for ec_get_user_session_id, if the expression matches with:

user_session_id="0"

Then, $user_session_id will return "0" including quotes.

Changing the regular expression to something like this should remove those:

{user_session_id=[\"]?([^;\"]+)}

..but I am sure there is a better way of doing this.

oacs-5-9 has passed a bunch of security tests, so consider looking at sec_login_read_cookie and friends.

cheers,
Ben