antoniop
committed
on 29 Mar 23
ns_getform will return the empty string only when invoked outside of a connection thread, which is a non-issue at installation time
openacs-4/.../acs-bootstrap-installer/installer.tcl (+17 -26)
85 85 }
86 86
87 87 ad_proc -private install_page_contract { mandatory_params optional_params } {
88 88     Instead of using ad_page_contract that relies on certain acs-subsite libraries
89 89     that may not be available at all times during installation we use this
90 90     more primitive proc instead.
91 91
92 92     @param mandatory_params An array list where keys are param names and values
93 93     are pretty names.
94 94     @param optional_params An array list with param names as keys and default
95 95     values as keys.
96 96
97 97     @author Peter Marklund
98 98 } {
99 99     array set mandatory_params_array $mandatory_params
100 100     array set optional_params_array $optional_params
101 101
102 102     set form [ns_getform]
103 103     set missing_params [list]
104 104
105       if { $form eq "" } {
106           # Form is empty - all mandatory params are missing
107           foreach param_name [array names mandatory_params_array] {
108               lappend missing_params $mandatory_params_array($param_name)
109           }
110       } else {
111           # Form is nonempty
112  
113 105     # Loop over all params
114 106     set all_param_names [concat [array names mandatory_params_array] \
115 107                              [array names optional_params_array]]
116 108     foreach param_name $all_param_names {
117 109         set param_value [ns_set iget $form $param_name]
118 110         set mandatory_p [expr {$param_name in $mandatory_params}]
119 111
120 112         if { $param_value ne "" } {
121 113             # Param in form - set value in callers scope
122 114             uplevel [list set $param_name $param_value]
123 115         } else {
124 116             # Param not in form
125 117             if { $mandatory_p } {
126 118                 # Mandatory param - complain
127 119                 lappend missing_params $mandatory_params_array($param_name)
128 120             } else {
129 121                 # Optional param - set default
130 122                 uplevel [list set $param_name $optional_params_array($param_name)]
131 123             }
132 124         }
133 125     }
134       }
135 126
136 127     # If there are missing mandatory params - return a complaint
137 128     # page and exit
138 129     if { [llength $missing_params] > 0 } {
139 130         ns_write "[install_header 200 {Missing parameters}]
140 131
141 132 The following mandatory parameters are missing:
142 133 <ul>
143 134 <li>[join $missing_params "</li>\n<li>"]</li>
144 135 </ul>
145 136
146 137 <p>
147 138 Please back up your browser and provide those parameters. Thank you.
148 139 </p>
149 140
150 141 [install_footer]
151 142 "
152 143         return -code return
153 144     }
154 145 }